@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 CHANGED
@@ -85,3 +85,9 @@ import { CodeEditor } from "@particle-academy/fancy-code";
85
85
  ## License
86
86
 
87
87
  MIT
88
+
89
+ ---
90
+
91
+ ## ⭐ Star Fancy UI
92
+
93
+ If this package is useful to you, a quick ⭐ on the repo really helps us build a better kit. Thank you!
package/dist/index.cjs CHANGED
@@ -1079,6 +1079,7 @@ function tokenizeMarkdown(source) {
1079
1079
  return tokens;
1080
1080
  }
1081
1081
  function pushInline(line, base, out) {
1082
+ if (line.length > 5e3) return;
1082
1083
  const spans = [];
1083
1084
  const add = (type, start, end) => {
1084
1085
  spans.push(tok(type, base + start, base + end));
@@ -1684,8 +1685,11 @@ var CodeEditor = Object.assign(CodeEditorRoot, {
1684
1685
  function escapeHtml2(s) {
1685
1686
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1686
1687
  }
1688
+ function escapeAttr(s) {
1689
+ return s.replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1690
+ }
1687
1691
  function inline(text) {
1688
- 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>");
1692
+ 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>");
1689
1693
  }
1690
1694
  function renderMarkdown(markdown) {
1691
1695
  const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
@@ -1719,7 +1723,7 @@ function renderMarkdown(markdown) {
1719
1723
  i++;
1720
1724
  }
1721
1725
  i++;
1722
- out.push(`<pre><code${lang ? ` class="language-${escapeHtml2(lang)}"` : ""}>${escapeHtml2(body.join("\n"))}</code></pre>`);
1726
+ out.push(`<pre><code${lang ? ` class="language-${escapeAttr(escapeHtml2(lang))}"` : ""}>${escapeHtml2(body.join("\n"))}</code></pre>`);
1723
1727
  continue;
1724
1728
  }
1725
1729
  const esc = escapeHtml2(line);