@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.js
CHANGED
|
@@ -244,6 +244,26 @@ var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
|
|
|
244
244
|
"var"
|
|
245
245
|
]);
|
|
246
246
|
var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "title", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
|
|
247
|
+
var SCOPE_BARRIER_NAMES = /* @__PURE__ */ new Set([
|
|
248
|
+
"applet",
|
|
249
|
+
"caption",
|
|
250
|
+
"html",
|
|
251
|
+
"table",
|
|
252
|
+
"td",
|
|
253
|
+
"th",
|
|
254
|
+
"marquee",
|
|
255
|
+
"object",
|
|
256
|
+
"template",
|
|
257
|
+
"mi",
|
|
258
|
+
"mo",
|
|
259
|
+
"mn",
|
|
260
|
+
"ms",
|
|
261
|
+
"mtext",
|
|
262
|
+
"annotation-xml",
|
|
263
|
+
"foreignobject",
|
|
264
|
+
"desc",
|
|
265
|
+
"title"
|
|
266
|
+
]);
|
|
247
267
|
var FOREIGN_ROOT_NAMES = ["svg", "math"];
|
|
248
268
|
var TYPE1_NAMES = /* @__PURE__ */ new Set(["script", "pre", "style", "textarea"]);
|
|
249
269
|
var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
@@ -414,6 +434,7 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
414
434
|
piOpen: false,
|
|
415
435
|
bogusOpen: false,
|
|
416
436
|
rawTextOpen: null,
|
|
437
|
+
openStack: [],
|
|
417
438
|
scriptDataEscaped: false,
|
|
418
439
|
declOpen: false,
|
|
419
440
|
cdataOpen: false,
|
|
@@ -537,7 +558,8 @@ function classifyBlockStart(text, indent, defListEnabled) {
|
|
|
537
558
|
function computeFreezeBoundary(text, options, resume) {
|
|
538
559
|
const mathFlow = options.mathFlow ?? true;
|
|
539
560
|
const referenceTaint = options.referenceTaint ?? true;
|
|
540
|
-
const
|
|
561
|
+
const prev = resume;
|
|
562
|
+
const cp = prev && prev.defListEnabled === options.defListEnabled && prev.mathFlow === mathFlow && prev.referenceTaint === referenceTaint && prev.confirmedOffset <= text.length ? prev : freshCheckpoint(options.defListEnabled, mathFlow, referenceTaint);
|
|
541
563
|
let start = cp.confirmedOffset;
|
|
542
564
|
let tailLine = null;
|
|
543
565
|
while (start < text.length) {
|
|
@@ -600,6 +622,14 @@ function computeFreezeBoundary(text, options, resume) {
|
|
|
600
622
|
}
|
|
601
623
|
return { boundary, checkpoint: cp };
|
|
602
624
|
}
|
|
625
|
+
function pendingFenceCloser(checkpoint) {
|
|
626
|
+
const cp = checkpoint;
|
|
627
|
+
if (cp.phasePoisonedAt !== Infinity) return "";
|
|
628
|
+
if (cp.openIndent !== 0) return "";
|
|
629
|
+
if (cp.inFence) return cp.fenceChar.repeat(cp.fenceLen);
|
|
630
|
+
if (cp.inMath) return "$".repeat(cp.mathFenceLen);
|
|
631
|
+
return "";
|
|
632
|
+
}
|
|
603
633
|
function floatingResidue(text, commentOpenAtStart) {
|
|
604
634
|
let out = "";
|
|
605
635
|
let open = commentOpenAtStart;
|
|
@@ -675,6 +705,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
675
705
|
cp.openTotal -= count;
|
|
676
706
|
}
|
|
677
707
|
}
|
|
708
|
+
if (cp.openStack.length > 0) cp.openStack = cp.openStack.filter((n) => !FOREIGN_ROOT_NAMES.includes(n));
|
|
678
709
|
};
|
|
679
710
|
const noteBreakout = (tag, closing) => {
|
|
680
711
|
if (closing || cp.rawTextOpen !== null) return;
|
|
@@ -698,13 +729,25 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
698
729
|
}
|
|
699
730
|
}
|
|
700
731
|
if (DOCUMENT_STRUCTURE_NAMES.has(tag)) cp.phasePoisonedAt = 0;
|
|
732
|
+
if (tag === "template" && !closing) cp.phasePoisonedAt = 0;
|
|
701
733
|
if (closing) {
|
|
734
|
+
let idx = -1;
|
|
735
|
+
for (let i = cp.openStack.length - 1; i >= 0; i--) {
|
|
736
|
+
if (cp.openStack[i] === tag) {
|
|
737
|
+
idx = i;
|
|
738
|
+
break;
|
|
739
|
+
}
|
|
740
|
+
if (SCOPE_BARRIER_NAMES.has(cp.openStack[i])) break;
|
|
741
|
+
}
|
|
742
|
+
if (idx === -1) return;
|
|
743
|
+
cp.openStack.splice(idx, 1);
|
|
702
744
|
const count = cp.tagBalance.get(tag) ?? 0;
|
|
703
745
|
if (count > 0) {
|
|
704
746
|
cp.tagBalance.set(tag, count - 1);
|
|
705
747
|
cp.openTotal -= 1;
|
|
706
748
|
}
|
|
707
749
|
} else {
|
|
750
|
+
cp.openStack.push(tag);
|
|
708
751
|
cp.tagBalance.set(tag, (cp.tagBalance.get(tag) ?? 0) + 1);
|
|
709
752
|
cp.openTotal += 1;
|
|
710
753
|
}
|
|
@@ -823,6 +866,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
823
866
|
if (!cp.type1FlowOpen) {
|
|
824
867
|
cp.htmlFlowSinceBlank = false;
|
|
825
868
|
cp.htmlFlowReal = false;
|
|
869
|
+
if (cp.rawTextOpen !== null && !cp.rawTextInline) {
|
|
870
|
+
cp.phasePoisonedAt = 0;
|
|
871
|
+
}
|
|
826
872
|
}
|
|
827
873
|
cp.prevLineBlank = true;
|
|
828
874
|
cp.prevLineWasText = false;
|
|
@@ -922,6 +968,7 @@ ${cont(scanText)}` };
|
|
|
922
968
|
const poisonRawDivergence = () => {
|
|
923
969
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
924
970
|
};
|
|
971
|
+
let inlineRawOpenerIdx = -1;
|
|
925
972
|
while (pos < scanText.length) {
|
|
926
973
|
if (cp.piOpen) {
|
|
927
974
|
const c = scanText.indexOf("?>", pos);
|
|
@@ -977,6 +1024,7 @@ ${cont(scanText)}` };
|
|
|
977
1024
|
} else if (first === cd) {
|
|
978
1025
|
rawSpans.push([cd, cd + 9]);
|
|
979
1026
|
cp.cdataOpen = true;
|
|
1027
|
+
if (!isMdBlank(scanText.slice(0, cd)) || ln.indent > 3) inlineRawOpenerIdx = cd;
|
|
980
1028
|
pos = cd + 9;
|
|
981
1029
|
} else if (first === pi) {
|
|
982
1030
|
if (scanText[pi + 2] === ">") {
|
|
@@ -987,14 +1035,19 @@ ${cont(scanText)}` };
|
|
|
987
1035
|
}
|
|
988
1036
|
rawSpans.push([pi, pi + 2]);
|
|
989
1037
|
cp.piOpen = true;
|
|
1038
|
+
if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) inlineRawOpenerIdx = pi;
|
|
990
1039
|
pos = pi + 2;
|
|
991
1040
|
} else {
|
|
992
1041
|
rawSpans.push([decl, decl + 2]);
|
|
993
1042
|
if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
|
|
994
1043
|
cp.declOpen = true;
|
|
1044
|
+
if (!isMdBlank(scanText.slice(0, decl)) || ln.indent > 3) inlineRawOpenerIdx = decl;
|
|
995
1045
|
pos = decl + 2;
|
|
996
1046
|
}
|
|
997
1047
|
}
|
|
1048
|
+
if (inlineRawOpenerIdx !== -1 && (cp.piOpen || cp.declOpen || cp.cdataOpen)) {
|
|
1049
|
+
cp.phasePoisonedAt = 0;
|
|
1050
|
+
}
|
|
998
1051
|
let tagText = scanText;
|
|
999
1052
|
for (const [from, to] of rawSpans) {
|
|
1000
1053
|
tagText = tagText.slice(0, from) + " ".repeat(to - from) + tagText.slice(to);
|
|
@@ -1083,9 +1136,9 @@ ${cont(scanText)}` };
|
|
|
1083
1136
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
1084
1137
|
applyTag(tag, closing);
|
|
1085
1138
|
}
|
|
1086
|
-
if (cp.commentOpen && lastCommentOpenerIdx !== -1
|
|
1087
|
-
if (!isMdBlank(tagText.slice(0, lastCommentOpenerIdx))) {
|
|
1088
|
-
cp.phasePoisonedAt =
|
|
1139
|
+
if (cp.commentOpen && lastCommentOpenerIdx !== -1) {
|
|
1140
|
+
if (!isMdBlank(tagText.slice(0, lastCommentOpenerIdx)) || ln.indent > 3) {
|
|
1141
|
+
cp.phasePoisonedAt = 0;
|
|
1089
1142
|
}
|
|
1090
1143
|
}
|
|
1091
1144
|
if (masked !== null && masked !== ln.text) {
|
|
@@ -1385,6 +1438,40 @@ function hasStrayTablePart(values) {
|
|
|
1385
1438
|
}
|
|
1386
1439
|
return false;
|
|
1387
1440
|
}
|
|
1441
|
+
var HEAD_ROUTED_NAMES = /* @__PURE__ */ new Set([
|
|
1442
|
+
"base",
|
|
1443
|
+
"basefont",
|
|
1444
|
+
"bgsound",
|
|
1445
|
+
"link",
|
|
1446
|
+
"meta",
|
|
1447
|
+
"noframes",
|
|
1448
|
+
"script",
|
|
1449
|
+
"style",
|
|
1450
|
+
"template",
|
|
1451
|
+
"title"
|
|
1452
|
+
]);
|
|
1453
|
+
var HEAD_ROUTED_RAW_TEXT_RE = /<(script|style|title|noframes)(?=[\s/>])/i;
|
|
1454
|
+
var ANY_START_TAG_RE = /<([a-z][a-z0-9-]*)(?=[\s/>])/gi;
|
|
1455
|
+
function headRoutedCaptureUnclosed(values) {
|
|
1456
|
+
if (values.length === 0) return false;
|
|
1457
|
+
const joined = values.join("\n");
|
|
1458
|
+
const opener = HEAD_ROUTED_RAW_TEXT_RE.exec(joined);
|
|
1459
|
+
if (opener === null) return false;
|
|
1460
|
+
const before = joined.slice(0, opener.index);
|
|
1461
|
+
if (/<[!?]/.test(before)) return true;
|
|
1462
|
+
ANY_START_TAG_RE.lastIndex = 0;
|
|
1463
|
+
let m;
|
|
1464
|
+
while ((m = ANY_START_TAG_RE.exec(before)) !== null) {
|
|
1465
|
+
if (!HEAD_ROUTED_NAMES.has(m[1].toLowerCase())) return false;
|
|
1466
|
+
}
|
|
1467
|
+
const name = opener[1].toLowerCase();
|
|
1468
|
+
const after = joined.slice(opener.index + opener[0].length);
|
|
1469
|
+
if (name === "script") {
|
|
1470
|
+
const close = after.search(/<\/script(?=[\s/>])/i);
|
|
1471
|
+
return close === -1 || /<!--/.test(after.slice(0, close));
|
|
1472
|
+
}
|
|
1473
|
+
return !new RegExp(`</${name}(?=[\\s/>])`, "i").test(after);
|
|
1474
|
+
}
|
|
1388
1475
|
var STRAY_SYNTHESIZED_END_TAG_RE = /<\/(?:br|p)\b/i;
|
|
1389
1476
|
function spliceTrees(input) {
|
|
1390
1477
|
const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
|
|
@@ -1443,11 +1530,14 @@ function spliceTrees(input) {
|
|
|
1443
1530
|
});
|
|
1444
1531
|
const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
|
|
1445
1532
|
if (hasStrayTablePart(prefixMdast.flatMap((c) => c.type === "html" ? [c.value] : []))) return null;
|
|
1533
|
+
const leadingHtml = [];
|
|
1446
1534
|
for (const child of tailMdastChildren) {
|
|
1447
1535
|
if (isWrapInvisible(child)) continue;
|
|
1448
1536
|
if (child.type !== "html") break;
|
|
1449
1537
|
if (STRAY_SYNTHESIZED_END_TAG_RE.test(child.value) || TABLE_PART_TAG_RE.test(child.value)) return null;
|
|
1538
|
+
leadingHtml.push(child.value);
|
|
1450
1539
|
}
|
|
1540
|
+
if (headRoutedCaptureUnclosed(leadingHtml)) return null;
|
|
1451
1541
|
const aligned = alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible);
|
|
1452
1542
|
if (aligned === null) return null;
|
|
1453
1543
|
const hastChildren = aligned.children;
|
|
@@ -2091,12 +2181,10 @@ function phantomSuffixCloser(content) {
|
|
|
2091
2181
|
const endsWithNewline = content.endsWith("\n");
|
|
2092
2182
|
const confirmed = endsWithNewline ? content : content + "\n";
|
|
2093
2183
|
const { checkpoint } = computeFreezeBoundary(confirmed, { defListEnabled: false, referenceTaint: false });
|
|
2094
|
-
|
|
2095
|
-
if (
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
if (checkpoint.inMath) return `${nl}${"$".repeat(checkpoint.mathFenceLen)}`;
|
|
2099
|
-
return "";
|
|
2184
|
+
const closer = pendingFenceCloser(checkpoint);
|
|
2185
|
+
if (closer === "") return "";
|
|
2186
|
+
return endsWithNewline ? closer : `
|
|
2187
|
+
${closer}`;
|
|
2100
2188
|
}
|
|
2101
2189
|
|
|
2102
2190
|
// src/components/extractContributions.ts
|
|
@@ -2372,7 +2460,7 @@ function createRegistry(onEmpty) {
|
|
|
2372
2460
|
|
|
2373
2461
|
// src/components/pluginChain.ts
|
|
2374
2462
|
import rehypeKatex from "rehype-katex";
|
|
2375
|
-
import rehypeRaw from "rehype-raw";
|
|
2463
|
+
import rehypeRaw from "@ai-markdown/rehype-raw";
|
|
2376
2464
|
import rehypeUnwrapImages from "rehype-unwrap-images";
|
|
2377
2465
|
|
|
2378
2466
|
// src/components/rehypeUnwrapCrossChunkImages.ts
|