@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.dev.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])) {
|
|
@@ -4578,21 +4624,7 @@ function convertSingleToDoubleDollar(text) {
|
|
|
4578
4624
|
}
|
|
4579
4625
|
function preprocessLaTeX(str) {
|
|
4580
4626
|
if (!hasLatexTrigger(str)) return str;
|
|
4581
|
-
|
|
4582
|
-
const result = segments.map((segment) => {
|
|
4583
|
-
if (segment.isCode) return segment.text;
|
|
4584
|
-
let text = segment.text;
|
|
4585
|
-
text = escapeMhchemCommands(text);
|
|
4586
|
-
text = escapeCurrencyDollarSigns(text);
|
|
4587
|
-
text = convertLatexDelimiters(text);
|
|
4588
|
-
text = escapeLatexPipes(text);
|
|
4589
|
-
text = escapeLatexPipesInUnclosed(text);
|
|
4590
|
-
text = escapeTextUnderscores(text);
|
|
4591
|
-
text = convertSingleToDoubleDollar(text);
|
|
4592
|
-
text = truncateUnclosedLatexBlock(text);
|
|
4593
|
-
return text;
|
|
4594
|
-
});
|
|
4595
|
-
return result.join("");
|
|
4627
|
+
return processSlice(str, false).out;
|
|
4596
4628
|
}
|
|
4597
4629
|
function hasLatexTrigger(str) {
|
|
4598
4630
|
return str.includes("$") || str.includes("\\[") || str.includes("\\(");
|
|
@@ -4621,7 +4653,7 @@ function hasUnclosedTextCommand(text) {
|
|
|
4621
4653
|
}
|
|
4622
4654
|
var RESIDUAL_OPEN_BRACKET_RE = /(?<!!)\\\[/;
|
|
4623
4655
|
var LEADING_DOUBLE_DOLLAR_RE = /^\s*\$\$/;
|
|
4624
|
-
function
|
|
4656
|
+
function processSlice(slice, probe = true) {
|
|
4625
4657
|
const segments = splitByProtectedRegions(slice);
|
|
4626
4658
|
const parts = [];
|
|
4627
4659
|
let quiescent = true;
|
|
@@ -4745,13 +4777,13 @@ function createIncrementalLatexPreprocessor(options) {
|
|
|
4745
4777
|
};
|
|
4746
4778
|
const cut = findRawSafeCut(active);
|
|
4747
4779
|
if (cut > 0) {
|
|
4748
|
-
const candidate =
|
|
4780
|
+
const candidate = processSlice(active.slice(0, cut));
|
|
4749
4781
|
if (candidate.quiescent) freeze(cut, candidate);
|
|
4750
4782
|
}
|
|
4751
4783
|
nextAttemptLen = advanced || !backoff ? 0 : active.length * 2;
|
|
4752
4784
|
onAttempt?.({ activeLength, frozenBytes });
|
|
4753
4785
|
}
|
|
4754
|
-
const tail =
|
|
4786
|
+
const tail = processSlice(active, false);
|
|
4755
4787
|
const head = tail.truncatedAtSeamStart ? frozenOut.replace(/\s+$/, "") : frozenOut;
|
|
4756
4788
|
const out = head + tail.out;
|
|
4757
4789
|
prevSource = source;
|
|
@@ -4815,6 +4847,8 @@ export {
|
|
|
4815
4847
|
hasLoneSurrogate,
|
|
4816
4848
|
highlight,
|
|
4817
4849
|
isFootnoteSection,
|
|
4850
|
+
isWhitespaceText,
|
|
4851
|
+
lastMeaningfulIdx,
|
|
4818
4852
|
measureStage,
|
|
4819
4853
|
mergeClassNameAllowlist,
|
|
4820
4854
|
normalizeForMatch,
|