@particle-academy/fancy-code 0.5.0 → 0.5.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/README.md +6 -0
- package/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1077,6 +1077,7 @@ function tokenizeMarkdown(source) {
|
|
|
1077
1077
|
return tokens;
|
|
1078
1078
|
}
|
|
1079
1079
|
function pushInline(line, base, out) {
|
|
1080
|
+
if (line.length > 5e3) return;
|
|
1080
1081
|
const spans = [];
|
|
1081
1082
|
const add = (type, start, end) => {
|
|
1082
1083
|
spans.push(tok(type, base + start, base + end));
|
|
@@ -1682,8 +1683,11 @@ var CodeEditor = Object.assign(CodeEditorRoot, {
|
|
|
1682
1683
|
function escapeHtml2(s) {
|
|
1683
1684
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1684
1685
|
}
|
|
1686
|
+
function escapeAttr(s) {
|
|
1687
|
+
return s.replace(/"/g, """).replace(/'/g, "'");
|
|
1688
|
+
}
|
|
1685
1689
|
function inline(text) {
|
|
1686
|
-
return text.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, alt, src, title) => `<img src="${src}" alt="${alt}"${title ? ` title="${title}"` : ""}>`).replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, t, href, title) => `<a href="${href}"${title ? ` title="${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>");
|
|
1690
|
+
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>");
|
|
1687
1691
|
}
|
|
1688
1692
|
function renderMarkdown(markdown) {
|
|
1689
1693
|
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|
|
@@ -1717,7 +1721,7 @@ function renderMarkdown(markdown) {
|
|
|
1717
1721
|
i++;
|
|
1718
1722
|
}
|
|
1719
1723
|
i++;
|
|
1720
|
-
out.push(`<pre><code${lang ? ` class="language-${escapeHtml2(lang)}"` : ""}>${escapeHtml2(body.join("\n"))}</code></pre>`);
|
|
1724
|
+
out.push(`<pre><code${lang ? ` class="language-${escapeAttr(escapeHtml2(lang))}"` : ""}>${escapeHtml2(body.join("\n"))}</code></pre>`);
|
|
1721
1725
|
continue;
|
|
1722
1726
|
}
|
|
1723
1727
|
const esc = escapeHtml2(line);
|