@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.cjs
CHANGED
|
@@ -65,6 +65,8 @@ __export(src_exports, {
|
|
|
65
65
|
hasLoneSurrogate: () => hasLoneSurrogate,
|
|
66
66
|
highlight: () => highlight,
|
|
67
67
|
isFootnoteSection: () => isFootnoteSection,
|
|
68
|
+
isWhitespaceText: () => isWhitespaceText,
|
|
69
|
+
lastMeaningfulIdx: () => lastMeaningfulIdx,
|
|
68
70
|
measureStage: () => measureStage,
|
|
69
71
|
mergeClassNameAllowlist: () => mergeClassNameAllowlist,
|
|
70
72
|
normalizeForMatch: () => normalizeForMatch,
|
|
@@ -268,6 +270,26 @@ var import_micromark_util_html_tag_name = require("micromark-util-html-tag-name"
|
|
|
268
270
|
var import_micromark_util_normalize_identifier = require("micromark-util-normalize-identifier");
|
|
269
271
|
var TYPE6_NAMES = new Set(import_micromark_util_html_tag_name.htmlBlockNames);
|
|
270
272
|
var TABLE_PART_NAMES = /* @__PURE__ */ new Set(["td", "th", "tr", "tbody", "thead", "tfoot", "caption", "col", "colgroup"]);
|
|
273
|
+
var DOCUMENT_STRUCTURE_NAMES = /* @__PURE__ */ new Set(["html", "head", "body", "frameset"]);
|
|
274
|
+
var RETROACTIVE_OPENERS = [
|
|
275
|
+
"<!doctype",
|
|
276
|
+
"<html",
|
|
277
|
+
"<head",
|
|
278
|
+
"<body",
|
|
279
|
+
"<frameset",
|
|
280
|
+
"</html",
|
|
281
|
+
"</head",
|
|
282
|
+
"</body",
|
|
283
|
+
"</frameset"
|
|
284
|
+
];
|
|
285
|
+
function tailCarriesRetroactive(text) {
|
|
286
|
+
const lower = text.toLowerCase();
|
|
287
|
+
for (let i = lower.indexOf("<"); i !== -1; i = lower.indexOf("<", i + 1)) {
|
|
288
|
+
const rest = lower.slice(i);
|
|
289
|
+
for (const op of RETROACTIVE_OPENERS) if (rest.startsWith(op)) return true;
|
|
290
|
+
}
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
271
293
|
var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
|
|
272
294
|
"b",
|
|
273
295
|
"big",
|
|
@@ -333,6 +355,7 @@ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
333
355
|
]);
|
|
334
356
|
var TYPE6_START_RE = /^<\/?([A-Za-z][A-Za-z0-9-]*)(?:[ \t\r]|\/?>|$)/;
|
|
335
357
|
var TYPE1_START_RE = /^<(script|pre|style|textarea)(?:[ \t\r]|>|$)/i;
|
|
358
|
+
var TYPE1_CLOSE_RE = /<\/(?:script|pre|style|textarea)>/i;
|
|
336
359
|
var TYPE7_LINE_RE = /^(?:<[A-Za-z][A-Za-z0-9-]*(?:[ \t\r][^>]*|\/)?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\r]*>)[ \t\r]*$/;
|
|
337
360
|
var t7Name = (line) => /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(line)[1];
|
|
338
361
|
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
@@ -508,7 +531,9 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
508
531
|
tagAcrossLines: false,
|
|
509
532
|
tagAcrossLinesIndent: 0,
|
|
510
533
|
tagAcrossLinesState: "outside",
|
|
511
|
-
htmlFlowReal: false
|
|
534
|
+
htmlFlowReal: false,
|
|
535
|
+
type1FlowOpen: false,
|
|
536
|
+
rawTextInline: false
|
|
512
537
|
};
|
|
513
538
|
}
|
|
514
539
|
function isPlausibleLinkDefRest(rest) {
|
|
@@ -653,8 +678,9 @@ function computeFreezeBoundary(text, options, resume) {
|
|
|
653
678
|
if (tailLine) return !canBecomeDdLine(tailLine.text, false);
|
|
654
679
|
return false;
|
|
655
680
|
};
|
|
681
|
+
const tailRetroactive = tailLine !== null && tailCarriesRetroactive(tailLine.text);
|
|
656
682
|
let boundary = 0;
|
|
657
|
-
for (let i = cp.candidates.length - 1; i >= 0; i--) {
|
|
683
|
+
for (let i = cp.candidates.length - 1; i >= 0 && !tailRetroactive; i--) {
|
|
658
684
|
const c = cp.candidates[i];
|
|
659
685
|
if (!c.htmlBalanced || c.hazard || c.seamRisk) continue;
|
|
660
686
|
if (c.offset > cp.phasePoisonedAt) continue;
|
|
@@ -738,8 +764,10 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
738
764
|
cp.rawTextOpen = null;
|
|
739
765
|
} else if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
|
|
740
766
|
cp.rawTextOpen = tag;
|
|
767
|
+
cp.rawTextInline = !cp.htmlFlowReal;
|
|
741
768
|
if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
742
769
|
}
|
|
770
|
+
if (DOCUMENT_STRUCTURE_NAMES.has(tag)) cp.phasePoisonedAt = 0;
|
|
743
771
|
if (closing) {
|
|
744
772
|
const count = cp.tagBalance.get(tag) ?? 0;
|
|
745
773
|
if (count > 0) {
|
|
@@ -850,15 +878,22 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
850
878
|
cp.candidates.push({
|
|
851
879
|
offset: Math.min(ln.end + 1, text.length),
|
|
852
880
|
blankRun: cp.blankRun,
|
|
853
|
-
|
|
881
|
+
// `type1FlowOpen`: an unterminated type-1 block swallows this blank
|
|
882
|
+
// and everything after it as RAW content, so nothing here is a block
|
|
883
|
+
// boundary at all. Its tags are invisible to the balance scan
|
|
884
|
+
// (`rawTextOpen` suppresses them), which is exactly why `openTotal`
|
|
885
|
+
// reads 0 and the candidate looked safe.
|
|
886
|
+
htmlBalanced: cp.openTotal === 0 && !cp.commentOpen && !cp.piOpen && !cp.declOpen && !cp.cdataOpen && !cp.bogusOpen && !cp.type1FlowOpen,
|
|
854
887
|
hazard: cp.hazardVerdict,
|
|
855
888
|
seamRisk: cp.htmlSeamPending,
|
|
856
889
|
defListSettled: null
|
|
857
890
|
});
|
|
858
891
|
cp.paragraphHasUnpairedRun = false;
|
|
859
892
|
cp.openBracket = null;
|
|
860
|
-
cp.
|
|
861
|
-
|
|
893
|
+
if (!cp.type1FlowOpen) {
|
|
894
|
+
cp.htmlFlowSinceBlank = false;
|
|
895
|
+
cp.htmlFlowReal = false;
|
|
896
|
+
}
|
|
862
897
|
cp.prevLineBlank = true;
|
|
863
898
|
cp.prevLineWasText = false;
|
|
864
899
|
cp.prevLineWasValidDef = false;
|
|
@@ -872,7 +907,9 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
872
907
|
}
|
|
873
908
|
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
|
|
874
909
|
if (tagStart) {
|
|
910
|
+
const noRealBlockOpen = !cp.htmlFlowReal;
|
|
875
911
|
cp.htmlFlowSinceBlank = true;
|
|
912
|
+
if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.type1FlowOpen = true;
|
|
876
913
|
if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
|
|
877
914
|
if (!cp.htmlFlowReal) {
|
|
878
915
|
const t = mdTrimStart(ln.text);
|
|
@@ -1023,6 +1060,7 @@ ${cont(scanText)}` };
|
|
|
1023
1060
|
pos = pi + 2;
|
|
1024
1061
|
} else {
|
|
1025
1062
|
rawSpans.push([decl, decl + 2]);
|
|
1063
|
+
if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
|
|
1026
1064
|
cp.declOpen = true;
|
|
1027
1065
|
pos = decl + 2;
|
|
1028
1066
|
}
|
|
@@ -1103,7 +1141,10 @@ ${cont(scanText)}` };
|
|
|
1103
1141
|
TAG_OR_COMMENT_RE.lastIndex = gt + 1;
|
|
1104
1142
|
}
|
|
1105
1143
|
}
|
|
1106
|
-
if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs))
|
|
1144
|
+
if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs)) {
|
|
1145
|
+
TAG_OR_COMMENT_RE.lastIndex = m.index + 2 + m[2].length;
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1107
1148
|
const selfClosing = /\/\s*$/.test(attrs);
|
|
1108
1149
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
1109
1150
|
applyTag(tag, closing);
|
|
@@ -1184,6 +1225,14 @@ ${cont(scanText)}` };
|
|
|
1184
1225
|
cp.htmlSeamPending = true;
|
|
1185
1226
|
}
|
|
1186
1227
|
}
|
|
1228
|
+
if (cp.rawTextOpen !== null && cp.rawTextInline) {
|
|
1229
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1230
|
+
}
|
|
1231
|
+
if (cp.type1FlowOpen && TYPE1_CLOSE_RE.test(ln.text)) {
|
|
1232
|
+
cp.type1FlowOpen = false;
|
|
1233
|
+
cp.htmlFlowSinceBlank = false;
|
|
1234
|
+
cp.htmlFlowReal = false;
|
|
1235
|
+
}
|
|
1187
1236
|
cp.blankRun = 0;
|
|
1188
1237
|
cp.prevLineBlank = false;
|
|
1189
1238
|
cp.prevLineWasText = true;
|
|
@@ -1199,6 +1248,15 @@ function isFootnoteSection(node) {
|
|
|
1199
1248
|
const props = node.properties;
|
|
1200
1249
|
return props?.dataFootnotes !== void 0;
|
|
1201
1250
|
}
|
|
1251
|
+
function isWhitespaceText(c) {
|
|
1252
|
+
return c.type === "text" && /^\s*$/.test(c.value);
|
|
1253
|
+
}
|
|
1254
|
+
function lastMeaningfulIdx(children) {
|
|
1255
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
1256
|
+
if (!isWhitespaceText(children[i])) return i;
|
|
1257
|
+
}
|
|
1258
|
+
return -1;
|
|
1259
|
+
}
|
|
1202
1260
|
|
|
1203
1261
|
// src/components/incrementalParse/attributeHastChildren.ts
|
|
1204
1262
|
function attributeHastChildren(mdast, hast, stopAt = Infinity) {
|
|
@@ -1981,16 +2039,6 @@ function isBackrefAnchor(c) {
|
|
|
1981
2039
|
if (el.tagName !== "a") return false;
|
|
1982
2040
|
return Boolean(el.properties && "dataFootnoteBackref" in el.properties);
|
|
1983
2041
|
}
|
|
1984
|
-
function isWhitespaceText(c) {
|
|
1985
|
-
if (c.type !== "text") return false;
|
|
1986
|
-
return /^\s*$/.test(c.value);
|
|
1987
|
-
}
|
|
1988
|
-
function lastMeaningfulIdx(children) {
|
|
1989
|
-
for (let i = children.length - 1; i >= 0; i--) {
|
|
1990
|
-
if (!isWhitespaceText(children[i])) return i;
|
|
1991
|
-
}
|
|
1992
|
-
return -1;
|
|
1993
|
-
}
|
|
1994
2042
|
function dropTrailingBackrefs(children) {
|
|
1995
2043
|
let trailingWsStart = children.length;
|
|
1996
2044
|
while (trailingWsStart > 0 && isWhitespaceText(children[trailingWsStart - 1])) {
|
|
@@ -4657,21 +4705,7 @@ function convertSingleToDoubleDollar(text) {
|
|
|
4657
4705
|
}
|
|
4658
4706
|
function preprocessLaTeX(str) {
|
|
4659
4707
|
if (!hasLatexTrigger(str)) return str;
|
|
4660
|
-
|
|
4661
|
-
const result = segments.map((segment) => {
|
|
4662
|
-
if (segment.isCode) return segment.text;
|
|
4663
|
-
let text = segment.text;
|
|
4664
|
-
text = escapeMhchemCommands(text);
|
|
4665
|
-
text = escapeCurrencyDollarSigns(text);
|
|
4666
|
-
text = convertLatexDelimiters(text);
|
|
4667
|
-
text = escapeLatexPipes(text);
|
|
4668
|
-
text = escapeLatexPipesInUnclosed(text);
|
|
4669
|
-
text = escapeTextUnderscores(text);
|
|
4670
|
-
text = convertSingleToDoubleDollar(text);
|
|
4671
|
-
text = truncateUnclosedLatexBlock(text);
|
|
4672
|
-
return text;
|
|
4673
|
-
});
|
|
4674
|
-
return result.join("");
|
|
4708
|
+
return processSlice(str, false).out;
|
|
4675
4709
|
}
|
|
4676
4710
|
function hasLatexTrigger(str) {
|
|
4677
4711
|
return str.includes("$") || str.includes("\\[") || str.includes("\\(");
|
|
@@ -4700,7 +4734,7 @@ function hasUnclosedTextCommand(text) {
|
|
|
4700
4734
|
}
|
|
4701
4735
|
var RESIDUAL_OPEN_BRACKET_RE = /(?<!!)\\\[/;
|
|
4702
4736
|
var LEADING_DOUBLE_DOLLAR_RE = /^\s*\$\$/;
|
|
4703
|
-
function
|
|
4737
|
+
function processSlice(slice, probe = true) {
|
|
4704
4738
|
const segments = splitByProtectedRegions(slice);
|
|
4705
4739
|
const parts = [];
|
|
4706
4740
|
let quiescent = true;
|
|
@@ -4824,13 +4858,13 @@ function createIncrementalLatexPreprocessor(options) {
|
|
|
4824
4858
|
};
|
|
4825
4859
|
const cut = findRawSafeCut(active);
|
|
4826
4860
|
if (cut > 0) {
|
|
4827
|
-
const candidate =
|
|
4861
|
+
const candidate = processSlice(active.slice(0, cut));
|
|
4828
4862
|
if (candidate.quiescent) freeze(cut, candidate);
|
|
4829
4863
|
}
|
|
4830
4864
|
nextAttemptLen = advanced || !backoff ? 0 : active.length * 2;
|
|
4831
4865
|
onAttempt?.({ activeLength, frozenBytes });
|
|
4832
4866
|
}
|
|
4833
|
-
const tail =
|
|
4867
|
+
const tail = processSlice(active, false);
|
|
4834
4868
|
const head = tail.truncatedAtSeamStart ? frozenOut.replace(/\s+$/, "") : frozenOut;
|
|
4835
4869
|
const out = head + tail.out;
|
|
4836
4870
|
prevSource = source;
|
|
@@ -4895,6 +4929,8 @@ function createRemendPreprocessor(options) {
|
|
|
4895
4929
|
hasLoneSurrogate,
|
|
4896
4930
|
highlight,
|
|
4897
4931
|
isFootnoteSection,
|
|
4932
|
+
isWhitespaceText,
|
|
4933
|
+
lastMeaningfulIdx,
|
|
4898
4934
|
measureStage,
|
|
4899
4935
|
mergeClassNameAllowlist,
|
|
4900
4936
|
normalizeForMatch,
|