@ai-react-markdown/engine 2.4.2 → 2.4.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.dev.js CHANGED
@@ -1056,6 +1056,8 @@ function rebaseDualWalk(node, segments, maxEnd, offsetDelta, lineDelta) {
1056
1056
  for (const child of children) rebaseDualWalk(child, segments, maxEnd, offsetDelta, lineDelta);
1057
1057
  }
1058
1058
  }
1059
+ var TABLE_PART_TAG_RE = /<(?:td|th|tr|tbody|thead|tfoot|caption|col|colgroup)\b/i;
1060
+ var STRAY_SYNTHESIZED_END_TAG_RE = /<\/(?:br|p)\b/i;
1059
1061
  function spliceTrees(input) {
1060
1062
  const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
1061
1063
  const injectedLen = injectionPrefix.length;
@@ -1112,6 +1114,12 @@ function spliceTrees(input) {
1112
1114
  return !(start !== void 0 && start < injectedLen);
1113
1115
  });
1114
1116
  const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
1117
+ if (prefixMdast.some((c) => c.type === "html" && TABLE_PART_TAG_RE.test(c.value))) return null;
1118
+ for (const child of tailMdastChildren) {
1119
+ if (isWrapInvisible(child)) continue;
1120
+ if (child.type !== "html") break;
1121
+ if (STRAY_SYNTHESIZED_END_TAG_RE.test(child.value) || TABLE_PART_TAG_RE.test(child.value)) return null;
1122
+ }
1115
1123
  const aligned = alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible);
1116
1124
  if (aligned === null) return null;
1117
1125
  const hastChildren = aligned.children;
@@ -1237,6 +1245,9 @@ function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
1237
1245
  return null;
1238
1246
  }
1239
1247
  const lastIsLiteral = last !== void 0 && last.type === "text" && last.value.trim() !== "";
1248
+ if (lastIsLiteral && pairIdx >= 0 && visibles[pairIdx].type !== "html") {
1249
+ return null;
1250
+ }
1240
1251
  const litOwnerEnd = pairIdx >= 0 ? visibles[pairIdx].position?.end?.offset : void 0;
1241
1252
  const litEnd = lastIsLiteral ? last.position?.end?.offset : void 0;
