@pixerate/editor 0.14.1 → 0.14.2
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/dist/index.cjs +111 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +111 -3
- package/dist/index.js.map +1 -1
- package/dist/serializers/index.cjs +111 -3
- package/dist/serializers/index.cjs.map +1 -1
- package/dist/serializers/index.d.cts +8 -0
- package/dist/serializers/index.d.ts +8 -0
- package/dist/serializers/index.js +111 -3
- package/dist/serializers/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2698,6 +2698,114 @@ md2.validateLink = (url) => {
|
|
|
2698
2698
|
}
|
|
2699
2699
|
return defaultValidateLink.call(md2, url);
|
|
2700
2700
|
};
|
|
2701
|
+
var ALLOWED_HTML_TAGS = /* @__PURE__ */ new Set([
|
|
2702
|
+
"a",
|
|
2703
|
+
"abbr",
|
|
2704
|
+
"b",
|
|
2705
|
+
"blockquote",
|
|
2706
|
+
"br",
|
|
2707
|
+
"code",
|
|
2708
|
+
"del",
|
|
2709
|
+
"details",
|
|
2710
|
+
"div",
|
|
2711
|
+
"em",
|
|
2712
|
+
"h1",
|
|
2713
|
+
"h2",
|
|
2714
|
+
"h3",
|
|
2715
|
+
"h4",
|
|
2716
|
+
"h5",
|
|
2717
|
+
"h6",
|
|
2718
|
+
"hr",
|
|
2719
|
+
"i",
|
|
2720
|
+
"img",
|
|
2721
|
+
"input",
|
|
2722
|
+
"kbd",
|
|
2723
|
+
"li",
|
|
2724
|
+
"mark",
|
|
2725
|
+
"ol",
|
|
2726
|
+
"p",
|
|
2727
|
+
"pre",
|
|
2728
|
+
"s",
|
|
2729
|
+
"span",
|
|
2730
|
+
"strong",
|
|
2731
|
+
"sub",
|
|
2732
|
+
"summary",
|
|
2733
|
+
"sup",
|
|
2734
|
+
"table",
|
|
2735
|
+
"tbody",
|
|
2736
|
+
"td",
|
|
2737
|
+
"tfoot",
|
|
2738
|
+
"th",
|
|
2739
|
+
"thead",
|
|
2740
|
+
"tr",
|
|
2741
|
+
"u",
|
|
2742
|
+
"ul"
|
|
2743
|
+
]);
|
|
2744
|
+
var ALLOWED_HTML_ATTRS = /* @__PURE__ */ new Set([
|
|
2745
|
+
"alt",
|
|
2746
|
+
"align",
|
|
2747
|
+
"checked",
|
|
2748
|
+
"class",
|
|
2749
|
+
"colspan",
|
|
2750
|
+
"disabled",
|
|
2751
|
+
"height",
|
|
2752
|
+
"href",
|
|
2753
|
+
"rel",
|
|
2754
|
+
"rowspan",
|
|
2755
|
+
"src",
|
|
2756
|
+
"start",
|
|
2757
|
+
"target",
|
|
2758
|
+
"title",
|
|
2759
|
+
"type",
|
|
2760
|
+
"width"
|
|
2761
|
+
]);
|
|
2762
|
+
var HTML_TAG_REGEX = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^\s"'>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)\s*\/?>/g;
|
|
2763
|
+
var HTML_ATTR_REGEX = /([^\s"'>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
2764
|
+
function sanitizeTag(tagText, isClosing, rawTagName, rawAttrs) {
|
|
2765
|
+
const tagName = rawTagName.toLowerCase();
|
|
2766
|
+
if (!ALLOWED_HTML_TAGS.has(tagName)) return escapeHtml(tagText);
|
|
2767
|
+
if (isClosing) return `</${tagName}>`;
|
|
2768
|
+
if (tagName === "input" && !/\stype\s*=\s*["']?checkbox["']?[\s>/]/i.test(tagText)) {
|
|
2769
|
+
return escapeHtml(tagText);
|
|
2770
|
+
}
|
|
2771
|
+
let attrs = "";
|
|
2772
|
+
let attrMatch;
|
|
2773
|
+
HTML_ATTR_REGEX.lastIndex = 0;
|
|
2774
|
+
while ((attrMatch = HTML_ATTR_REGEX.exec(rawAttrs)) !== null) {
|
|
2775
|
+
const name = attrMatch[1].toLowerCase();
|
|
2776
|
+
if (!ALLOWED_HTML_ATTRS.has(name) && !/^data-[a-z0-9_.-]+$/.test(name)) {
|
|
2777
|
+
continue;
|
|
2778
|
+
}
|
|
2779
|
+
const rawValue = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4];
|
|
2780
|
+
if (rawValue === void 0) {
|
|
2781
|
+
attrs += ` ${name}`;
|
|
2782
|
+
continue;
|
|
2783
|
+
}
|
|
2784
|
+
const value = md2.utils.unescapeAll(rawValue);
|
|
2785
|
+
if ((name === "href" || name === "src") && // Browsers ignore control characters and whitespace inside schemes.
|
|
2786
|
+
!md2.validateLink(value.replace(/[\u0000-\u0020\u007f]/g, ""))) {
|
|
2787
|
+
continue;
|
|
2788
|
+
}
|
|
2789
|
+
attrs += ` ${name}="${escapeHtml(value)}"`;
|
|
2790
|
+
}
|
|
2791
|
+
return `<${tagName}${attrs}>`;
|
|
2792
|
+
}
|
|
2793
|
+
function sanitizeEmbeddedHtml(html) {
|
|
2794
|
+
let result = "";
|
|
2795
|
+
let lastIndex = 0;
|
|
2796
|
+
let match;
|
|
2797
|
+
HTML_TAG_REGEX.lastIndex = 0;
|
|
2798
|
+
while ((match = HTML_TAG_REGEX.exec(html)) !== null) {
|
|
2799
|
+
result += html.slice(lastIndex, match.index).replace(/</g, "<");
|
|
2800
|
+
result += sanitizeTag(match[0], match[1], match[2], match[3]);
|
|
2801
|
+
lastIndex = match.index + match[0].length;
|
|
2802
|
+
}
|
|
2803
|
+
return result + html.slice(lastIndex).replace(/</g, "<");
|
|
2804
|
+
}
|
|
2805
|
+
var defaultHtmlInline = md2.renderer.rules.html_inline;
|
|
2806
|
+
var defaultHtmlBlock = md2.renderer.rules.html_block;
|
|
2807
|
+
md2.renderer.rules.html_inline = (tokens, idx, options, env, self) => env?.allowUnsafeHtml ? defaultHtmlInline(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
|
|
2808
|
+
md2.renderer.rules.html_block = (tokens, idx, options, env, self) => env?.allowUnsafeHtml ? defaultHtmlBlock(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
|
|
2701
2809
|
function preprocessMarkdownFileLinks(content) {
|
|
2702
2810
|
if (!content) return "";
|
|
2703
2811
|
return content.replace(
|
|
@@ -2705,8 +2813,8 @@ function preprocessMarkdownFileLinks(content) {
|
|
|
2705
2813
|
(_match, rawLabel, href) => {
|
|
2706
2814
|
const trimmed = rawLabel.trim();
|
|
2707
2815
|
const codeMatch = trimmed.match(/^`([^`]+)`$/);
|
|
2708
|
-
const labelContent = codeMatch ? `<code>${codeMatch[1]}</code>` : trimmed;
|
|
2709
|
-
return `<a href="${href}" data-file-link="true" title="Click to copy file path">${labelContent}</a>`;
|
|
2816
|
+
const labelContent = codeMatch ? `<code>${escapeHtml(codeMatch[1])}</code>` : escapeHtml(trimmed);
|
|
2817
|
+
return `<a href="${escapeHtml(href)}" data-file-link="true" title="Click to copy file path">${labelContent}</a>`;
|
|
2710
2818
|
}
|
|
2711
2819
|
);
|
|
2712
2820
|
}
|
|
@@ -2722,7 +2830,7 @@ function markdownToTipTapHtml(markdown, options) {
|
|
|
2722
2830
|
};
|
|
2723
2831
|
content = preprocessMarkdownMentions(content, mentionOpts);
|
|
2724
2832
|
}
|
|
2725
|
-
return md2.render(content);
|
|
2833
|
+
return md2.render(content, { allowUnsafeHtml: options?.allowUnsafeHtml });
|
|
2726
2834
|
}
|
|
2727
2835
|
function getEditorMarkdown(editor) {
|
|
2728
2836
|
if (!editor) return "";
|