@ai-react-markdown/engine 2.5.2 → 2.5.4
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 +87 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.dev.cjs +87 -12
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +87 -12
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +87 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.dev.js
CHANGED
|
@@ -177,6 +177,26 @@ import { htmlBlockNames } from "micromark-util-html-tag-name";
|
|
|
177
177
|
import { normalizeIdentifier } from "micromark-util-normalize-identifier";
|
|
178
178
|
var TYPE6_NAMES = new Set(htmlBlockNames);
|
|
179
179
|
var TABLE_PART_NAMES = /* @__PURE__ */ new Set(["td", "th", "tr", "tbody", "thead", "tfoot", "caption", "col", "colgroup"]);
|
|
180
|
+
var DOCUMENT_STRUCTURE_NAMES = /* @__PURE__ */ new Set(["html", "head", "body", "frameset"]);
|
|
181
|
+
var RETROACTIVE_OPENERS = [
|
|
182
|
+
"<!doctype",
|
|
183
|
+
"<html",
|
|
184
|
+
"<head",
|
|
185
|
+
"<body",
|
|
186
|
+
"<frameset",
|
|
187
|
+
"</html",
|
|
188
|
+
"</head",
|
|
189
|
+
"</body",
|
|
190
|
+
"</frameset"
|
|
191
|
+
];
|
|
192
|
+
function tailCarriesRetroactive(text) {
|
|
193
|
+
const lower = text.toLowerCase();
|
|
194
|
+
for (let i = lower.indexOf("<"); i !== -1; i = lower.indexOf("<", i + 1)) {
|
|
195
|
+
const rest = lower.slice(i);
|
|
196
|
+
for (const op of RETROACTIVE_OPENERS) if (rest.startsWith(op)) return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
180
200
|
var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
|
|
181
201
|
"b",
|
|
182
202
|
"big",
|
|
@@ -223,7 +243,8 @@ var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
|
|
|
223
243
|
"ul",
|
|
224
244
|
"var"
|
|
225
245
|
]);
|
|
226
|
-
var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
|
|
246
|
+
var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "title", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
|
|
247
|
+
var FOREIGN_ROOT_NAMES = ["svg", "math"];
|
|
227
248
|
var TYPE1_NAMES = /* @__PURE__ */ new Set(["script", "pre", "style", "textarea"]);
|
|
228
249
|
var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
229
250
|
"script",
|
|
@@ -242,6 +263,7 @@ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
242
263
|
]);
|
|
243
264
|
var TYPE6_START_RE = /^<\/?([A-Za-z][A-Za-z0-9-]*)(?:[ \t\r]|\/?>|$)/;
|
|
244
265
|
var TYPE1_START_RE = /^<(script|pre|style|textarea)(?:[ \t\r]|>|$)/i;
|
|
266
|
+
var TYPE1_CLOSE_RE = /<\/(?:script|pre|style|textarea)>/i;
|
|
245
267
|
var TYPE7_LINE_RE = /^(?:<[A-Za-z][A-Za-z0-9-]*(?:[ \t\r][^>]*|\/)?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\r]*>)[ \t\r]*$/;
|
|
246
268
|
var t7Name = (line) => /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(line)[1];
|
|
247
269
|
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
@@ -392,6 +414,7 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
392
414
|
piOpen: false,
|
|
393
415
|
bogusOpen: false,
|
|
394
416
|
rawTextOpen: null,
|
|
417
|
+
scriptDataEscaped: false,
|
|
395
418
|
declOpen: false,
|
|
396
419
|
cdataOpen: false,
|
|
397
420
|
inFence: false,
|
|
@@ -417,7 +440,9 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
417
440
|
tagAcrossLines: false,
|
|
418
441
|
tagAcrossLinesIndent: 0,
|
|
419
442
|
tagAcrossLinesState: "outside",
|
|
420
|
-
htmlFlowReal: false
|
|
443
|
+
htmlFlowReal: false,
|
|
444
|
+
type1FlowOpen: false,
|
|
445
|
+
rawTextInline: false
|
|
421
446
|
};
|
|
422
447
|
}
|
|
423
448
|
function isPlausibleLinkDefRest(rest) {
|
|
@@ -562,8 +587,9 @@ function computeFreezeBoundary(text, options, resume) {
|
|
|
562
587
|
if (tailLine) return !canBecomeDdLine(tailLine.text, false);
|
|
563
588
|
return false;
|
|
564
589
|
};
|
|
590
|
+
const tailRetroactive = tailLine !== null && tailCarriesRetroactive(tailLine.text);
|
|
565
591
|
let boundary = 0;
|
|
566
|
-
for (let i = cp.candidates.length - 1; i >= 0; i--) {
|
|
592
|
+
for (let i = cp.candidates.length - 1; i >= 0 && !tailRetroactive; i--) {
|
|
567
593
|
const c = cp.candidates[i];
|
|
568
594
|
if (!c.htmlBalanced || c.hazard || c.seamRisk) continue;
|
|
569
595
|
if (c.offset > cp.phasePoisonedAt) continue;
|
|
@@ -629,7 +655,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
629
655
|
cp.htmlSeamPending = false;
|
|
630
656
|
}
|
|
631
657
|
}
|
|
632
|
-
const inForeignContent = () =>
|
|
658
|
+
const inForeignContent = () => FOREIGN_ROOT_NAMES.some((name) => (cp.tagBalance.get(name) ?? 0) > 0);
|
|
633
659
|
const honoursSelfClosing = (tag) => {
|
|
634
660
|
if (tag === "svg" || tag === "math") return true;
|
|
635
661
|
if (!inForeignContent() || HTML_BREAKOUT_TAGS.has(tag)) return false;
|
|
@@ -641,14 +667,37 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
641
667
|
for (const ip of HTML_INTEGRATION_POINTS) if ((cp.tagBalance.get(ip) ?? 0) > 0) return true;
|
|
642
668
|
return false;
|
|
643
669
|
};
|
|
670
|
+
const popForeignRoots = () => {
|
|
671
|
+
for (const name of FOREIGN_ROOT_NAMES) {
|
|
672
|
+
const count = cp.tagBalance.get(name) ?? 0;
|
|
673
|
+
if (count > 0) {
|
|
674
|
+
cp.tagBalance.set(name, 0);
|
|
675
|
+
cp.openTotal -= count;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
const noteBreakout = (tag, closing) => {
|
|
680
|
+
if (closing || cp.rawTextOpen !== null) return;
|
|
681
|
+
if (HTML_BREAKOUT_TAGS.has(tag) && !htmlRulesApply()) popForeignRoots();
|
|
682
|
+
};
|
|
644
683
|
const applyTag = (tag, closing) => {
|
|
645
684
|
if (cp.rawTextOpen !== null) {
|
|
685
|
+
if (cp.scriptDataEscaped && !closing && tag === "script") {
|
|
686
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
687
|
+
}
|
|
646
688
|
if (!(closing && tag === cp.rawTextOpen)) return;
|
|
647
689
|
cp.rawTextOpen = null;
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
690
|
+
cp.scriptDataEscaped = false;
|
|
691
|
+
} else {
|
|
692
|
+
noteBreakout(tag, closing);
|
|
693
|
+
if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
|
|
694
|
+
cp.rawTextOpen = tag;
|
|
695
|
+
cp.scriptDataEscaped = false;
|
|
696
|
+
cp.rawTextInline = !cp.htmlFlowReal;
|
|
697
|
+
if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
698
|
+
}
|
|
651
699
|
}
|
|
700
|
+
if (DOCUMENT_STRUCTURE_NAMES.has(tag)) cp.phasePoisonedAt = 0;
|
|
652
701
|
if (closing) {
|
|
653
702
|
const count = cp.tagBalance.get(tag) ?? 0;
|
|
654
703
|
if (count > 0) {
|
|
@@ -759,15 +808,22 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
759
808
|
cp.candidates.push({
|
|
760
809
|
offset: Math.min(ln.end + 1, text.length),
|
|
761
810
|
blankRun: cp.blankRun,
|
|
762
|
-
|
|
811
|
+
// `type1FlowOpen`: an unterminated type-1 block swallows this blank
|
|
812
|
+
// and everything after it as RAW content, so nothing here is a block
|
|
813
|
+
// boundary at all. Its tags are invisible to the balance scan
|
|
814
|
+
// (`rawTextOpen` suppresses them), which is exactly why `openTotal`
|
|
815
|
+
// reads 0 and the candidate looked safe.
|
|
816
|
+
htmlBalanced: cp.openTotal === 0 && !cp.commentOpen && !cp.piOpen && !cp.declOpen && !cp.cdataOpen && !cp.bogusOpen && !cp.type1FlowOpen,
|
|
763
817
|
hazard: cp.hazardVerdict,
|
|
764
818
|
seamRisk: cp.htmlSeamPending,
|
|
765
819
|
defListSettled: null
|
|
766
820
|
});
|
|
767
821
|
cp.paragraphHasUnpairedRun = false;
|
|
768
822
|
cp.openBracket = null;
|
|
769
|
-
cp.
|
|
770
|
-
|
|
823
|
+
if (!cp.type1FlowOpen) {
|
|
824
|
+
cp.htmlFlowSinceBlank = false;
|
|
825
|
+
cp.htmlFlowReal = false;
|
|
826
|
+
}
|
|
771
827
|
cp.prevLineBlank = true;
|
|
772
828
|
cp.prevLineWasText = false;
|
|
773
829
|
cp.prevLineWasValidDef = false;
|
|
@@ -781,7 +837,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
781
837
|
}
|
|
782
838
|
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
|
|
783
839
|
if (tagStart) {
|
|
840
|
+
const noRealBlockOpen = !cp.htmlFlowReal;
|
|
784
841
|
cp.htmlFlowSinceBlank = true;
|
|
842
|
+
if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.type1FlowOpen = true;
|
|
785
843
|
if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
|
|
786
844
|
if (!cp.htmlFlowReal) {
|
|
787
845
|
const t = mdTrimStart(ln.text);
|
|
@@ -932,6 +990,7 @@ ${cont(scanText)}` };
|
|
|
932
990
|
pos = pi + 2;
|
|
933
991
|
} else {
|
|
934
992
|
rawSpans.push([decl, decl + 2]);
|
|
993
|
+
if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
|
|
935
994
|
cp.declOpen = true;
|
|
936
995
|
pos = decl + 2;
|
|
937
996
|
}
|
|
@@ -963,7 +1022,10 @@ ${cont(scanText)}` };
|
|
|
963
1022
|
let m;
|
|
964
1023
|
let lastCommentOpenerIdx = -1;
|
|
965
1024
|
while ((m = TAG_OR_COMMENT_RE.exec(tagText)) !== null) {
|
|
966
|
-
if (cp.rawTextOpen !== null && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>"))
|
|
1025
|
+
if (cp.rawTextOpen !== null && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) {
|
|
1026
|
+
if (cp.rawTextOpen === "script" && m[0] === "<!--") cp.scriptDataEscaped = true;
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
967
1029
|
if (m[0] === "<!--") {
|
|
968
1030
|
const next = tagText.slice(m.index + 4, m.index + 6);
|
|
969
1031
|
if (cp.commentOpen) {
|
|
@@ -1012,8 +1074,12 @@ ${cont(scanText)}` };
|
|
|
1012
1074
|
TAG_OR_COMMENT_RE.lastIndex = gt + 1;
|
|
1013
1075
|
}
|
|
1014
1076
|
}
|
|
1015
|
-
if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs))
|
|
1077
|
+
if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs)) {
|
|
1078
|
+
TAG_OR_COMMENT_RE.lastIndex = m.index + 2 + m[2].length;
|
|
1079
|
+
continue;
|
|
1080
|
+
}
|
|
1016
1081
|
const selfClosing = /\/\s*$/.test(attrs);
|
|
1082
|
+
noteBreakout(tag, closing);
|
|
1017
1083
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
1018
1084
|
applyTag(tag, closing);
|
|
1019
1085
|
}
|
|
@@ -1036,6 +1102,7 @@ ${cont(scanText)}` };
|
|
|
1036
1102
|
if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + mr.index);
|
|
1037
1103
|
if (closing && mr[3] !== void 0 && !/^\s*$/.test(mr[3])) continue;
|
|
1038
1104
|
const selfClosing = mr[3] !== void 0 && /\/\s*$/.test(mr[3]);
|
|
1105
|
+
noteBreakout(tag, closing);
|
|
1039
1106
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
1040
1107
|
applyTag(tag, closing);
|
|
1041
1108
|
}
|
|
@@ -1093,6 +1160,14 @@ ${cont(scanText)}` };
|
|
|
1093
1160
|
cp.htmlSeamPending = true;
|
|
1094
1161
|
}
|
|
1095
1162
|
}
|
|
1163
|
+
if (cp.rawTextOpen !== null && cp.rawTextInline) {
|
|
1164
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1165
|
+
}
|
|
1166
|
+
if (cp.type1FlowOpen && TYPE1_CLOSE_RE.test(ln.text)) {
|
|
1167
|
+
cp.type1FlowOpen = false;
|
|
1168
|
+
cp.htmlFlowSinceBlank = false;
|
|
1169
|
+
cp.htmlFlowReal = false;
|
|
1170
|
+
}
|
|
1096
1171
|
cp.blankRun = 0;
|
|
1097
1172
|
cp.prevLineBlank = false;
|
|
1098
1173
|
cp.prevLineWasText = true;
|