@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.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;
@@ -3918,15 +3920,14 @@ function lineHasBacktick(content, pos) {
3918
3920
  }
3919
3921
  return false;
3920
3922
  }
3921
- function isAtLineStart(content, pos) {
3923
+ function lineIndentBefore(content, pos) {
3922
3924
  let i = pos - 1;
3923
- let spaces = 0;
3924
- while (i >= 0 && content[i] === " ") {
3925
- spaces++;
3926
- if (spaces > 3) return false;
3925
+ let indent = 0;
3926
+ while (i >= 0 && (content[i] === " " || content[i] === " ")) {
3927
+ indent += content[i] === " " ? 4 : 1;
3927
3928
  i--;
3928
3929
  }
3929
- return i < 0 || content[i] === "\n" || content[i] === "\r";
3930
+ return i < 0 || content[i] === "\n" || content[i] === "\r" ? indent : -1;
3930
3931
  }
3931
3932
  function findClosingBacktickRun(content, start, n) {
3932
3933
  let i = start;
@@ -3947,6 +3948,7 @@ function splitByProtectedRegions(content) {
3947
3948
  let multilineStart = -1;
3948
3949
  let multilineFenceMarker = null;
3949
3950
  let multilineFenceLength = 0;
3951
+ let multilineFenceIndent = 0;
3950
3952
  function pushProtected(start, end) {
3951
3953
  if (start > lastIndex) {
3952
3954
  segments.push({ text: content.substring(lastIndex, start), isCode: false });
@@ -3960,7 +3962,8 @@ function splitByProtectedRegions(content) {
3960
3962
  if (multilineStart !== -1) {
3961
3963
  if (char === multilineFenceMarker) {
3962
3964
  const runLen = getRepeatedMarkerLength(content, i, multilineFenceMarker);
3963
- if (runLen >= multilineFenceLength && isAtLineStart(content, i) && restOfLineIsBlank(content, i + runLen)) {
3965
+ const closerIndent = lineIndentBefore(content, i);
3966
+ if (runLen >= multilineFenceLength && closerIndent !== -1 && closerIndent <= multilineFenceIndent + 3 && restOfLineIsBlank(content, i + runLen)) {
3964
3967
  pushProtected(multilineStart, i + runLen);
3965
3968
  multilineStart = -1;
3966
3969
  multilineFenceMarker = null;
@@ -3976,10 +3979,12 @@ function splitByProtectedRegions(content) {
3976
3979
  }
3977
3980
  if (char === "`" || char === "~") {
3978
3981
  const runLen = getRepeatedMarkerLength(content, i, char);
3979
- if (runLen >= 3 && isAtLineStart(content, i) && !(char === "`" && lineHasBacktick(content, i + runLen))) {
3982
+ const openerIndent = lineIndentBefore(content, i);
3983
+ if (runLen >= 3 && openerIndent !== -1 && !(char === "`" && lineHasBacktick(content, i + runLen))) {
3980
3984
  multilineStart = i;
3981
3985
  multilineFenceMarker = char;
3982
3986
  multilineFenceLength = runLen;
3987
+ multilineFenceIndent = openerIndent;
3983
3988
  i += runLen;
3984
3989
  continue;
3985
3990
  }