@ai-react-markdown/engine 2.5.4 → 2.6.0
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 +99 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -194
- package/dist/index.d.ts +7 -194
- package/dist/index.dev.cjs +99 -11
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +99 -11
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +99 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -337,6 +337,26 @@ var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
|
|
|
337
337
|
"var"
|
|
338
338
|
]);
|
|
339
339
|
var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "title", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
|
|
340
|
+
var SCOPE_BARRIER_NAMES = /* @__PURE__ */ new Set([
|
|
341
|
+
"applet",
|
|
342
|
+
"caption",
|
|
343
|
+
"html",
|
|
344
|
+
"table",
|
|
345
|
+
"td",
|
|
346
|
+
"th",
|
|
347
|
+
"marquee",
|
|
348
|
+
"object",
|
|
349
|
+
"template",
|
|
350
|
+
"mi",
|
|
351
|
+
"mo",
|
|
352
|
+
"mn",
|
|
353
|
+
"ms",
|
|
354
|
+
"mtext",
|
|
355
|
+
"annotation-xml",
|
|
356
|
+
"foreignobject",
|
|
357
|
+
"desc",
|
|
358
|
+
"title"
|
|
359
|
+
]);
|
|
340
360
|
var FOREIGN_ROOT_NAMES = ["svg", "math"];
|
|
341
361
|
var TYPE1_NAMES = /* @__PURE__ */ new Set(["script", "pre", "style", "textarea"]);
|
|
342
362
|
var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
@@ -507,6 +527,7 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
507
527
|
piOpen: false,
|
|
508
528
|
bogusOpen: false,
|
|
509
529
|
rawTextOpen: null,
|
|
530
|
+
openStack: [],
|
|
510
531
|
scriptDataEscaped: false,
|
|
511
532
|
declOpen: false,
|
|
512
533
|
cdataOpen: false,
|
|
@@ -630,7 +651,8 @@ function classifyBlockStart(text, indent, defListEnabled) {
|
|
|
630
651
|
function computeFreezeBoundary(text, options, resume) {
|
|
631
652
|
const mathFlow = options.mathFlow ?? true;
|
|
632
653
|
const referenceTaint = options.referenceTaint ?? true;
|
|
633
|
-
const
|
|
654
|
+
const prev = resume;
|
|
655
|
+
const cp = prev && prev.defListEnabled === options.defListEnabled && prev.mathFlow === mathFlow && prev.referenceTaint === referenceTaint && prev.confirmedOffset <= text.length ? prev : freshCheckpoint(options.defListEnabled, mathFlow, referenceTaint);
|
|
634
656
|
let start = cp.confirmedOffset;
|
|
635
657
|
let tailLine = null;
|
|
636
658
|
while (start < text.length) {
|
|
@@ -693,6 +715,14 @@ function computeFreezeBoundary(text, options, resume) {
|
|
|
693
715
|
}
|
|
694
716
|
return { boundary, checkpoint: cp };
|
|
695
717
|
}
|
|
718
|
+
function pendingFenceCloser(checkpoint) {
|
|
719
|
+
const cp = checkpoint;
|
|
720
|
+
if (cp.phasePoisonedAt !== Infinity) return "";
|
|
721
|
+
if (cp.openIndent !== 0) return "";
|
|
722
|
+
if (cp.inFence) return cp.fenceChar.repeat(cp.fenceLen);
|
|
723
|
+
if (cp.inMath) return "$".repeat(cp.mathFenceLen);
|
|
724
|
+
return "";
|
|
725
|
+
}
|
|
696
726
|
function floatingResidue(text, commentOpenAtStart) {
|
|
697
727
|
let out = "";
|
|
698
728
|
let open = commentOpenAtStart;
|
|
@@ -768,6 +798,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
768
798
|
cp.openTotal -= count;
|
|
769
799
|
}
|
|
770
800
|
}
|
|
801
|
+
if (cp.openStack.length > 0) cp.openStack = cp.openStack.filter((n) => !FOREIGN_ROOT_NAMES.includes(n));
|
|
771
802
|
};
|
|
772
803
|
const noteBreakout = (tag, closing) => {
|
|
773
804
|
if (closing || cp.rawTextOpen !== null) return;
|
|
@@ -791,13 +822,25 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
791
822
|
}
|
|
792
823
|
}
|
|
793
824
|
if (DOCUMENT_STRUCTURE_NAMES.has(tag)) cp.phasePoisonedAt = 0;
|
|
825
|
+
if (tag === "template" && !closing) cp.phasePoisonedAt = 0;
|
|
794
826
|
if (closing) {
|
|
827
|
+
let idx = -1;
|
|
828
|
+
for (let i = cp.openStack.length - 1; i >= 0; i--) {
|
|
829
|
+
if (cp.openStack[i] === tag) {
|
|
830
|
+
idx = i;
|
|
831
|
+
break;
|
|
832
|
+
}
|
|
833
|
+
if (SCOPE_BARRIER_NAMES.has(cp.openStack[i])) break;
|
|
834
|
+
}
|
|
835
|
+
if (idx === -1) return;
|
|
836
|
+
cp.openStack.splice(idx, 1);
|
|
795
837
|
const count = cp.tagBalance.get(tag) ?? 0;
|
|
796
838
|
if (count > 0) {
|
|
797
839
|
cp.tagBalance.set(tag, count - 1);
|
|
798
840
|
cp.openTotal -= 1;
|
|
799
841
|
}
|
|
800
842
|
} else {
|
|
843
|
+
cp.openStack.push(tag);
|
|
801
844
|
cp.tagBalance.set(tag, (cp.tagBalance.get(tag) ?? 0) + 1);
|
|
802
845
|
cp.openTotal += 1;
|
|
803
846
|
}
|
|
@@ -916,6 +959,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
916
959
|
if (!cp.type1FlowOpen) {
|
|
917
960
|
cp.htmlFlowSinceBlank = false;
|
|
918
961
|
cp.htmlFlowReal = false;
|
|
962
|
+
if (cp.rawTextOpen !== null && !cp.rawTextInline) {
|
|
963
|
+
cp.phasePoisonedAt = 0;
|
|
964
|
+
}
|
|
919
965
|
}
|
|
920
966
|
cp.prevLineBlank = true;
|
|
921
967
|
cp.prevLineWasText = false;
|
|
@@ -1015,6 +1061,7 @@ ${cont(scanText)}` };
|
|
|
1015
1061
|
const poisonRawDivergence = () => {
|
|
1016
1062
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1017
1063
|
};
|
|
1064
|
+
let inlineRawOpenerIdx = -1;
|
|
1018
1065
|
while (pos < scanText.length) {
|
|
1019
1066
|
if (cp.piOpen) {
|
|
1020
1067
|
const c = scanText.indexOf("?>", pos);
|
|
@@ -1070,6 +1117,7 @@ ${cont(scanText)}` };
|
|
|
1070
1117
|
} else if (first === cd) {
|
|
1071
1118
|
rawSpans.push([cd, cd + 9]);
|
|
1072
1119
|
cp.cdataOpen = true;
|
|
1120
|
+
if (!isMdBlank(scanText.slice(0, cd)) || ln.indent > 3) inlineRawOpenerIdx = cd;
|
|
1073
1121
|
pos = cd + 9;
|
|
1074
1122
|
} else if (first === pi) {
|
|
1075
1123
|
if (scanText[pi + 2] === ">") {
|
|
@@ -1080,14 +1128,19 @@ ${cont(scanText)}` };
|
|
|
1080
1128
|
}
|
|
1081
1129
|
rawSpans.push([pi, pi + 2]);
|
|
1082
1130
|
cp.piOpen = true;
|
|
1131
|
+
if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) inlineRawOpenerIdx = pi;
|
|
1083
1132
|
pos = pi + 2;
|
|
1084
1133
|
} else {
|
|
1085
1134
|
rawSpans.push([decl, decl + 2]);
|
|
1086
1135
|
if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
|
|
1087
1136
|
cp.declOpen = true;
|
|
1137
|
+
if (!isMdBlank(scanText.slice(0, decl)) || ln.indent > 3) inlineRawOpenerIdx = decl;
|
|
1088
1138
|
pos = decl + 2;
|
|
1089
1139
|
}
|
|
1090
1140
|
}
|
|
1141
|
+
if (inlineRawOpenerIdx !== -1 && (cp.piOpen || cp.declOpen || cp.cdataOpen)) {
|
|
1142
|
+
cp.phasePoisonedAt = 0;
|
|
1143
|
+
}
|
|
1091
1144
|
let tagText = scanText;
|
|
1092
1145
|
for (const [from, to] of rawSpans) {
|
|
1093
1146
|
tagText = tagText.slice(0, from) + " ".repeat(to - from) + tagText.slice(to);
|
|
@@ -1176,9 +1229,9 @@ ${cont(scanText)}` };
|
|
|
1176
1229
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
1177
1230
|
applyTag(tag, closing);
|
|
1178
1231
|
}
|
|
1179
|
-
if (cp.commentOpen && lastCommentOpenerIdx !== -1
|
|
1180
|
-
if (!isMdBlank(tagText.slice(0, lastCommentOpenerIdx))) {
|
|
1181
|
-
cp.phasePoisonedAt =
|
|
1232
|
+
if (cp.commentOpen && lastCommentOpenerIdx !== -1) {
|
|
1233
|
+
if (!isMdBlank(tagText.slice(0, lastCommentOpenerIdx)) || ln.indent > 3) {
|
|
1234
|
+
cp.phasePoisonedAt = 0;
|
|
1182
1235
|
}
|
|
1183
1236
|
}
|
|
1184
1237
|
if (masked !== null && masked !== ln.text) {
|
|
@@ -1478,6 +1531,40 @@ function hasStrayTablePart(values) {
|
|
|
1478
1531
|
}
|
|
1479
1532
|
return false;
|
|
1480
1533
|
}
|
|
1534
|
+
var HEAD_ROUTED_NAMES = /* @__PURE__ */ new Set([
|
|
1535
|
+
"base",
|
|
1536
|
+
"basefont",
|
|
1537
|
+
"bgsound",
|
|
1538
|
+
"link",
|
|
1539
|
+
"meta",
|
|
1540
|
+
"noframes",
|
|
1541
|
+
"script",
|
|
1542
|
+
"style",
|
|
1543
|
+
"template",
|
|
1544
|
+
"title"
|
|
1545
|
+
]);
|
|
1546
|
+
var HEAD_ROUTED_RAW_TEXT_RE = /<(script|style|title|noframes)(?=[\s/>])/i;
|
|
1547
|
+
var ANY_START_TAG_RE = /<([a-z][a-z0-9-]*)(?=[\s/>])/gi;
|
|
1548
|
+
function headRoutedCaptureUnclosed(values) {
|
|
1549
|
+
if (values.length === 0) return false;
|
|
1550
|
+
const joined = values.join("\n");
|
|
1551
|
+
const opener = HEAD_ROUTED_RAW_TEXT_RE.exec(joined);
|
|
1552
|
+
if (opener === null) return false;
|
|
1553
|
+
const before = joined.slice(0, opener.index);
|
|
1554
|
+
if (/<[!?]/.test(before)) return true;
|
|
1555
|
+
ANY_START_TAG_RE.lastIndex = 0;
|
|
1556
|
+
let m;
|
|
1557
|
+
while ((m = ANY_START_TAG_RE.exec(before)) !== null) {
|
|
1558
|
+
if (!HEAD_ROUTED_NAMES.has(m[1].toLowerCase())) return false;
|
|
1559
|
+
}
|
|
1560
|
+
const name = opener[1].toLowerCase();
|
|
1561
|
+
const after = joined.slice(opener.index + opener[0].length);
|
|
1562
|
+
if (name === "script") {
|
|
1563
|
+
const close = after.search(/<\/script(?=[\s/>])/i);
|
|
1564
|
+
return close === -1 || /<!--/.test(after.slice(0, close));
|
|
1565
|
+
}
|
|
1566
|
+
return !new RegExp(`</${name}(?=[\\s/>])`, "i").test(after);
|
|
1567
|
+
}
|
|
1481
1568
|
var STRAY_SYNTHESIZED_END_TAG_RE = /<\/(?:br|p)\b/i;
|
|
1482
1569
|
function spliceTrees(input) {
|
|
1483
1570
|
const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
|
|
@@ -1536,11 +1623,14 @@ function spliceTrees(input) {
|
|
|
1536
1623
|
});
|
|
1537
1624
|
const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
|
|
1538
1625
|
if (hasStrayTablePart(prefixMdast.flatMap((c) => c.type === "html" ? [c.value] : []))) return null;
|
|
1626
|
+
const leadingHtml = [];
|
|
1539
1627
|
for (const child of tailMdastChildren) {
|
|
1540
1628
|
if (isWrapInvisible(child)) continue;
|
|
1541
1629
|
if (child.type !== "html") break;
|
|
1542
1630
|
if (STRAY_SYNTHESIZED_END_TAG_RE.test(child.value) || TABLE_PART_TAG_RE.test(child.value)) return null;
|
|
1631
|
+
leadingHtml.push(child.value);
|
|
1543
1632
|
}
|
|
1633
|
+
if (headRoutedCaptureUnclosed(leadingHtml)) return null;
|
|
1544
1634
|
const aligned = alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible);
|
|
1545
1635
|
if (aligned === null) return null;
|
|
1546
1636
|
const hastChildren = aligned.children;
|
|
@@ -2184,12 +2274,10 @@ function phantomSuffixCloser(content) {
|
|
|
2184
2274
|
const endsWithNewline = content.endsWith("\n");
|
|
2185
2275
|
const confirmed = endsWithNewline ? content : content + "\n";
|
|
2186
2276
|
const { checkpoint } = computeFreezeBoundary(confirmed, { defListEnabled: false, referenceTaint: false });
|
|
2187
|
-
|
|
2188
|
-
if (
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
if (checkpoint.inMath) return `${nl}${"$".repeat(checkpoint.mathFenceLen)}`;
|
|
2192
|
-
return "";
|
|
2277
|
+
const closer = pendingFenceCloser(checkpoint);
|
|
2278
|
+
if (closer === "") return "";
|
|
2279
|
+
return endsWithNewline ? closer : `
|
|
2280
|
+
${closer}`;
|
|
2193
2281
|
}
|
|
2194
2282
|
|
|
2195
2283
|
// src/components/extractContributions.ts
|
|
@@ -2465,7 +2553,7 @@ function createRegistry(onEmpty) {
|
|
|
2465
2553
|
|
|
2466
2554
|
// src/components/pluginChain.ts
|
|
2467
2555
|
var import_rehype_katex = __toESM(require("rehype-katex"), 1);
|
|
2468
|
-
var import_rehype_raw = __toESM(require("rehype-raw"), 1);
|
|
2556
|
+
var import_rehype_raw = __toESM(require("@ai-markdown/rehype-raw"), 1);
|
|
2469
2557
|
var import_rehype_unwrap_images = __toESM(require("rehype-unwrap-images"), 1);
|
|
2470
2558
|
|
|
2471
2559
|
// src/components/rehypeUnwrapCrossChunkImages.ts
|