@ai-react-markdown/engine 2.7.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 +259 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -78
- package/dist/index.d.ts +4 -78
- package/dist/index.dev.cjs +259 -70
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +259 -66
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +259 -66
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.dev.js
CHANGED
|
@@ -426,12 +426,82 @@ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
426
426
|
// (oracle review of the r2 batch; regression caught before release).
|
|
427
427
|
"plaintext"
|
|
428
428
|
]);
|
|
429
|
+
var P5_MARKUP_RE = /<[!/?A-Za-z]/;
|
|
429
430
|
var TYPE6_START_RE = /^<\/?([A-Za-z][A-Za-z0-9-]*)(?:[ \t\r]|\/?>|$)/;
|
|
430
431
|
var TYPE1_START_RE = /^<(script|pre|style|textarea)(?:[ \t\r]|>|$)/i;
|
|
431
432
|
var TYPE1_CLOSE_RE = /<\/(?:script|pre|style|textarea)>/i;
|
|
432
|
-
var
|
|
433
|
-
var
|
|
433
|
+
var isSpaceTab = (c) => c === 32 || c === 9;
|
|
434
|
+
var isAsciiAlpha = (c) => c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
435
|
+
var isAlnum = (c) => isAsciiAlpha(c) || c >= 48 && c <= 57;
|
|
436
|
+
var isAttrNameRest = (c) => isAlnum(c) || c === 45 || c === 46 || c === 58 || c === 95;
|
|
437
|
+
var isUnquotedExit = (c) => Number.isNaN(c) || c === 34 || c === 39 || c === 47 || c === 60 || c === 61 || c === 62 || c === 96 || isSpaceTab(c);
|
|
438
|
+
var completeOpenTagRest = (t, from) => {
|
|
439
|
+
let i = from;
|
|
440
|
+
for (; ; ) {
|
|
441
|
+
const c = t.charCodeAt(i);
|
|
442
|
+
if (c === 47) {
|
|
443
|
+
i += 1;
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
if (isSpaceTab(c)) {
|
|
447
|
+
i += 1;
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (!(c === 58 || c === 95 || isAsciiAlpha(c))) break;
|
|
451
|
+
i += 1;
|
|
452
|
+
while (isAttrNameRest(t.charCodeAt(i))) i += 1;
|
|
453
|
+
for (; ; ) {
|
|
454
|
+
while (isSpaceTab(t.charCodeAt(i))) i += 1;
|
|
455
|
+
if (t.charCodeAt(i) !== 61) break;
|
|
456
|
+
i += 1;
|
|
457
|
+
while (isSpaceTab(t.charCodeAt(i))) i += 1;
|
|
458
|
+
const v = t.charCodeAt(i);
|
|
459
|
+
if (Number.isNaN(v) || v === 60 || v === 61 || v === 62 || v === 96) return -1;
|
|
460
|
+
if (v === 34 || v === 39) {
|
|
461
|
+
i += 1;
|
|
462
|
+
while (t.charCodeAt(i) !== v) {
|
|
463
|
+
if (i >= t.length) return -1;
|
|
464
|
+
i += 1;
|
|
465
|
+
}
|
|
466
|
+
i += 1;
|
|
467
|
+
const a = t.charCodeAt(i);
|
|
468
|
+
if (!(a === 47 || a === 62 || isSpaceTab(a))) return -1;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
while (!isUnquotedExit(t.charCodeAt(i))) i += 1;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return t.charCodeAt(i) === 62 ? i + 1 : -1;
|
|
475
|
+
};
|
|
476
|
+
var isType7Line = (line) => {
|
|
477
|
+
const cr = line.indexOf("\r");
|
|
478
|
+
const t = cr === -1 ? line : line.slice(0, cr);
|
|
479
|
+
if (t.charCodeAt(0) !== 60) return false;
|
|
480
|
+
let i = 1;
|
|
481
|
+
const closing = t.charCodeAt(i) === 47;
|
|
482
|
+
if (closing) i += 1;
|
|
483
|
+
if (!isAsciiAlpha(t.charCodeAt(i))) return false;
|
|
484
|
+
const nameStart = i;
|
|
485
|
+
i += 1;
|
|
486
|
+
while (isAlnum(t.charCodeAt(i)) || t.charCodeAt(i) === 45) i += 1;
|
|
487
|
+
const c = t.charCodeAt(i);
|
|
488
|
+
if (!(Number.isNaN(c) || c === 47 || c === 62 || isSpaceTab(c))) return false;
|
|
489
|
+
const name = t.slice(nameStart, i).toLowerCase();
|
|
490
|
+
if (!closing && c !== 47 && TYPE1_NAMES.has(name)) return false;
|
|
491
|
+
if (TYPE6_NAMES.has(name)) return false;
|
|
492
|
+
if (closing) {
|
|
493
|
+
while (isSpaceTab(t.charCodeAt(i))) i += 1;
|
|
494
|
+
if (t.charCodeAt(i) !== 62) return false;
|
|
495
|
+
i += 1;
|
|
496
|
+
} else {
|
|
497
|
+
i = completeOpenTagRest(t, i);
|
|
498
|
+
if (i === -1) return false;
|
|
499
|
+
}
|
|
500
|
+
while (isSpaceTab(t.charCodeAt(i))) i += 1;
|
|
501
|
+
return i >= t.length;
|
|
502
|
+
};
|
|
434
503
|
var mdHtml = (b, type) => b.kind === "html" && b.type === type;
|
|
504
|
+
var mdType1RawText = (b) => b.kind === "html" && b.type === 1 && b.raw;
|
|
435
505
|
var mdHtml25 = (b) => b.kind === "html" && b.type >= 2 && b.type <= 5;
|
|
436
506
|
var commentEitherOpen = (md, p5) => mdHtml(md, 2) || p5.kind === "comment";
|
|
437
507
|
var inRawTextTok = (t) => t.kind === "rawText" || t.kind === "script";
|
|
@@ -453,7 +523,13 @@ var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
|
453
523
|
"wbr"
|
|
454
524
|
]);
|
|
455
525
|
var LIST_MARKER_RE = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
|
|
526
|
+
var CONTAINER_MARKER_RE = /^ {0,3}(?:>|(?:[-*+]|\d{1,9}[.)])[ \t]+\S)/;
|
|
527
|
+
var ATX_HEADING_RE = /^#{1,6}(?:[ \t]|$)/;
|
|
528
|
+
var THEMATIC_BREAK_RE = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
529
|
+
var BARE_MARKER_RE = /^(?:[-*+]|\d{1,9}[.)])[ \t]*$/;
|
|
530
|
+
var SETEXT_LEFTOVER_RE = /^(?:=+|--)[ \t]*$/;
|
|
456
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]*$/;
|
|
457
533
|
var FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
|
|
458
534
|
var MATH_RUN_RE = /^ {0,3}(\$\$+)/;
|
|
459
535
|
var TAG_OR_COMMENT_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?=[\s/>])([^>]*)>|<!--|-->|--!>/g;
|
|
@@ -562,10 +638,14 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
562
638
|
// doc start counts as a block start
|
|
563
639
|
prevLineWasText: false,
|
|
564
640
|
prevLineWasValidDef: false,
|
|
641
|
+
prevLineOpenContent: false,
|
|
642
|
+
tableMaybeOpen: false,
|
|
643
|
+
containerMaybeOpen: false,
|
|
565
644
|
paragraphHasUnpairedRun: false,
|
|
566
645
|
openBracket: null,
|
|
567
|
-
mayBeRawToMicromark: false,
|
|
568
646
|
p5SealPending: false,
|
|
647
|
+
defBlockMaybeOpen: false,
|
|
648
|
+
fnDefResumable: false,
|
|
569
649
|
phasePoisonedAt: Infinity,
|
|
570
650
|
pendingTruncatedTags: [],
|
|
571
651
|
pendingTruncatedCloses: [],
|
|
@@ -692,10 +772,11 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
692
772
|
newest.defListSettled = ln.blank ? true : !canBecomeDdLine(ln.text, true);
|
|
693
773
|
}
|
|
694
774
|
const isBlockStart = cp.prevLineBlank;
|
|
695
|
-
if (cp.p5SealPending && !ln.blank &&
|
|
696
|
-
const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
|
|
775
|
+
if (cp.p5SealPending && !ln.blank && cp.mdBlock.kind !== "html" && !(cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus")) {
|
|
776
|
+
const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defBlockMaybeOpen || cp.fnDefResumable && ln.indent >= 4;
|
|
697
777
|
const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
|
|
698
|
-
|
|
778
|
+
const closeTagOnly = CLOSE_TAG_ONLY_RE.test(ln.text);
|
|
779
|
+
if (!defShapedLine && !commentOnly && !closeTagOnly) {
|
|
699
780
|
cp.p5SealPending = false;
|
|
700
781
|
}
|
|
701
782
|
}
|
|
@@ -705,9 +786,13 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
705
786
|
const applyTag = (tag, closing) => {
|
|
706
787
|
if (inRawTextTok(cp.p5Tok)) {
|
|
707
788
|
if (cp.p5Tok.kind === "script" && cp.p5Tok.escaped && !closing && tag === "script") {
|
|
708
|
-
cp.
|
|
789
|
+
cp.p5Tok = { ...cp.p5Tok, double: true };
|
|
709
790
|
}
|
|
710
791
|
if (!(closing && tag === rawTextElement(cp.p5Tok))) return;
|
|
792
|
+
if (cp.p5Tok.kind === "script" && cp.p5Tok.double) {
|
|
793
|
+
cp.p5Tok = { ...cp.p5Tok, double: false };
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
711
796
|
cp.p5Tok = { kind: "data" };
|
|
712
797
|
} else {
|
|
713
798
|
if (!closing && RAW_TEXT_ELEMENTS.has(tag) && foreignRawTextSwitchUnknowable()) {
|
|
@@ -715,7 +800,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
715
800
|
} else if (!closing && RAW_TEXT_ELEMENTS.has(tag)) {
|
|
716
801
|
if (cp.p5Tok.kind !== "data") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
717
802
|
const openedInline = cp.mdBlock.kind !== "html";
|
|
718
|
-
cp.p5Tok = tag === "script" ? { kind: "script", escaped: false, openedInline } : { kind: "rawText", element: tag, openedInline };
|
|
803
|
+
cp.p5Tok = tag === "script" ? { kind: "script", escaped: false, double: false, openedInline } : { kind: "rawText", element: tag, openedInline };
|
|
719
804
|
if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
720
805
|
}
|
|
721
806
|
}
|
|
@@ -743,9 +828,14 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
743
828
|
cp.openTotal += 1;
|
|
744
829
|
}
|
|
745
830
|
};
|
|
746
|
-
const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) >
|
|
831
|
+
const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) > cp.pendingTruncatedTags.filter((t) => t === "table").length;
|
|
747
832
|
const strayTablePart = (tag) => TABLE_PART_NAMES.has(tag) && !definitelyInsideTable();
|
|
748
833
|
const commentOpenAtLineStart = commentEitherOpen(cp.mdBlock, cp.p5Tok);
|
|
834
|
+
const bothCommentsOpenAtLineStart = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind === "comment";
|
|
835
|
+
const inDivergenceWindow = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind !== "comment" || (mdHtml(cp.mdBlock, 3) || mdHtml(cp.mdBlock, 5)) && cp.p5Tok.kind !== "bogus";
|
|
836
|
+
if (inDivergenceWindow && P5_MARKUP_RE.test(ln.text)) {
|
|
837
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
838
|
+
}
|
|
749
839
|
const rawOpenAtLineStart = mdHtml25(cp.mdBlock) || cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus";
|
|
750
840
|
if (cp.mdBlock.kind === "fence") {
|
|
751
841
|
const close = FENCE_RE.exec(ln.text);
|
|
@@ -758,12 +848,15 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
758
848
|
cp.prevLineBlank = false;
|
|
759
849
|
cp.prevLineWasText = false;
|
|
760
850
|
cp.prevLineWasValidDef = false;
|
|
851
|
+
cp.prevLineOpenContent = false;
|
|
852
|
+
cp.tableMaybeOpen = false;
|
|
853
|
+
cp.containerMaybeOpen = false;
|
|
761
854
|
return;
|
|
762
855
|
}
|
|
763
856
|
if (cp.mdBlock.kind !== "math" && !rawOpenAtLineStart) {
|
|
764
857
|
const open = FENCE_RE.exec(ln.text);
|
|
765
858
|
const bogusInfo = open !== null && open[1][0] === "`" && ln.text.slice(ln.text.indexOf(open[1]) + open[1].length).includes("`");
|
|
766
|
-
if (open && !bogusInfo && cp.
|
|
859
|
+
if (open && !bogusInfo && cp.mdBlock.kind === "html") {
|
|
767
860
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
768
861
|
} else if (open && !bogusInfo) {
|
|
769
862
|
if (isBlockStart) {
|
|
@@ -777,6 +870,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
777
870
|
cp.prevLineBlank = false;
|
|
778
871
|
cp.prevLineWasText = false;
|
|
779
872
|
cp.prevLineWasValidDef = false;
|
|
873
|
+
cp.prevLineOpenContent = false;
|
|
874
|
+
cp.tableMaybeOpen = false;
|
|
875
|
+
cp.containerMaybeOpen = false;
|
|
780
876
|
return;
|
|
781
877
|
}
|
|
782
878
|
}
|
|
@@ -791,13 +887,16 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
791
887
|
cp.prevLineBlank = false;
|
|
792
888
|
cp.prevLineWasText = false;
|
|
793
889
|
cp.prevLineWasValidDef = false;
|
|
890
|
+
cp.prevLineOpenContent = false;
|
|
891
|
+
cp.tableMaybeOpen = false;
|
|
892
|
+
cp.containerMaybeOpen = false;
|
|
794
893
|
return;
|
|
795
894
|
}
|
|
796
895
|
const mathRun = cp.mathFlow && !rawOpenAtLineStart ? MATH_RUN_RE.exec(ln.text) : null;
|
|
797
896
|
if (mathRun) {
|
|
798
897
|
const rest = ln.text.slice(ln.text.indexOf(mathRun[1]) + mathRun[1].length);
|
|
799
898
|
if (!rest.includes("$")) {
|
|
800
|
-
if (cp.
|
|
899
|
+
if (cp.mdBlock.kind === "html") {
|
|
801
900
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
802
901
|
} else {
|
|
803
902
|
if (isBlockStart) {
|
|
@@ -811,6 +910,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
811
910
|
cp.prevLineBlank = false;
|
|
812
911
|
cp.prevLineWasText = false;
|
|
813
912
|
cp.prevLineWasValidDef = false;
|
|
913
|
+
cp.prevLineOpenContent = false;
|
|
914
|
+
cp.tableMaybeOpen = false;
|
|
915
|
+
cp.containerMaybeOpen = false;
|
|
814
916
|
return;
|
|
815
917
|
}
|
|
816
918
|
}
|
|
@@ -826,8 +928,11 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
826
928
|
}
|
|
827
929
|
cp.pendingTag = null;
|
|
828
930
|
if (cp.p5Tok.kind === "bogus") {
|
|
829
|
-
|
|
830
|
-
|
|
931
|
+
if (mdHtml25(cp.mdBlock)) {
|
|
932
|
+
} else {
|
|
933
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
934
|
+
cp.p5Tok = { kind: "data" };
|
|
935
|
+
}
|
|
831
936
|
}
|
|
832
937
|
if (cp.mdBlock.kind === "html" && cp.mdBlock.type >= 6) cp.mdBlock = { kind: "none" };
|
|
833
938
|
cp.blankRun += 1;
|
|
@@ -849,7 +954,6 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
849
954
|
cp.paragraphHasUnpairedRun = false;
|
|
850
955
|
cp.openBracket = null;
|
|
851
956
|
if (!mdHtml(cp.mdBlock, 1)) {
|
|
852
|
-
cp.mayBeRawToMicromark = false;
|
|
853
957
|
if (inRawTextTok(cp.p5Tok) && !cp.p5Tok.openedInline) {
|
|
854
958
|
cp.phasePoisonedAt = 0;
|
|
855
959
|
}
|
|
@@ -857,6 +961,10 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
857
961
|
cp.prevLineBlank = true;
|
|
858
962
|
cp.prevLineWasText = false;
|
|
859
963
|
cp.prevLineWasValidDef = false;
|
|
964
|
+
cp.defBlockMaybeOpen = false;
|
|
965
|
+
cp.prevLineOpenContent = false;
|
|
966
|
+
cp.tableMaybeOpen = false;
|
|
967
|
+
cp.containerMaybeOpen = false;
|
|
860
968
|
return;
|
|
861
969
|
}
|
|
862
970
|
if (isBlockStart) {
|
|
@@ -868,24 +976,35 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
868
976
|
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
|
|
869
977
|
if (tagStart) {
|
|
870
978
|
const noRealBlockOpen = cp.mdBlock.kind !== "html";
|
|
871
|
-
|
|
872
|
-
if (
|
|
873
|
-
if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
|
|
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()) };
|
|
874
981
|
if (cp.mdBlock.kind !== "html") {
|
|
875
982
|
const t = mdTrimStart(ln.text);
|
|
876
983
|
const t6 = TYPE6_START_RE.exec(t);
|
|
877
|
-
const t7 = TYPE7_LINE_RE.exec(t);
|
|
878
984
|
const realT6 = t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase());
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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
|
|
988
|
+
// construct — `prevLineOpenContent`, the exact interrupt input; the
|
|
989
|
+
// old `prevLineWasText` gate refused after headings, terminator
|
|
990
|
+
// lines and fence closes, where micromark measurably opens). The
|
|
991
|
+
// classifier itself is exact too (isType7Line) — including closing
|
|
992
|
+
// raw-text names (`</style>` alone is type 7, measured) and
|
|
993
|
+
// quoted-`>` attribute values.
|
|
994
|
+
!cp.prevLineOpenContent && type7Shaped) {
|
|
882
995
|
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7 };
|
|
996
|
+
} else if (cp.prevLineOpenContent && cp.tableMaybeOpen && type7Shaped) {
|
|
997
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
998
|
+
}
|
|
999
|
+
if (type7Shaped && cp.containerMaybeOpen) {
|
|
1000
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
883
1001
|
}
|
|
884
1002
|
}
|
|
885
1003
|
}
|
|
886
|
-
const inRawText = cp.mayBeRawToMicromark || rawOpenAtLineStart;
|
|
887
1004
|
const rawFlowStart = ln.indent <= 3 && /^<(?:!--|\?|![A-Za-z]|!\[CDATA\[)/.test(mdTrimStart(ln.text));
|
|
888
|
-
const
|
|
1005
|
+
const htmlOwnedLine = cp.mdBlock.kind === "html" || rawOpenAtLineStart || rawFlowStart;
|
|
1006
|
+
const maskingSuppressed = htmlOwnedLine || inRawTextTok(cp.p5Tok);
|
|
1007
|
+
const { masked, unpaired } = maskingSuppressed ? { masked: null, unpaired: false } : maskIntraLineCodeSpans(ln.text, cp.paragraphHasUnpairedRun);
|
|
889
1008
|
if (unpaired) cp.paragraphHasUnpairedRun = true;
|
|
890
1009
|
const scanText = masked ?? ln.text;
|
|
891
1010
|
const defRawToMicromark = cp.mdBlock.kind === "html" || rawOpenAtLineStart || inRawTextTok(cp.p5Tok);
|
|
@@ -897,30 +1016,27 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
897
1016
|
};
|
|
898
1017
|
let inlineRawOpenerIdx = -1;
|
|
899
1018
|
while (pos < scanText.length) {
|
|
900
|
-
if (mdHtml(cp.mdBlock, 3)) {
|
|
901
|
-
const
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
if (c === -1) {
|
|
918
|
-
rawSpans.push([pos, scanText.length]);
|
|
919
|
-
break;
|
|
1019
|
+
if (mdHtml(cp.mdBlock, 3) || mdHtml(cp.mdBlock, 5)) {
|
|
1020
|
+
const isPi = mdHtml(cp.mdBlock, 3);
|
|
1021
|
+
const term = isPi ? "?>" : "]]>";
|
|
1022
|
+
const c = scanText.indexOf(term, pos);
|
|
1023
|
+
const mdEnd = c === -1 ? scanText.length : c + term.length;
|
|
1024
|
+
if (cp.p5Tok.kind === "bogus") {
|
|
1025
|
+
const gt = scanText.indexOf(">", pos);
|
|
1026
|
+
if (gt !== -1 && (c === -1 || gt !== c + term.length - 1)) {
|
|
1027
|
+
cp.p5Tok = { kind: "data" };
|
|
1028
|
+
rawSpans.push([pos, gt + 1]);
|
|
1029
|
+
if (P5_MARKUP_RE.test(scanText.slice(gt + 1, c === -1 ? scanText.length : c))) {
|
|
1030
|
+
poisonRawDivergence();
|
|
1031
|
+
}
|
|
1032
|
+
} else {
|
|
1033
|
+
rawSpans.push([pos, mdEnd]);
|
|
1034
|
+
if (c !== -1) cp.p5Tok = { kind: "data" };
|
|
1035
|
+
}
|
|
920
1036
|
}
|
|
921
|
-
|
|
1037
|
+
if (c === -1) break;
|
|
922
1038
|
cp.mdBlock = { kind: "none" };
|
|
923
|
-
pos =
|
|
1039
|
+
pos = mdEnd;
|
|
924
1040
|
continue;
|
|
925
1041
|
}
|
|
926
1042
|
if (mdHtml(cp.mdBlock, 4)) {
|
|
@@ -946,7 +1062,12 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
946
1062
|
pos = c + 1;
|
|
947
1063
|
continue;
|
|
948
1064
|
}
|
|
949
|
-
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
|
+
}
|
|
950
1071
|
const pi = scanText.indexOf("<?", pos);
|
|
951
1072
|
const cd = scanText.indexOf("<![CDATA[", pos);
|
|
952
1073
|
const dm = scanText.slice(pos).search(/<![A-Za-z]/);
|
|
@@ -963,7 +1084,8 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
963
1084
|
pos = bogus + 2;
|
|
964
1085
|
} else if (first === cd) {
|
|
965
1086
|
rawSpans.push([cd, cd + 9]);
|
|
966
|
-
cp.mdBlock = { kind: "html", type: 5 };
|
|
1087
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5 };
|
|
1088
|
+
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
967
1089
|
if (!isMdBlank(scanText.slice(0, cd)) || ln.indent > 3) inlineRawOpenerIdx = cd;
|
|
968
1090
|
pos = cd + 9;
|
|
969
1091
|
} else if (first === pi) {
|
|
@@ -974,13 +1096,15 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
974
1096
|
continue;
|
|
975
1097
|
}
|
|
976
1098
|
rawSpans.push([pi, pi + 2]);
|
|
977
|
-
cp.mdBlock = { kind: "html", type: 3 };
|
|
1099
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3 };
|
|
1100
|
+
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
978
1101
|
if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) inlineRawOpenerIdx = pi;
|
|
979
1102
|
pos = pi + 2;
|
|
980
1103
|
} else {
|
|
981
1104
|
rawSpans.push([decl, decl + 2]);
|
|
982
1105
|
if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
|
|
983
|
-
cp.mdBlock = { kind: "html", type: 4 };
|
|
1106
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4 };
|
|
1107
|
+
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
984
1108
|
if (!isMdBlank(scanText.slice(0, decl)) || ln.indent > 3) inlineRawOpenerIdx = decl;
|
|
985
1109
|
pos = decl + 2;
|
|
986
1110
|
}
|
|
@@ -1017,7 +1141,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1017
1141
|
if (inRawTextTok(cp.p5Tok) && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) {
|
|
1018
1142
|
if (cp.p5Tok.kind === "script") {
|
|
1019
1143
|
if (m[0] === "<!--") cp.p5Tok = { ...cp.p5Tok, escaped: true };
|
|
1020
|
-
if (m[0] === "-->") cp.p5Tok = { ...cp.p5Tok, escaped: false };
|
|
1144
|
+
if (m[0] === "-->") cp.p5Tok = { ...cp.p5Tok, escaped: false, double: false };
|
|
1021
1145
|
}
|
|
1022
1146
|
continue;
|
|
1023
1147
|
}
|
|
@@ -1029,7 +1153,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1029
1153
|
if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
|
|
1030
1154
|
} else if (next === "!>" || next === "-!") {
|
|
1031
1155
|
if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
|
|
1032
|
-
|
|
1156
|
+
if (mdHtml(cp.mdBlock, 2) && P5_MARKUP_RE.test(tagText.slice(m.index + m[0].length))) {
|
|
1157
|
+
poisonRawDivergence();
|
|
1158
|
+
}
|
|
1033
1159
|
}
|
|
1034
1160
|
continue;
|
|
1035
1161
|
}
|
|
@@ -1047,7 +1173,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1047
1173
|
continue;
|
|
1048
1174
|
}
|
|
1049
1175
|
if (m[0] === "--!>") {
|
|
1050
|
-
if (
|
|
1176
|
+
if (mdHtml(cp.mdBlock, 2) && P5_MARKUP_RE.test(tagText.slice(m.index + m[0].length))) {
|
|
1177
|
+
poisonRawDivergence();
|
|
1178
|
+
}
|
|
1051
1179
|
if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
|
|
1052
1180
|
continue;
|
|
1053
1181
|
}
|
|
@@ -1138,14 +1266,16 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1138
1266
|
applyTag(tag, closing);
|
|
1139
1267
|
const rawLastLt = ln.text.lastIndexOf("<");
|
|
1140
1268
|
const rawTruncated = rawLastLt !== -1 && !ln.text.includes(">", rawLastLt);
|
|
1141
|
-
if (!closing && !
|
|
1269
|
+
if (!closing && !(htmlOwnedLine || inRawTextTok(cp.p5Tok)) && rawTruncated) {
|
|
1270
|
+
cp.pendingTruncatedTags.push(tag);
|
|
1271
|
+
}
|
|
1142
1272
|
}
|
|
1143
1273
|
}
|
|
1144
1274
|
}
|
|
1145
1275
|
}
|
|
1146
1276
|
}
|
|
1147
1277
|
const effectiveOpen = cp.openTotal - cp.pendingTruncatedTags.length;
|
|
1148
|
-
if ((
|
|
1278
|
+
if ((htmlOwnedLine || inRawTextTok(cp.p5Tok)) && effectiveOpen <= 0) {
|
|
1149
1279
|
let masked2 = "";
|
|
1150
1280
|
let cursor = 0;
|
|
1151
1281
|
for (const [from, to] of rawSpans) {
|
|
@@ -1153,7 +1283,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1153
1283
|
cursor = to;
|
|
1154
1284
|
}
|
|
1155
1285
|
masked2 += scanText.slice(cursor);
|
|
1156
|
-
if (floatingResidue(masked2,
|
|
1286
|
+
if (floatingResidue(masked2, bothCommentsOpenAtLineStart).length > 0) {
|
|
1157
1287
|
cp.p5SealPending = true;
|
|
1158
1288
|
}
|
|
1159
1289
|
}
|
|
@@ -1162,12 +1292,36 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
1162
1292
|
}
|
|
1163
1293
|
if (mdHtml(cp.mdBlock, 1) && TYPE1_CLOSE_RE.test(ln.text)) {
|
|
1164
1294
|
cp.mdBlock = { kind: "none" };
|
|
1165
|
-
cp.
|
|
1295
|
+
if (inRawTextTok(cp.p5Tok)) cp.phasePoisonedAt = 0;
|
|
1166
1296
|
}
|
|
1167
1297
|
cp.blankRun = 0;
|
|
1168
1298
|
cp.prevLineBlank = false;
|
|
1169
1299
|
cp.prevLineWasText = true;
|
|
1300
|
+
{
|
|
1301
|
+
const tt = mdTrimStart(ln.text);
|
|
1302
|
+
let openContent;
|
|
1303
|
+
if (htmlOwnedLine) {
|
|
1304
|
+
openContent = false;
|
|
1305
|
+
} else if (ln.indent >= 4) {
|
|
1306
|
+
openContent = cp.prevLineOpenContent;
|
|
1307
|
+
} else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt)) {
|
|
1308
|
+
openContent = false;
|
|
1309
|
+
} else if (BARE_MARKER_RE.test(tt)) {
|
|
1310
|
+
openContent = tt[0] === "-" ? false : cp.prevLineOpenContent;
|
|
1311
|
+
} else if (SETEXT_LEFTOVER_RE.test(tt)) {
|
|
1312
|
+
openContent = cp.tableMaybeOpen && cp.prevLineOpenContent ? true : !cp.prevLineOpenContent;
|
|
1313
|
+
} else {
|
|
1314
|
+
openContent = true;
|
|
1315
|
+
}
|
|
1316
|
+
cp.prevLineOpenContent = 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);
|
|
1320
|
+
}
|
|
1170
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;
|
|
1171
1325
|
}
|
|
1172
1326
|
|
|
1173
1327
|
// src/components/incrementalParse/spliceParse.ts
|
|
@@ -1416,6 +1570,33 @@ function headRoutedCaptureUnclosed(values) {
|
|
|
1416
1570
|
return !new RegExp(`</${name}(?=[\\s/>])`, "i").test(after);
|
|
1417
1571
|
}
|
|
1418
1572
|
var STRAY_SYNTHESIZED_END_TAG_RE = /<\/(?:br|p)\b/i;
|
|
1573
|
+
var RAW_TEXT_OPEN_RE = /<(script|style|textarea|title|xmp|iframe|noembed|noframes|plaintext)(?=[\s/>])/gi;
|
|
1574
|
+
function rawTextRegionCrossesOut(values) {
|
|
1575
|
+
for (const value of values) {
|
|
1576
|
+
let pos = 0;
|
|
1577
|
+
for (; ; ) {
|
|
1578
|
+
RAW_TEXT_OPEN_RE.lastIndex = pos;
|
|
1579
|
+
const open = RAW_TEXT_OPEN_RE.exec(value);
|
|
1580
|
+
if (open === null) break;
|
|
1581
|
+
const name = open[1].toLowerCase();
|
|
1582
|
+
const bodyStart = open.index + open[0].length;
|
|
1583
|
+
const closeRe = new RegExp(`</${name}(?=[\\s/>])`, "ig");
|
|
1584
|
+
closeRe.lastIndex = bodyStart;
|
|
1585
|
+
let close = closeRe.exec(value);
|
|
1586
|
+
if (name === "script") {
|
|
1587
|
+
while (close !== null) {
|
|
1588
|
+
const body = value.slice(bodyStart, close.index);
|
|
1589
|
+
const lastOpen = body.lastIndexOf("<!--");
|
|
1590
|
+
if (lastOpen === -1 || body.indexOf("-->", lastOpen + 4) !== -1) break;
|
|
1591
|
+
close = closeRe.exec(value);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (close === null) return true;
|
|
1595
|
+
pos = close.index + close[0].length;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return false;
|
|
1599
|
+
}
|
|
1419
1600
|
function spliceTrees(input) {
|
|
1420
1601
|
const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
|
|
1421
1602
|
const injectedLen = injectionPrefix.length;
|
|
@@ -1472,7 +1653,9 @@ function spliceTrees(input) {
|
|
|
1472
1653
|
return !(start !== void 0 && start < injectedLen);
|
|
1473
1654
|
});
|
|
1474
1655
|
const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
|
|
1475
|
-
|
|
1656
|
+
const prefixHtmlValues = prefixMdast.flatMap((c) => c.type === "html" ? [c.value] : []);
|
|
1657
|
+
if (hasStrayTablePart(prefixHtmlValues)) return null;
|
|
1658
|
+
if (rawTextRegionCrossesOut(prefixHtmlValues)) return null;
|
|
1476
1659
|
const leadingHtml = [];
|
|
1477
1660
|
for (const child of tailMdastChildren) {
|
|
1478
1661
|
if (isWrapInvisible(child)) continue;
|
|
@@ -1653,7 +1836,7 @@ function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
|
|
|
1653
1836
|
if (sepBuffer.length !== trailingGaps && sepBuffer.length !== trailingGaps + 1) return null;
|
|
1654
1837
|
for (let j = pairIdx + 1; j < visibles.length; j++) {
|
|
1655
1838
|
const v = visibles[j];
|
|
1656
|
-
if (v.type === "html" &&
|
|
1839
|
+
if (v.type === "html" && !isExactSanitizeStrippedConstruct(v.value)) return null;
|
|
1657
1840
|
}
|
|
1658
1841
|
for (let i = 0; i < trailingGaps + seam; i++) {
|
|
1659
1842
|
out.push({ type: "text", value: "\n" });
|
|
@@ -1703,7 +1886,7 @@ function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
|
|
|
1703
1886
|
if (!isSeparatorText(firstText)) {
|
|
1704
1887
|
if (firstText.type === "text" && firstText.position === void 0 && firstVisible?.type === "html") {
|
|
1705
1888
|
if (/^\s*<\/[A-Za-z][A-Za-z0-9-]*\s*>/.test(firstVisible.value)) return true;
|
|
1706
|
-
if (
|
|
1889
|
+
if (isSanitizeStrippedConstruct(firstVisible.value)) return false;
|
|
1707
1890
|
return null;
|
|
1708
1891
|
}
|
|
1709
1892
|
return false;
|
|
@@ -1719,12 +1902,26 @@ function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
|
|
|
1719
1902
|
}
|
|
1720
1903
|
}
|
|
1721
1904
|
if (firstVisible.type === "math") return false;
|
|
1722
|
-
if (firstVisible.type === "html" &&
|
|
1905
|
+
if (firstVisible.type === "html" && isSanitizeStrippedConstruct(firstVisible.value)) return false;
|
|
1723
1906
|
return null;
|
|
1724
1907
|
}
|
|
1725
|
-
function
|
|
1908
|
+
function isSanitizeStrippedConstruct(value) {
|
|
1726
1909
|
const v = value.trim();
|
|
1727
|
-
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;
|
|
1728
1925
|
}
|
|
1729
1926
|
function isSeparatorText(node) {
|
|
1730
1927
|
return node.type === "text" && node.position === void 0 && node.value.trim() === "";
|
|
@@ -4889,7 +5086,6 @@ export {
|
|
|
4889
5086
|
collectDefLabels,
|
|
4890
5087
|
computeFreezeBoundary,
|
|
4891
5088
|
createDefLabelScanner,
|
|
4892
|
-
createFile,
|
|
4893
5089
|
createIncrementalLatexPreprocessor,
|
|
4894
5090
|
createProcessor,
|
|
4895
5091
|
createRegistry,
|
|
@@ -4906,10 +5102,8 @@ export {
|
|
|
4906
5102
|
hasLoneSurrogate,
|
|
4907
5103
|
highlight,
|
|
4908
5104
|
isFootnoteSection,
|
|
4909
|
-
isWhitespaceText,
|
|
4910
5105
|
lastMeaningfulIdx,
|
|
4911
5106
|
measureStage,
|
|
4912
|
-
mergeClassNameAllowlist,
|
|
4913
5107
|
normalizeForMatch,
|
|
4914
5108
|
normalizeId,
|
|
4915
5109
|
pangu,
|
|
@@ -4925,7 +5119,6 @@ export {
|
|
|
4925
5119
|
shortenDocumentId,
|
|
4926
5120
|
smartypants,
|
|
4927
5121
|
sourceIdFromFootnoteLiId,
|
|
4928
|
-
splitByProtectedRegions,
|
|
4929
5122
|
subscribeStageTimings,
|
|
4930
5123
|
transformStage,
|
|
4931
5124
|
withDefs
|