@ai-react-markdown/engine 2.8.0 → 2.8.1
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/README.md +1 -1
- package/dist/index.cjs +61 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -77
- package/dist/index.d.ts +3 -77
- package/dist/index.dev.cjs +61 -24
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +61 -20
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +61 -20
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -501,6 +501,7 @@ var isType7Line = (line) => {
|
|
|
501
501
|
return i >= t.length;
|
|
502
502
|
};
|
|
503
503
|
var mdHtml = (b, type) => b.kind === "html" && b.type === type;
|
|
504
|
+
var mdType1RawText = (b) => b.kind === "html" && b.type === 1 && b.raw;
|
|
504
505
|
var mdHtml25 = (b) => b.kind === "html" && b.type >= 2 && b.type <= 5;
|
|
505
506
|
var commentEitherOpen = (md, p5) => mdHtml(md, 2) || p5.kind === "comment";
|
|
506
507
|
var inRawTextTok = (t) => t.kind === "rawText" || t.kind === "script";
|
|
@@ -522,11 +523,13 @@ var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
|
522
523
|
"wbr"
|
|
523
524
|
]);
|
|
524
525
|
var LIST_MARKER_RE = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
|
|
526
|
+
var CONTAINER_MARKER_RE = /^ {0,3}(?:>|(?:[-*+]|\d{1,9}[.)])[ \t]+\S)/;
|
|
525
527
|
var ATX_HEADING_RE = /^#{1,6}(?:[ \t]|$)/;
|
|
526
528
|
var THEMATIC_BREAK_RE = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
527
529
|
var BARE_MARKER_RE = /^(?:[-*+]|\d{1,9}[.)])[ \t]*$/;
|
|
528
530
|
var SETEXT_LEFTOVER_RE = /^(?:=+|--)[ \t]*$/;
|
|
529
531
|
var DEF_LIST_DD_RE = /^ {0,3}:[ \t]/;
|
|
532
|
+
var CLOSE_TAG_ONLY_RE = /^[ \t]*<\/[A-Za-z][A-Za-z0-9-]*[ \t]*>[ \t\r]*$/;
|
|
530
533
|
var FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
|
|
531
534
|
var MATH_RUN_RE = /^ {0,3}(\$\$+)/;
|
|
532
535
|
var TAG_OR_COMMENT_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?=[\s/>])([^>]*)>|<!--|-->|--!>/g;
|
|
@@ -637,9 +640,12 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
637
640
|
prevLineWasValidDef: false,
|
|
638
641
|
prevLineOpenContent: false,
|
|
639
642
|
tableMaybeOpen: false,
|
|
643
|
+
containerMaybeOpen: false,
|
|
640
644
|
paragraphHasUnpairedRun: false,
|
|
641
645
|
openBracket: null,
|
|
642
646
|
p5SealPending: false,
|
|
647
|
+
defBlockMaybeOpen: false,
|
|
648
|
+
fnDefResumable: false,
|
|
643
649
|
phasePoisonedAt: Infinity,
|
|
644
650
|
pendingTruncatedTags: [],
|
|
645
651
|
pendingTruncatedCloses: [],
|
|
@@ -767,9 +773,10 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
767
773
|
}
|
|
768
774
|
const isBlockStart = cp.prevLineBlank;
|
|
769
775
|
if (cp.p5SealPending && !ln.blank && cp.mdBlock.kind !== "html" && !(cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus")) {
|
|
770
|
-
const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
|
|
776
|
+
const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defBlockMaybeOpen || cp.fnDefResumable && ln.indent >= 4;
|
|
771
777
|
const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
|
|
772
|
-
|
|
778
|
+
const closeTagOnly = CLOSE_TAG_ONLY_RE.test(ln.text);
|
|
779
|
+
if (!defShapedLine && !commentOnly && !closeTagOnly) {
|
|
773
780
|
cp.p5SealPending = false;
|
|
774
781
|
}
|
|
775
782
|
}
|
|
@@ -821,7 +828,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
821
828
|
cp.openTotal += 1;
|
|
822
829
|
}
|
|
823
830
|
};
|
|
824
|
-
const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) >
|
|
831
|
+
const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) > cp.pendingTruncatedTags.filter((t) => t === "table").length;
|
|
825
832
|
const strayTablePart = (tag) => TABLE_PART_NAMES.has(tag) && !definitelyInsideTable();
|
|
826
833
|
const commentOpenAtLineStart = commentEitherOpen(cp.mdBlock, cp.p5Tok);
|
|
827
834
|
const bothCommentsOpenAtLineStart = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind === "comment";
|
|
@@ -843,6 +850,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
843
850
|
cp.prevLineWasValidDef = false;
|
|
844
851
|
cp.prevLineOpenContent = false;
|
|
845
852
|
cp.tableMaybeOpen = false;
|
|
853
|
+
cp.containerMaybeOpen = false;
|
|
846
854
|
return;
|
|
847
855
|
}
|
|
848
856
|
if (cp.mdBlock.kind !== "math" && !rawOpenAtLineStart) {
|
|
@@ -864,6 +872,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
864
872
|
cp.prevLineWasValidDef = false;
|
|
865
873
|
cp.prevLineOpenContent = false;
|
|
866
874
|
cp.tableMaybeOpen = false;
|
|
875
|
+
cp.containerMaybeOpen = false;
|
|
867
876
|
return;
|
|
868
877
|
}
|
|
869
878
|
}
|
|
@@ -880,6 +889,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
880
889
|
cp.prevLineWasValidDef = false;
|
|
881
890
|
cp.prevLineOpenContent = false;
|
|
882
891
|
cp.tableMaybeOpen = false;
|
|
892
|
+
cp.containerMaybeOpen = false;
|
|
883
893
|
return;
|
|
884
894
|
}
|
|
885
895
|
const mathRun = cp.mathFlow && !rawOpenAtLineStart ? MATH_RUN_RE.exec(ln.text) : null;
|
|
@@ -902,6 +912,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
902
912
|
cp.prevLineWasValidDef = false;
|
|
903
913
|
cp.prevLineOpenContent = false;
|
|
904
914
|
cp.tableMaybeOpen = false;
|
|
915
|
+
cp.containerMaybeOpen = false;
|
|
905
916
|
return;
|
|
906
917
|
}
|
|
907
918
|
}
|
|
@@ -950,8 +961,10 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
950
961
|
cp.prevLineBlank = true;
|
|
951
962
|
cp.prevLineWasText = false;
|
|
952
963
|
cp.prevLineWasValidDef = false;
|
|
964
|
+
cp.defBlockMaybeOpen = false;
|
|
953
965
|
cp.prevLineOpenContent = false;
|
|
954
966
|
cp.tableMaybeOpen = false;
|
|
967
|
+
cp.containerMaybeOpen = false;
|
|
955
968
|
return;
|
|
956
969
|
}
|
|
957
970
|
if (isBlockStart) {
|
|
@@ -963,21 +976,27 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
963
976
|
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
|
|
964
977
|
if (tagStart) {
|
|
965
978
|
const noRealBlockOpen = cp.mdBlock.kind !== "html";
|
|
966
|
-
|
|
979
|
+
const t1 = noRealBlockOpen ? TYPE1_START_RE.exec(mdTrimStart(ln.text)) : null;
|
|
980
|
+
if (t1) cp.mdBlock = { kind: "html", type: 1, raw: RAW_TEXT_ELEMENTS.has(t1[1].toLowerCase()) };
|
|
967
981
|
if (cp.mdBlock.kind !== "html") {
|
|
968
982
|
const t = mdTrimStart(ln.text);
|
|
969
983
|
const t6 = TYPE6_START_RE.exec(t);
|
|
970
984
|
const realT6 = t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase());
|
|
971
|
-
|
|
985
|
+
const t1Line = TYPE1_START_RE.test(t);
|
|
986
|
+
const type7Shaped = !realT6 && !t1Line && isType7Line(t);
|
|
987
|
+
if (realT6 || t1Line || // Type 7 cannot interrupt CONTENT (micromark's paragraph/definition
|
|
972
988
|
// construct — `prevLineOpenContent`, the exact interrupt input; the
|
|
973
989
|
// old `prevLineWasText` gate refused after headings, terminator
|
|
974
990
|
// lines and fence closes, where micromark measurably opens). The
|
|
975
991
|
// classifier itself is exact too (isType7Line) — including closing
|
|
976
992
|
// raw-text names (`</style>` alone is type 7, measured) and
|
|
977
993
|
// quoted-`>` attribute values.
|
|
978
|
-
!cp.prevLineOpenContent &&
|
|
994
|
+
!cp.prevLineOpenContent && type7Shaped) {
|
|
979
995
|
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7 };
|
|
980
|
-
} else if (cp.prevLineOpenContent && cp.tableMaybeOpen &&
|
|
996
|
+
} else if (cp.prevLineOpenContent && cp.tableMaybeOpen && type7Shaped) {
|
|
997
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
998
|
+
}
|
|
999
|
+
if (type7Shaped && cp.containerMaybeOpen) {
|
|
981
1000
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
982
1001
|
}
|
|
983
1002
|
}
|
|
@@ -1043,7 +1062,12 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1043
1062
|
pos = c + 1;
|
|
1044
1063
|
continue;
|
|
1045
1064
|
}
|
|
1046
|
-
if (commentOpenAtLineStart || inRawTextTok(cp.p5Tok) ||
|
|
1065
|
+
if (commentOpenAtLineStart || inRawTextTok(cp.p5Tok) || mdType1RawText(cp.mdBlock)) {
|
|
1066
|
+
if (inRawTextTok(cp.p5Tok) && cp.p5Tok.openedInline && (tailCarriesRetroactive(ln.text) || /<template(?![a-z0-9-])/i.test(ln.text))) {
|
|
1067
|
+
cp.phasePoisonedAt = 0;
|
|
1068
|
+
}
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1047
1071
|
const pi = scanText.indexOf("<?", pos);
|
|
1048
1072
|
const cd = scanText.indexOf("<![CDATA[", pos);
|
|
1049
1073
|
const dm = scanText.slice(pos).search(/<![A-Za-z]/);
|
|
@@ -1280,17 +1304,24 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1280
1304
|
openContent = false;
|
|
1281
1305
|
} else if (ln.indent >= 4) {
|
|
1282
1306
|
openContent = cp.prevLineOpenContent;
|
|
1283
|
-
} else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt)
|
|
1307
|
+
} else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt)) {
|
|
1284
1308
|
openContent = false;
|
|
1309
|
+
} else if (BARE_MARKER_RE.test(tt)) {
|
|
1310
|
+
openContent = tt[0] === "-" ? false : cp.prevLineOpenContent;
|
|
1285
1311
|
} else if (SETEXT_LEFTOVER_RE.test(tt)) {
|
|
1286
|
-
openContent = !cp.prevLineOpenContent;
|
|
1312
|
+
openContent = cp.tableMaybeOpen && cp.prevLineOpenContent ? true : !cp.prevLineOpenContent;
|
|
1287
1313
|
} else {
|
|
1288
1314
|
openContent = true;
|
|
1289
1315
|
}
|
|
1290
1316
|
cp.prevLineOpenContent = openContent;
|
|
1291
|
-
cp.tableMaybeOpen = ln.text.includes("|") || cp.tableMaybeOpen && openContent;
|
|
1317
|
+
cp.tableMaybeOpen = !htmlOwnedLine && ln.text.includes("|") || cp.tableMaybeOpen && openContent;
|
|
1318
|
+
const containerMarker = CONTAINER_MARKER_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defListEnabled && DEF_LIST_DD_RE.test(ln.text);
|
|
1319
|
+
cp.containerMaybeOpen = openContent && (containerMarker || cp.containerMaybeOpen);
|
|
1292
1320
|
}
|
|
1293
1321
|
cp.prevLineWasValidDef = validLinkDef;
|
|
1322
|
+
cp.defBlockMaybeOpen = cp.defBlockMaybeOpen || DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
|
|
1323
|
+
if (FOOTNOTE_DEF_RE.test(ln.text)) cp.fnDefResumable = true;
|
|
1324
|
+
else if (isBlockStart && ln.indent <= 3) cp.fnDefResumable = false;
|
|
1294
1325
|
}
|
|
1295
1326
|
|
|
1296
1327
|
// src/components/incrementalParse/spliceParse.ts
|
|
@@ -1805,7 +1836,7 @@ function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
|
|
|
1805
1836
|
if (sepBuffer.length !== trailingGaps && sepBuffer.length !== trailingGaps + 1) return null;
|
|
1806
1837
|
for (let j = pairIdx + 1; j < visibles.length; j++) {
|
|
1807
1838
|
const v = visibles[j];
|
|
1808
|
-
if (v.type === "html" &&
|
|
1839
|
+
if (v.type === "html" && !isExactSanitizeStrippedConstruct(v.value)) return null;
|
|
1809
1840
|
}
|
|
1810
1841
|
for (let i = 0; i < trailingGaps + seam; i++) {
|
|
1811
1842
|
out.push({ type: "text", value: "\n" });
|
|
@@ -1855,7 +1886,7 @@ function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
|
|
|
1855
1886
|
if (!isSeparatorText(firstText)) {
|
|
1856
1887
|
if (firstText.type === "text" && firstText.position === void 0 && firstVisible?.type === "html") {
|
|
1857
1888
|
if (/^\s*<\/[A-Za-z][A-Za-z0-9-]*\s*>/.test(firstVisible.value)) return true;
|
|
1858
|
-
if (
|
|
1889
|
+
if (isSanitizeStrippedConstruct(firstVisible.value)) return false;
|
|
1859
1890
|
return null;
|
|
1860
1891
|
}
|
|
1861
1892
|
return false;
|
|
@@ -1871,12 +1902,26 @@ function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
|
|
|
1871
1902
|
}
|
|
1872
1903
|
}
|
|
1873
1904
|
if (firstVisible.type === "math") return false;
|
|
1874
|
-
if (firstVisible.type === "html" &&
|
|
1905
|
+
if (firstVisible.type === "html" && isSanitizeStrippedConstruct(firstVisible.value)) return false;
|
|
1875
1906
|
return null;
|
|
1876
1907
|
}
|
|
1877
|
-
function
|
|
1908
|
+
function isSanitizeStrippedConstruct(value) {
|
|
1878
1909
|
const v = value.trim();
|
|
1879
|
-
return v.startsWith("<!--") && v.endsWith("-->") || v.startsWith("<?") && v.endsWith("?>") || v.startsWith("<![CDATA[") && v.endsWith("]]>") || /^<![A-Za-z]/.test(v) && v.endsWith(">");
|
|
1910
|
+
return v.startsWith("<!--") && v.endsWith("-->") || v.startsWith("<?") && v.endsWith("?>") || v.startsWith("<![CDATA[") && v.endsWith("]]>") || /^<![A-Za-z]/.test(v) && !/^<!doctype/i.test(v) && v.endsWith(">");
|
|
1911
|
+
}
|
|
1912
|
+
function isExactSanitizeStrippedConstruct(value) {
|
|
1913
|
+
if (value.startsWith("<!--")) {
|
|
1914
|
+
if (value.length < 7 || !value.endsWith("-->")) return false;
|
|
1915
|
+
const close = value.indexOf("-->", 4);
|
|
1916
|
+
const bangClose = value.indexOf("--!>", 4);
|
|
1917
|
+
if (close !== value.length - 3) return false;
|
|
1918
|
+
return bangClose === -1 || bangClose > close;
|
|
1919
|
+
}
|
|
1920
|
+
if (/^<!doctype/i.test(value)) return false;
|
|
1921
|
+
if (value.startsWith("<?") || /^<!(?:[A-Za-z]|\[CDATA\[)/.test(value)) {
|
|
1922
|
+
return value.indexOf(">") === value.length - 1;
|
|
1923
|
+
}
|
|
1924
|
+
return false;
|
|
1880
1925
|
}
|
|
1881
1926
|
function isSeparatorText(node) {
|
|
1882
1927
|
return node.type === "text" && node.position === void 0 && node.value.trim() === "";
|
|
@@ -5029,7 +5074,6 @@ export {
|
|
|
5029
5074
|
collectDefLabels,
|
|
5030
5075
|
computeFreezeBoundary,
|
|
5031
5076
|
createDefLabelScanner,
|
|
5032
|
-
createFile,
|
|
5033
5077
|
createIncrementalLatexPreprocessor,
|
|
5034
5078
|
createProcessor,
|
|
5035
5079
|
createRegistry,
|
|
@@ -5046,10 +5090,8 @@ export {
|
|
|
5046
5090
|
hasLoneSurrogate,
|
|
5047
5091
|
highlight,
|
|
5048
5092
|
isFootnoteSection,
|
|
5049
|
-
isWhitespaceText,
|
|
5050
5093
|
lastMeaningfulIdx,
|
|
5051
5094
|
measureStage,
|
|
5052
|
-
mergeClassNameAllowlist,
|
|
5053
5095
|
normalizeForMatch,
|
|
5054
5096
|
normalizeId,
|
|
5055
5097
|
pangu,
|
|
@@ -5065,7 +5107,6 @@ export {
|
|
|
5065
5107
|
shortenDocumentId,
|
|
5066
5108
|
smartypants,
|
|
5067
5109
|
sourceIdFromFootnoteLiId,
|
|
5068
|
-
splitByProtectedRegions,
|
|
5069
5110
|
subscribeStageTimings,
|
|
5070
5111
|
transformStage,
|
|
5071
5112
|
withDefs
|