@ai-react-markdown/engine 2.8.1 → 2.9.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 +65 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.dev.cjs +70 -17
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +70 -17
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +65 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.dev.cjs
CHANGED
|
@@ -378,9 +378,9 @@ function inlineResourceEnd(text, openIdx) {
|
|
|
378
378
|
}
|
|
379
379
|
return -1;
|
|
380
380
|
}
|
|
381
|
-
function collectRefLine(cp, lnStart, lnEnd, scanText, inRawText, isBlockStart) {
|
|
382
|
-
const defShaped = inRawText ? null : DEF_RE.exec(
|
|
383
|
-
const def = defShaped !== null && (defShaped[1].startsWith("^") || isPlausibleLinkDefRest(
|
|
381
|
+
function collectRefLine(cp, lnStart, lnEnd, scanText, rawText, inRawText, isBlockStart) {
|
|
382
|
+
const defShaped = inRawText ? null : DEF_RE.exec(rawText);
|
|
383
|
+
const def = defShaped !== null && (defShaped[1].startsWith("^") || isPlausibleLinkDefRest(rawText.slice(defShaped.index + defShaped[0].length))) ? defShaped : null;
|
|
384
384
|
const defLineStart = isBlockStart || !cp.prevLineWasText || cp.prevLineWasValidDef;
|
|
385
385
|
const validDef = def !== null && defLineStart;
|
|
386
386
|
if (validDef) {
|
|
@@ -598,12 +598,15 @@ var rawTextElement = (t) => t.kind === "rawText" ? t.element : t.kind === "scrip
|
|
|
598
598
|
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
599
599
|
"area",
|
|
600
600
|
"base",
|
|
601
|
+
"basefont",
|
|
602
|
+
"bgsound",
|
|
601
603
|
"br",
|
|
602
604
|
"col",
|
|
603
605
|
"embed",
|
|
604
606
|
"hr",
|
|
605
607
|
"img",
|
|
606
608
|
"input",
|
|
609
|
+
"keygen",
|
|
607
610
|
"link",
|
|
608
611
|
"meta",
|
|
609
612
|
"param",
|
|
@@ -855,6 +858,24 @@ function floatingResidue(text, commentOpenAtStart) {
|
|
|
855
858
|
if (!open) out += text.slice(last);
|
|
856
859
|
return out;
|
|
857
860
|
}
|
|
861
|
+
var RAW_CONSTRUCT_START_RE = /^<(?:!--|\?|![A-Za-z]|!\[CDATA\[)/;
|
|
862
|
+
var sealResumableAbove = (cp) => cp.defBlockMaybeOpen || cp.fnDefResumable || cp.containerMaybeOpen;
|
|
863
|
+
function sealReleaseDerived(cp, ln, isBlockStart) {
|
|
864
|
+
if (sealResumableAbove(cp) && !(isBlockStart && ln.indent <= 3)) return false;
|
|
865
|
+
if (cp.prevLineOpenContent) return false;
|
|
866
|
+
if (cp.tableMaybeOpen) return false;
|
|
867
|
+
const head = mdTrimStart(ln.text);
|
|
868
|
+
if (RAW_CONSTRUCT_START_RE.test(head) || TYPE1_START_RE.test(head) || isType7Line(head)) return false;
|
|
869
|
+
const t6 = TYPE6_START_RE.exec(head);
|
|
870
|
+
if (t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase())) return false;
|
|
871
|
+
if (DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text)) return false;
|
|
872
|
+
return true;
|
|
873
|
+
}
|
|
874
|
+
function sealReleaseEnumerated(cp, ln, isBlockStart) {
|
|
875
|
+
const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defBlockMaybeOpen || cp.fnDefResumable && !(isBlockStart && ln.indent <= 3);
|
|
876
|
+
const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
|
|
877
|
+
return !defShapedLine && !commentOnly && !CLOSE_TAG_ONLY_RE.test(ln.text);
|
|
878
|
+
}
|
|
858
879
|
function processConfirmedLine(cp, ln, text) {
|
|
859
880
|
const newest = cp.candidates[cp.candidates.length - 1];
|
|
860
881
|
if (newest && newest.defListSettled === null) {
|
|
@@ -862,16 +883,19 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
862
883
|
}
|
|
863
884
|
const isBlockStart = cp.prevLineBlank;
|
|
864
885
|
if (cp.p5SealPending && !ln.blank && cp.mdBlock.kind !== "html" && !(cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus")) {
|
|
865
|
-
|
|
866
|
-
const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
|
|
867
|
-
const closeTagOnly = CLOSE_TAG_ONLY_RE.test(ln.text);
|
|
868
|
-
if (!defShapedLine && !commentOnly && !closeTagOnly) {
|
|
886
|
+
if (sealReleaseDerived(cp, ln, isBlockStart)) {
|
|
869
887
|
cp.p5SealPending = false;
|
|
888
|
+
if (!sealReleaseEnumerated(cp, ln, isBlockStart)) {
|
|
889
|
+
console.error(
|
|
890
|
+
`[ai-react-markdown] seal-release containment broken at offset ${ln.start}: the derived predicate released a line the retired enumeration withheld (${JSON.stringify(ln.text.slice(0, 80))}).`
|
|
891
|
+
);
|
|
892
|
+
}
|
|
870
893
|
}
|
|
871
894
|
}
|
|
872
895
|
const possiblyInsideForeign = () => FOREIGN_ROOT_NAMES.some((name) => (cp.tagBalance.get(name) ?? 0) > 0);
|
|
873
896
|
const honoursSelfClosing = (tag) => tag === "svg" || tag === "math";
|
|
874
897
|
const foreignRawTextSwitchUnknowable = () => possiblyInsideForeign();
|
|
898
|
+
let discardedEndTag = false;
|
|
875
899
|
const applyTag = (tag, closing) => {
|
|
876
900
|
if (inRawTextTok(cp.p5Tok)) {
|
|
877
901
|
if (cp.p5Tok.kind === "script" && cp.p5Tok.escaped && !closing && tag === "script") {
|
|
@@ -904,7 +928,10 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
904
928
|
}
|
|
905
929
|
if (SCOPE_BARRIER_NAMES.has(cp.openStack[i])) break;
|
|
906
930
|
}
|
|
907
|
-
if (idx === -1)
|
|
931
|
+
if (idx === -1) {
|
|
932
|
+
discardedEndTag = true;
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
908
935
|
cp.openStack.splice(idx, 1);
|
|
909
936
|
const count = cp.tagBalance.get(tag) ?? 0;
|
|
910
937
|
if (count > 0) {
|
|
@@ -1023,6 +1050,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1023
1050
|
cp.p5Tok = { kind: "data" };
|
|
1024
1051
|
}
|
|
1025
1052
|
}
|
|
1053
|
+
if (cp.p5Tok.kind === "comment" && !mdHtml(cp.mdBlock, 2)) {
|
|
1054
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1055
|
+
}
|
|
1026
1056
|
if (cp.mdBlock.kind === "html" && cp.mdBlock.type >= 6) cp.mdBlock = { kind: "none" };
|
|
1027
1057
|
cp.blankRun += 1;
|
|
1028
1058
|
cp.lastBlankStart = ln.start;
|
|
@@ -1066,7 +1096,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1066
1096
|
if (tagStart) {
|
|
1067
1097
|
const noRealBlockOpen = cp.mdBlock.kind !== "html";
|
|
1068
1098
|
const t1 = noRealBlockOpen ? TYPE1_START_RE.exec(mdTrimStart(ln.text)) : null;
|
|
1069
|
-
if (t1) cp.mdBlock = { kind: "html", type: 1, raw: RAW_TEXT_ELEMENTS.has(t1[1].toLowerCase()) };
|
|
1099
|
+
if (t1) cp.mdBlock = { kind: "html", type: 1, raw: RAW_TEXT_ELEMENTS.has(t1[1].toLowerCase()), indent: ln.indent };
|
|
1070
1100
|
if (cp.mdBlock.kind !== "html") {
|
|
1071
1101
|
const t = mdTrimStart(ln.text);
|
|
1072
1102
|
const t6 = TYPE6_START_RE.exec(t);
|
|
@@ -1081,7 +1111,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1081
1111
|
// raw-text names (`</style>` alone is type 7, measured) and
|
|
1082
1112
|
// quoted-`>` attribute values.
|
|
1083
1113
|
!cp.prevLineOpenContent && type7Shaped) {
|
|
1084
|
-
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7 };
|
|
1114
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7, indent: ln.indent };
|
|
1085
1115
|
} else if (cp.prevLineOpenContent && cp.tableMaybeOpen && type7Shaped) {
|
|
1086
1116
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1087
1117
|
}
|
|
@@ -1090,14 +1120,14 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1090
1120
|
}
|
|
1091
1121
|
}
|
|
1092
1122
|
}
|
|
1093
|
-
const rawFlowStart = ln.indent <= 3 &&
|
|
1123
|
+
const rawFlowStart = ln.indent <= 3 && RAW_CONSTRUCT_START_RE.test(mdTrimStart(ln.text));
|
|
1094
1124
|
const htmlOwnedLine = cp.mdBlock.kind === "html" || rawOpenAtLineStart || rawFlowStart;
|
|
1095
1125
|
const maskingSuppressed = htmlOwnedLine || inRawTextTok(cp.p5Tok);
|
|
1096
1126
|
const { masked, unpaired } = maskingSuppressed ? { masked: null, unpaired: false } : maskIntraLineCodeSpans(ln.text, cp.paragraphHasUnpairedRun);
|
|
1097
1127
|
if (unpaired) cp.paragraphHasUnpairedRun = true;
|
|
1098
1128
|
const scanText = masked ?? ln.text;
|
|
1099
1129
|
const defRawToMicromark = cp.mdBlock.kind === "html" || rawOpenAtLineStart || inRawTextTok(cp.p5Tok);
|
|
1100
|
-
const { validLinkDef } = collectRefLine(cp, ln.start, ln.end, scanText, defRawToMicromark, isBlockStart);
|
|
1130
|
+
const { validLinkDef } = collectRefLine(cp, ln.start, ln.end, scanText, ln.text, defRawToMicromark, isBlockStart);
|
|
1101
1131
|
const rawSpans = [];
|
|
1102
1132
|
let pos = 0;
|
|
1103
1133
|
const poisonRawDivergence = () => {
|
|
@@ -1173,7 +1203,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1173
1203
|
pos = bogus + 2;
|
|
1174
1204
|
} else if (first === cd) {
|
|
1175
1205
|
rawSpans.push([cd, cd + 9]);
|
|
1176
|
-
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5 };
|
|
1206
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5, indent: ln.indent };
|
|
1177
1207
|
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
1178
1208
|
if (!isMdBlank(scanText.slice(0, cd)) || ln.indent > 3) inlineRawOpenerIdx = cd;
|
|
1179
1209
|
pos = cd + 9;
|
|
@@ -1185,14 +1215,14 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1185
1215
|
continue;
|
|
1186
1216
|
}
|
|
1187
1217
|
rawSpans.push([pi, pi + 2]);
|
|
1188
|
-
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3 };
|
|
1218
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3, indent: ln.indent };
|
|
1189
1219
|
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
1190
1220
|
if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) inlineRawOpenerIdx = pi;
|
|
1191
1221
|
pos = pi + 2;
|
|
1192
1222
|
} else {
|
|
1193
1223
|
rawSpans.push([decl, decl + 2]);
|
|
1194
1224
|
if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
|
|
1195
|
-
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4 };
|
|
1225
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4, indent: ln.indent };
|
|
1196
1226
|
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
1197
1227
|
if (!isMdBlank(scanText.slice(0, decl)) || ln.indent > 3) inlineRawOpenerIdx = decl;
|
|
1198
1228
|
pos = decl + 2;
|
|
@@ -1251,7 +1281,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1251
1281
|
if (next.startsWith(">") || next === "->") {
|
|
1252
1282
|
continue;
|
|
1253
1283
|
}
|
|
1254
|
-
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 2 };
|
|
1284
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 2, indent: ln.indent };
|
|
1255
1285
|
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "comment" };
|
|
1256
1286
|
lastCommentOpenerIdx = m.index;
|
|
1257
1287
|
continue;
|
|
@@ -1372,7 +1402,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1372
1402
|
cursor = to;
|
|
1373
1403
|
}
|
|
1374
1404
|
masked2 += scanText.slice(cursor);
|
|
1375
|
-
if (floatingResidue(masked2, bothCommentsOpenAtLineStart).length > 0) {
|
|
1405
|
+
if (floatingResidue(masked2, bothCommentsOpenAtLineStart).length > 0 || discardedEndTag) {
|
|
1376
1406
|
cp.p5SealPending = true;
|
|
1377
1407
|
}
|
|
1378
1408
|
}
|
|
@@ -1411,7 +1441,30 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1411
1441
|
cp.defBlockMaybeOpen = cp.defBlockMaybeOpen || DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
|
|
1412
1442
|
if (FOOTNOTE_DEF_RE.test(ln.text)) cp.fnDefResumable = true;
|
|
1413
1443
|
else if (isBlockStart && ln.indent <= 3) cp.fnDefResumable = false;
|
|
1444
|
+
const isBarrier = (name) => SCOPE_BARRIER_NAMES.has(name);
|
|
1445
|
+
const topLevelHtmlBlock = cp.mdBlock.kind === "html" && cp.mdBlock.indent === 0;
|
|
1446
|
+
const confirmedBarriers = cp.openStack.filter(isBarrier).length - cp.pendingTruncatedTags.filter(isBarrier).length;
|
|
1447
|
+
if (!topLevelHtmlBlock && confirmedBarriers > 0) {
|
|
1448
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1449
|
+
}
|
|
1450
|
+
const maskUnbacked = mdType1RawText(cp.mdBlock) && !inRawTextTok(cp.p5Tok);
|
|
1451
|
+
if (maskUnbacked) {
|
|
1452
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1453
|
+
if (tailCarriesRetroactive(ln.text) || /<template(?![a-z0-9-])/i.test(ln.text)) {
|
|
1454
|
+
cp.phasePoisonedAt = 0;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1414
1457
|
}
|
|
1458
|
+
var SCANNER_NAME_LISTS = [
|
|
1459
|
+
["type1", TYPE1_NAMES],
|
|
1460
|
+
["rawText", RAW_TEXT_ELEMENTS],
|
|
1461
|
+
["type6", TYPE6_NAMES],
|
|
1462
|
+
["void", VOID_TAGS],
|
|
1463
|
+
["documentStructure", DOCUMENT_STRUCTURE_NAMES],
|
|
1464
|
+
["tablePart", TABLE_PART_NAMES],
|
|
1465
|
+
["scopeBarrier", SCOPE_BARRIER_NAMES],
|
|
1466
|
+
["foreignRoot", new Set(FOREIGN_ROOT_NAMES)]
|
|
1467
|
+
];
|
|
1415
1468
|
|
|
1416
1469
|
// src/components/incrementalParse/spliceParse.ts
|
|
1417
1470
|
var import_micromark_util_normalize_identifier2 = require("micromark-util-normalize-identifier");
|