@particle-academy/fancy-code 0.12.0 → 0.12.1
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 +18 -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 +1 -1
package/dist/index.js
CHANGED
|
@@ -1808,8 +1808,27 @@ function escapeHtml(s) {
|
|
|
1808
1808
|
function escapeAttr(s) {
|
|
1809
1809
|
return s.replace(/"/g, """).replace(/'/g, "'");
|
|
1810
1810
|
}
|
|
1811
|
+
var LINK_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto", "tel"]);
|
|
1812
|
+
function schemeOf(url) {
|
|
1813
|
+
let s = "";
|
|
1814
|
+
for (const ch of url) {
|
|
1815
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
1816
|
+
if (code === 9 || code === 10 || code === 13) continue;
|
|
1817
|
+
if (s === "" && code <= 32) continue;
|
|
1818
|
+
s += ch;
|
|
1819
|
+
}
|
|
1820
|
+
const m = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(s);
|
|
1821
|
+
return m ? m[1].toLowerCase() : null;
|
|
1822
|
+
}
|
|
1823
|
+
function safeUrl(url, kind) {
|
|
1824
|
+
const scheme = schemeOf(url);
|
|
1825
|
+
if (scheme === null) return true;
|
|
1826
|
+
if (scheme === "http" || scheme === "https") return true;
|
|
1827
|
+
if (kind === "link") return LINK_SCHEMES.has(scheme);
|
|
1828
|
+
return scheme === "data" && /^data:image\/(png|jpe?g|gif|webp|avif|bmp);/i.test(url.trim());
|
|
1829
|
+
}
|
|
1811
1830
|
function inline(text) {
|
|
1812
|
-
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>");
|
|
1831
|
+
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>");
|
|
1813
1832
|
}
|
|
1814
1833
|
function renderMarkdown(markdown) {
|
|
1815
1834
|
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|