1242
1253
  if (lastIsLiteral && last.position !== void 0 && (litEnd === void 0 || litOwnerEnd === void 0)) {
@@ -1325,8 +1336,9 @@ function stripInjectedHast(tailMdast, tailHast, injectedLen, tailWrapVisible) {
1325
1336
  }
1326
1337
  function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
1327
1338
  const firstText = tailHastChildren[0];
1328
- if (!firstText) return false;
1329
1339
  const firstVisible = tailMdastChildren.find((c) => !isWrapInvisible(c));
1340
+ if (firstVisible?.type === "html" && STRAY_SYNTHESIZED_END_TAG_RE.test(firstVisible.value)) return null;
1341
+ if (!firstText) return false;
1330
1342
  if (!isSeparatorText(firstText)) {
1331
1343
  if (firstText.type === "text" && firstText.position === void 0 && firstVisible?.type === "html") {
1332
1344
  if (/^\s*<\/[A-Za-z][A-Za-z0-9-]*\s*>/.test(firstVisible.value)) return true;
@@ -1767,17 +1779,8 @@ function phantomSuffixCloser(content) {
1767
1779
  }
1768
1780
 
1769
1781
  // src/components/extractContributions.ts
1770
- function fakeAnchorElement(url) {
1771
- return { type: "element", tagName: "a", properties: { href: url }, children: [] };
1772
- }
1773
- function sanitizeDefUrl(url, urlTransform) {
1774
- if (!urlTransform) return url;
1775
- const result = urlTransform(url, "href", fakeAnchorElement(url));
1776
- return result == null ? "" : String(result);
1777
- }
1778
1782
  function* extractContributions(mdast, options = {}) {
1779
1783
  const phantomFn = options.phantomFootnoteLabels;
1780
- const urlTransform = options.urlTransform;
1781
1784
  const out = [];
1782
1785
  visit3(mdast, (n) => {
1783
1786
  if (n.type === "footnoteReference") {
@@ -1805,7 +1808,7 @@ function* extractContributions(mdast, options = {}) {
1805
1808
  out.push({
1806
1809
  kind: "linkDef",
1807
1810
  label: normalizeId(d.identifier),
1808
- url: sanitizeDefUrl(d.url, urlTransform),
1811
+ url: d.url,
1809
1812
  title: d.title
1810
1813
  });
1811
1814
  }
@@ -3519,8 +3522,7 @@ function isProtocolAllowed(url, allowed) {
3519
3522
  }
3520
3523
  function sanitizeCrossChunkUrl(rawUrl, key, tagName, urlTransform, schema) {
3521
3524
  rawUrl = normalizeUri2(rawUrl);
3522
- const callerProtocols = schema.protocols;
3523
- const allowed = callerProtocols === void 0 || callerProtocols === null ? sanitizeSchema.protocols?.[key] : callerProtocols[key];
3525
+ const allowed = Object.hasOwn(schema, "protocols") ? schema.protocols?.[key] : sanitizeSchema.protocols?.[key];
3524
3526
  if (allowed && allowed.length > 0 && !isProtocolAllowed(rawUrl, allowed)) return null;
3525
3527
  const transformed = urlTransform(rawUrl, key, fakeElement(tagName, key, rawUrl));
3526
3528
  if (transformed == null) return null;
@@ -3930,15 +3932,14 @@ function lineHasBacktick(content, pos) {
3930
3932
  }
3931
3933
  return false;
3932
3934
  }
3933
- function isAtLineStart(content, pos) {
3935
+ function lineIndentBefore(content, pos) {
3934
3936
  let i = pos - 1;
3935
- let spaces = 0;
3936
- while (i >= 0 && content[i] === " ") {
3937
- spaces++;
3938
- if (spaces > 3) return false;
3937
+ let indent = 0;
3938
+ while (i >= 0 && (content[i] === " " || content[i] === " ")) {
3939
+ indent += content[i] === " " ? 4 : 1;
3939
3940
  i--;
3940
3941
  }
3941
- return i < 0 || content[i] === "\n" || content[i] === "\r";
3942
+ return i < 0 || content[i] === "\n" || content[i] === "\r" ? indent : -1;
3942
3943
  }
3943
3944
  function findClosingBacktickRun(content, start, n) {
3944
3945
  let i = start;
@@ -3959,6 +3960,7 @@ function splitByProtectedRegions(content) {
3959
3960
  let multilineStart = -1;
3960
3961
  let multilineFenceMarker = null;
3961
3962
  let multilineFenceLength = 0;
3963
+ let multilineFenceIndent = 0;
3962
3964
  function pushProtected(start, end) {
3963
3965
  if (start > lastIndex) {
3964
3966
  segments.push({ text: content.substring(lastIndex, start), isCode: false });
@@ -3972,7 +3974,8 @@ function splitByProtectedRegions(content) {
3972
3974
  if (multilineStart !== -1) {
3973
3975
  if (char === multilineFenceMarker) {
3974
3976
  const runLen = getRepeatedMarkerLength(content, i, multilineFenceMarker);
3975
- if (runLen >= multilineFenceLength && isAtLineStart(content, i) && restOfLineIsBlank(content, i + runLen)) {
3977
+ const closerIndent = lineIndentBefore(content, i);
3978
+ if (runLen >= multilineFenceLength && closerIndent !== -1 && closerIndent <= multilineFenceIndent + 3 && restOfLineIsBlank(content, i + runLen)) {
3976
3979
  pushProtected(multilineStart, i + runLen);
3977
3980
  multilineStart = -1;
3978
3981
  multilineFenceMarker = null;
@@ -3988,10 +3991,12 @@ function splitByProtectedRegions(content) {
3988
3991
  }
3989
3992
  if (char === "`" || char === "~") {
3990
3993
  const runLen = getRepeatedMarkerLength(content, i, char);
3991
- if (runLen >= 3 && isAtLineStart(content, i) && !(char === "`" && lineHasBacktick(content, i + runLen))) {
3994
+ const openerIndent = lineIndentBefore(content, i);
3995
+ if (runLen >= 3 && openerIndent !== -1 && !(char === "`" && lineHasBacktick(content, i + runLen))) {
3992
3996
  multilineStart = i;
3993
3997
  multilineFenceMarker = char;
3994
3998
  multilineFenceLength = runLen;
3999
+ multilineFenceIndent = openerIndent;
3995
4000
  i += runLen;
3996
4001
  continue;
3997
4002
  }