@pixerate/editor 0.14.1 → 0.14.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/dist/index.js CHANGED
@@ -2536,6 +2536,114 @@ md2.validateLink = (url) => {
2536
2536
  }
2537
2537
  return defaultValidateLink.call(md2, url);
2538
2538
  };
2539
+ var ALLOWED_HTML_TAGS = /* @__PURE__ */ new Set([
2540
+ "a",
2541
+ "abbr",
2542
+ "b",
2543
+ "blockquote",
2544
+ "br",
2545
+ "code",
2546
+ "del",
2547
+ "details",
2548
+ "div",
2549
+ "em",
2550
+ "h1",
2551
+ "h2",
2552
+ "h3",
2553
+ "h4",
2554
+ "h5",
2555
+ "h6",
2556
+ "hr",
2557
+ "i",
2558
+ "img",
2559
+ "input",
2560
+ "kbd",
2561
+ "li",
2562
+ "mark",
2563
+ "ol",
2564
+ "p",
2565
+ "pre",
2566
+ "s",
2567
+ "span",
2568
+ "strong",
2569
+ "sub",
2570
+ "summary",
2571
+ "sup",
2572
+ "table",
2573
+ "tbody",
2574
+ "td",
2575
+ "tfoot",
2576
+ "th",
2577
+ "thead",
2578
+ "tr",
2579
+ "u",
2580
+ "ul"
2581
+ ]);
2582
+ var ALLOWED_HTML_ATTRS = /* @__PURE__ */ new Set([
2583
+ "alt",
2584
+ "align",
2585
+ "checked",
2586
+ "class",
2587
+ "colspan",
2588
+ "disabled",
2589
+ "height",
2590
+ "href",
2591
+ "rel",
2592
+ "rowspan",
2593
+ "src",
2594
+ "start",
2595
+ "target",
2596
+ "title",
2597
+ "type",
2598
+ "width"
2599
+ ]);
2600
+ var HTML_TAG_REGEX = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^\s"'>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)\s*\/?>/g;
2601
+ var HTML_ATTR_REGEX = /([^\s"'>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
2602
+ function sanitizeTag(tagText, isClosing, rawTagName, rawAttrs) {
2603
+ const tagName = rawTagName.toLowerCase();
2604
+ if (!ALLOWED_HTML_TAGS.has(tagName)) return escapeHtml(tagText);
2605
+ if (isClosing) return `</${tagName}>`;
2606
+ if (tagName === "input" && !/\stype\s*=\s*["']?checkbox["']?[\s>/]/i.test(tagText)) {
2607
+ return escapeHtml(tagText);
2608
+ }
2609
+ let attrs = "";
2610
+ let attrMatch;
2611
+ HTML_ATTR_REGEX.lastIndex = 0;
2612
+ while ((attrMatch = HTML_ATTR_REGEX.exec(rawAttrs)) !== null) {
2613
+ const name = attrMatch[1].toLowerCase();
2614
+ if (!ALLOWED_HTML_ATTRS.has(name) && !/^data-[a-z0-9_.-]+$/.test(name)) {
2615
+ continue;
2616
+ }
2617
+ const rawValue = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4];
2618
+ if (rawValue === void 0) {
2619
+ attrs += ` ${name}`;
2620
+ continue;
2621
+ }
2622
+ const value = md2.utils.unescapeAll(rawValue);
2623
+ if ((name === "href" || name === "src") && // Browsers ignore control characters and whitespace inside schemes.
2624
+ !md2.validateLink(value.replace(/[\u0000-\u0020\u007f]/g, ""))) {
2625
+ continue;
2626
+ }
2627
+ attrs += ` ${name}="${escapeHtml(value)}"`;
2628
+ }
2629
+ return `<${tagName}${attrs}>`;
2630
+ }
2631
+ function sanitizeEmbeddedHtml(html) {
2632
+ let result = "";
2633
+ let lastIndex = 0;
2634
+ let match;
2635
+ HTML_TAG_REGEX.lastIndex = 0;
2636
+ while ((match = HTML_TAG_REGEX.exec(html)) !== null) {
2637
+ result += html.slice(lastIndex, match.index).replace(/</g, "&lt;");
2638
+ result += sanitizeTag(match[0], match[1], match[2], match[3]);
2639
+ lastIndex = match.index + match[0].length;
2640
+ }
2641
+ return result + html.slice(lastIndex).replace(/</g, "&lt;");
2642
+ }
2643
+ var defaultHtmlInline = md2.renderer.rules.html_inline;
2644
+ var defaultHtmlBlock = md2.renderer.rules.html_block;
2645
+ md2.renderer.rules.html_inline = (tokens, idx, options, env, self) => env?.allowUnsafeHtml ? defaultHtmlInline(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
2646
+ md2.renderer.rules.html_block = (tokens, idx, options, env, self) => env?.allowUnsafeHtml ? defaultHtmlBlock(tokens, idx, options, env, self) : sanitizeEmbeddedHtml(tokens[idx].content);
2539
2647
  function preprocessMarkdownFileLinks(content) {
2540
2648
  if (!content) return "";
2541
2649
  return content.replace(
@@ -2543,8 +2651,8 @@ function preprocessMarkdownFileLinks(content) {
2543
2651
  (_match, rawLabel, href) => {
2544
2652
  const trimmed = rawLabel.trim();
2545
2653
  const codeMatch = trimmed.match(/^`([^`]+)`$/);
2546
- const labelContent = codeMatch ? `<code>${codeMatch[1]}</code>` : trimmed;
2547
- return `<a href="${href}" data-file-link="true" title="Click to copy file path">${labelContent}</a>`;
2654
+ const labelContent = codeMatch ? `<code>${escapeHtml(codeMatch[1])}</code>` : escapeHtml(trimmed);
2655
+ return `<a href="${escapeHtml(href)}" data-file-link="true" title="Click to copy file path">${labelContent}</a>`;
2548
2656
  }
2549
2657
  );
2550
2658
  }
@@ -2560,7 +2668,7 @@ function markdownToTipTapHtml(markdown, options) {
2560
2668
  };
2561
2669
  content = preprocessMarkdownMentions(content, mentionOpts);
2562
2670
  }
2563
- return md2.render(content);
2671
+ return md2.render(content, { allowUnsafeHtml: options?.allowUnsafeHtml });
2564
2672
  }
2565
2673
  function getEditorMarkdown(editor) {
2566
2674
  if (!editor) return "";