@particle-academy/fancy-code 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/dist/index.cjs +20 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1642,8 +1642,27 @@ function escapeHtml(s) {
|
|
|
1642
1642
|
function escapeAttr(s) {
|
|
1643
1643
|
return s.replace(/"/g, """).replace(/'/g, "'");
|
|
1644
1644
|
}
|
|
1645
|
+
var LINK_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto", "tel"]);
|
|
1646
|
+
function schemeOf(url) {
|
|
1647
|
+
let s = "";
|
|
1648
|
+
for (const ch of url) {
|
|
1649
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
1650
|
+
if (code === 9 || code === 10 || code === 13) continue;
|
|
1651
|
+
if (s === "" && code <= 32) continue;
|
|
1652
|
+
s += ch;
|
|
1653
|
+
}
|
|
1654
|
+
const m = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(s);
|
|
1655
|
+
return m ? m[1].toLowerCase() : null;
|
|
1656
|
+
}
|
|
1657
|
+
function safeUrl(url, kind) {
|
|
1658
|
+
const scheme = schemeOf(url);
|
|
1659
|
+
if (scheme === null) return true;
|
|
1660
|
+
if (scheme === "http" || scheme === "https") return true;
|
|
1661
|
+
if (kind === "link") return LINK_SCHEMES.has(scheme);
|
|
1662
|
+
return scheme === "data" && /^data:image\/(png|jpe?g|gif|webp|avif|bmp);/i.test(url.trim());
|
|
1663
|
+
}
|
|
1645
1664
|
function inline(text) {
|
|
1646
|
-
return text.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, alt, src, title) => `<img src="${escapeAttr(src)}" alt="${escapeAttr(alt)}"${title ? ` title="${escapeAttr(title)}"` : ""}>`).replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, t, href, title) => `<a href="${escapeAttr(href)}"${title ? ` title="${escapeAttr(title)}"` : ""} rel="noopener">${t}</a>`).replace(/`([^`]+)`/g, (_m, c) => `<code>${c}</code>`).replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, "<strong>$2</strong>").replace(/(\*|_)(?=\S)([\s\S]*?\S)\1/g, "<em>$2</em>");
|
|
1665
|
+
return text.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, alt, src, title) => safeUrl(src, "image") ? `<img src="${escapeAttr(src)}" alt="${escapeAttr(alt)}"${title ? ` title="${escapeAttr(title)}"` : ""}>` : alt).replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, t, href, title) => safeUrl(href, "link") ? `<a href="${escapeAttr(href)}"${title ? ` title="${escapeAttr(title)}"` : ""} rel="noopener">${t}</a>` : t).replace(/`([^`]+)`/g, (_m, c) => `<code>${c}</code>`).replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, "<strong>$2</strong>").replace(/(\*|_)(?=\S)([\s\S]*?\S)\1/g, "<em>$2</em>");
|
|
1647
1666
|
}
|
|
1648
1667
|
function renderMarkdown(markdown) {
|
|
1649
1668
|
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|