@ai-react-markdown/engine 2.5.1 → 2.5.3
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 +70 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -1
- package/dist/index.d.ts +40 -1
- package/dist/index.dev.cjs +70 -34
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +68 -34
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +68 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.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",
|
|
@@ -242,6 +262,7 @@ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
242
262
|
]);
|
|
243
263
|
var TYPE6_START_RE = /^<\/?([A-Za-z][A-Za-z0-9-]*)(?:[ \t\r]|\/?>|$)/;
|
|
244
264
|
var TYPE1_START_RE = /^<(script|pre|style|textarea)(?:[ \t\r]|>|$)/i;
|
|
265
|
+
var TYPE1_CLOSE_RE = /<\/(?:script|pre|style|textarea)>/i;
|
|
245
266
|
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
267
|
var t7Name = (line) => /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(line)[1];
|
|
247
268
|
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
@@ -417,7 +438,9 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
417
438
|
tagAcrossLines: false,
|
|
418
439
|
tagAcrossLinesIndent: 0,
|
|
419
440
|
tagAcrossLinesState: "outside",
|
|
420
|
-
htmlFlowReal: false
|
|
441
|
+
htmlFlowReal: false,
|
|
442
|
+
type1FlowOpen: false,
|
|
443
|
+
rawTextInline: false
|
|
421
444
|
};
|
|
422
445
|
}
|
|
423
446
|
function isPlausibleLinkDefRest(rest) {
|
|
@@ -562,8 +585,9 @@ function computeFreezeBoundary(text, options, resume) {
|
|
|
562
585
|
if (tailLine) return !canBecomeDdLine(tailLine.text, false);
|
|
563
586
|
return false;
|
|
564
587
|
};
|
|
588
|
+
const tailRetroactive = tailLine !== null && tailCarriesRetroactive(tailLine.text);
|
|
565
589
|
let boundary = 0;
|
|
566
|
-
for (let i = cp.candidates.length - 1; i >= 0; i--) {
|
|
590
|
+
for (let i = cp.candidates.length - 1; i >= 0 && !tailRetroactive; i--) {
|
|
567
591
|
const c = cp.candidates[i];
|
|
568
592
|
if (!c.htmlBalanced || c.hazard || c.seamRisk) continue;
|
|
569
593
|
if (c.offset > cp.phasePoisonedAt) continue;
|
|
@@ -647,8 +671,10 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
647
671
|
cp.rawTextOpen = null;
|
|
648
672
|
} else if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
|
|
649
673
|
cp.rawTextOpen = tag;
|
|
674
|
+
cp.rawTextInline = !cp.htmlFlowReal;
|
|
650
675
|
if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
651
676
|
}
|
|
677
|
+
if (DOCUMENT_STRUCTURE_NAMES.has(tag)) cp.phasePoisonedAt = 0;
|
|
652
678
|
if (closing) {
|
|
653
679
|
const count = cp.tagBalance.get(tag) ?? 0;
|
|
654
680
|
if (count > 0) {
|
|
@@ -759,15 +785,22 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
759
785
|
cp.candidates.push({
|
|
760
786
|
offset: Math.min(ln.end + 1, text.length),
|
|
761
787
|
blankRun: cp.blankRun,
|
|
762
|
-
|
|
788
|
+
// `type1FlowOpen`: an unterminated type-1 block swallows this blank
|
|
789
|
+
// and everything after it as RAW content, so nothing here is a block
|
|
790
|
+
// boundary at all. Its tags are invisible to the balance scan
|
|
791
|
+
// (`rawTextOpen` suppresses them), which is exactly why `openTotal`
|
|
792
|
+
// reads 0 and the candidate looked safe.
|
|
793
|
+
htmlBalanced: cp.openTotal === 0 && !cp.commentOpen && !cp.piOpen && !cp.declOpen && !cp.cdataOpen && !cp.bogusOpen && !cp.type1FlowOpen,
|
|
763
794
|
hazard: cp.hazardVerdict,
|
|
764
795
|
seamRisk: cp.htmlSeamPending,
|
|
765
796
|
defListSettled: null
|
|
766
797
|
});
|
|
767
798
|
cp.paragraphHasUnpairedRun = false;
|
|
768
799
|
cp.openBracket = null;
|
|
769
|
-
cp.
|
|
770
|
-
|
|
800
|
+
if (!cp.type1FlowOpen) {
|
|
801
|
+
cp.htmlFlowSinceBlank = false;
|
|
802
|
+
cp.htmlFlowReal = false;
|
|
803
|
+
}
|
|
771
804
|
cp.prevLineBlank = true;
|
|
772
805
|
cp.prevLineWasText = false;
|
|
773
806
|
cp.prevLineWasValidDef = false;
|
|
@@ -781,7 +814,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
781
814
|
}
|
|
782
815
|
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
|
|
783
816
|
if (tagStart) {
|
|
817
|
+
const noRealBlockOpen = !cp.htmlFlowReal;
|
|
784
818
|
cp.htmlFlowSinceBlank = true;
|
|
819
|
+
if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.type1FlowOpen = true;
|
|
785
820
|
if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
|
|
786
821
|
if (!cp.htmlFlowReal) {
|
|
787
822
|
const t = mdTrimStart(ln.text);
|
|
@@ -932,6 +967,7 @@ ${cont(scanText)}` };
|
|
|
932
967
|
pos = pi + 2;
|
|
933
968
|
} else {
|
|
934
969
|
rawSpans.push([decl, decl + 2]);
|
|
970
|
+
if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
|
|
935
971
|
cp.declOpen = true;
|
|
936
972
|
pos = decl + 2;
|
|
937
973
|
}
|
|
@@ -1012,7 +1048,10 @@ ${cont(scanText)}` };
|
|
|
1012
1048
|
TAG_OR_COMMENT_RE.lastIndex = gt + 1;
|
|
1013
1049
|
}
|
|
1014
1050
|
}
|
|
1015
|
-
if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs))
|
|
1051
|
+
if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs)) {
|
|
1052
|
+
TAG_OR_COMMENT_RE.lastIndex = m.index + 2 + m[2].length;
|
|
1053
|
+
continue;
|
|
1054
|
+
}
|
|
1016
1055
|
const selfClosing = /\/\s*$/.test(attrs);
|
|
1017
1056
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
1018
1057
|
applyTag(tag, closing);
|
|
@@ -1093,6 +1132,14 @@ ${cont(scanText)}` };
|
|
|
1093
1132
|
cp.htmlSeamPending = true;
|
|
1094
1133
|
}
|
|
1095
1134
|
}
|
|
1135
|
+
if (cp.rawTextOpen !== null && cp.rawTextInline) {
|
|
1136
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1137
|
+
}
|
|
1138
|
+
if (cp.type1FlowOpen && TYPE1_CLOSE_RE.test(ln.text)) {
|
|
1139
|
+
cp.type1FlowOpen = false;
|
|
1140
|
+
cp.htmlFlowSinceBlank = false;
|
|
1141
|
+
cp.htmlFlowReal = false;
|
|
1142
|
+
}
|
|
1096
1143
|
cp.blankRun = 0;
|
|
1097
1144
|
cp.prevLineBlank = false;
|
|
1098
1145
|
cp.prevLineWasText = true;
|
|
@@ -1108,6 +1155,15 @@ function isFootnoteSection(node) {
|
|
|
1108
1155
|
const props = node.properties;
|
|
1109
1156
|
return props?.dataFootnotes !== void 0;
|
|
1110
1157
|
}
|
|
1158
|
+
function isWhitespaceText(c) {
|
|
1159
|
+
return c.type === "text" && /^\s*$/.test(c.value);
|
|
1160
|
+
}
|
|
1161
|
+
function lastMeaningfulIdx(children) {
|
|
1162
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
1163
|
+
if (!isWhitespaceText(children[i])) return i;
|
|
1164
|
+
}
|
|
1165
|
+
return -1;
|
|
1166
|
+
}
|
|
1111
1167
|
|
|
1112
1168
|
// src/components/incrementalParse/attributeHastChildren.ts
|
|
1113
1169
|
function attributeHastChildren(mdast, hast, stopAt = Infinity) {
|
|
@@ -1890,16 +1946,6 @@ function isBackrefAnchor(c) {
|
|
|
1890
1946
|
if (el.tagName !== "a") return false;
|
|
1891
1947
|
return Boolean(el.properties && "dataFootnoteBackref" in el.properties);
|
|
1892
1948
|
}
|
|
1893
|
-
function isWhitespaceText(c) {
|
|
1894
|
-
if (c.type !== "text") return false;
|
|
1895
|
-
return /^\s*$/.test(c.value);
|
|
1896
|
-
}
|
|
1897
|
-
function lastMeaningfulIdx(children) {
|
|
1898
|
-
for (let i = children.length - 1; i >= 0; i--) {
|
|
1899
|
-
if (!isWhitespaceText(children[i])) return i;
|
|
1900
|
-
}
|
|
1901
|
-
return -1;
|
|
1902
|
-
}
|
|
1903
1949
|
function dropTrailingBackrefs(children) {
|
|
1904
1950
|
let trailingWsStart = children.length;
|
|
1905
1951
|
while (trailingWsStart > 0 && isWhitespaceText(children[trailingWsStart - 1])) {
|
|
@@ -4566,21 +4612,7 @@ function convertSingleToDoubleDollar(text) {
|
|
|
4566
4612
|
}
|
|
4567
4613
|
function preprocessLaTeX(str) {
|
|
4568
4614
|
if (!hasLatexTrigger(str)) return str;
|
|
4569
|
-
|
|
4570
|
-
const result = segments.map((segment) => {
|
|
4571
|
-
if (segment.isCode) return segment.text;
|
|
4572
|
-
let text = segment.text;
|
|
4573
|
-
text = escapeMhchemCommands(text);
|
|
4574
|
-
text = escapeCurrencyDollarSigns(text);
|
|
4575
|
-
text = convertLatexDelimiters(text);
|
|
4576
|
-
text = escapeLatexPipes(text);
|
|
4577
|
-
text = escapeLatexPipesInUnclosed(text);
|
|
4578
|
-
text = escapeTextUnderscores(text);
|
|
4579
|
-
text = convertSingleToDoubleDollar(text);
|
|
4580
|
-
text = truncateUnclosedLatexBlock(text);
|
|
4581
|
-
return text;
|
|
4582
|
-
});
|
|
4583
|
-
return result.join("");
|
|
4615
|
+
return processSlice(str, false).out;
|
|
4584
4616
|
}
|
|
4585
4617
|
function hasLatexTrigger(str) {
|
|
4586
4618
|
return str.includes("$") || str.includes("\\[") || str.includes("\\(");
|
|
@@ -4609,7 +4641,7 @@ function hasUnclosedTextCommand(text) {
|
|
|
4609
4641
|
}
|
|
4610
4642
|
var RESIDUAL_OPEN_BRACKET_RE = /(?<!!)\\\[/;
|
|
4611
4643
|
var LEADING_DOUBLE_DOLLAR_RE = /^\s*\$\$/;
|
|
4612
|
-
function
|
|
4644
|
+
function processSlice(slice, probe = true) {
|
|
4613
4645
|
const segments = splitByProtectedRegions(slice);
|
|
4614
4646
|
const parts = [];
|
|
4615
4647
|
let quiescent = true;
|
|
@@ -4733,13 +4765,13 @@ function createIncrementalLatexPreprocessor(options) {
|
|
|
4733
4765
|
};
|
|
4734
4766
|
const cut = findRawSafeCut(active);
|
|
4735
4767
|
if (cut > 0) {
|
|
4736
|
-
const candidate =
|
|
4768
|
+
const candidate = processSlice(active.slice(0, cut));
|
|
4737
4769
|
if (candidate.quiescent) freeze(cut, candidate);
|
|
4738
4770
|
}
|
|
4739
4771
|
nextAttemptLen = advanced || !backoff ? 0 : active.length * 2;
|
|
4740
4772
|
onAttempt?.({ activeLength, frozenBytes });
|
|
4741
4773
|
}
|
|
4742
|
-
const tail =
|
|
4774
|
+
const tail = processSlice(active, false);
|
|
4743
4775
|
const head = tail.truncatedAtSeamStart ? frozenOut.replace(/\s+$/, "") : frozenOut;
|
|
4744
4776
|
const out = head + tail.out;
|
|
4745
4777
|
prevSource = source;
|
|
@@ -4803,6 +4835,8 @@ export {
|
|
|
4803
4835
|
hasLoneSurrogate,
|
|
4804
4836
|
highlight,
|
|
4805
4837
|
isFootnoteSection,
|
|
4838
|
+
isWhitespaceText,
|
|
4839
|
+
lastMeaningfulIdx,
|
|
4806
4840
|
measureStage,
|
|
4807
4841
|
mergeClassNameAllowlist,
|
|
4808
4842
|
normalizeForMatch,
|