stream-markdown-parser 0.0.48 → 0.0.50
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.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +116 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -313,6 +313,12 @@ interface ParseOptions {
|
|
|
313
313
|
preTransformTokens?: TransformTokensHook;
|
|
314
314
|
postTransformTokens?: TransformTokensHook;
|
|
315
315
|
requireClosingStrong?: boolean;
|
|
316
|
+
/**
|
|
317
|
+
* When true, indicates the input buffer is complete (end-of-stream).
|
|
318
|
+
* This disables "mid-state" streaming behavior (e.g. unclosed math/link/code
|
|
319
|
+
* tokens staying in a loading state) and keeps trailing markers as literal text.
|
|
320
|
+
*/
|
|
321
|
+
final?: boolean;
|
|
316
322
|
/**
|
|
317
323
|
* Custom HTML-like tag names that should be emitted as custom nodes
|
|
318
324
|
* instead of `html_inline` when encountered (e.g. ['thinking']).
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/factory.ts","../src/types.ts","../src/parser/inline-parsers/index.ts","../src/parser/index.ts","../src/config.ts","../src/findMatchingClose.ts","../src/parser/inline-parsers/fence-parser.ts","../src/plugins/containers.ts","../src/plugins/isMathLike.ts","../src/plugins/math.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,cAAA,SAAuB;sBAClB;;EADL,gBAAA,CAAe,EAAA,OAAA;;;;ECVf,CAAA;EAaL;AAEZ;AAMA;AAOA;EAMiB,cAAW,CAAA,EAAA,SAEhB,MAAA,EAAA;AAIZ;;;UAxCiB,QAAA;;EDUA,GAAA,EAAA,MAAA;;;;ACVjB;AAaA;AAEA;AAMA;AAOA;AAMA;AAMiB,KA3BL,WAAA,GAAc,QAgCjB,GAhC4B,MA2BH,CAAA,MAA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,QA2PA,CAAA;EAE1B,IAAA,EAAA,gBAAY;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/factory.ts","../src/types.ts","../src/parser/inline-parsers/index.ts","../src/parser/index.ts","../src/config.ts","../src/findMatchingClose.ts","../src/parser/inline-parsers/fence-parser.ts","../src/plugins/containers.ts","../src/plugins/isMathLike.ts","../src/plugins/math.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,cAAA,SAAuB;sBAClB;;EADL,gBAAA,CAAe,EAAA,OAAA;;;;ECVf,CAAA;EAaL;AAEZ;AAMA;AAOA;EAMiB,cAAW,CAAA,EAAA,SAEhB,MAAA,EAAA;AAIZ;;;UAxCiB,QAAA;;EDUA,GAAA,EAAA,MAAA;;;;ACVjB;AAaA;AAEA;AAMA;AAOA;AAMA;AAMiB,KA3BL,WAAA,GAAc,QAgCjB,GAhC4B,MA2BH,CAAA,MAAQ,EAAA,OAAA,CAAA;AAQzB,UAjCA,QAAA,SAAiB,QAmCtB,CAF0B;EAKrB,IAAA,EAAA,MAAA;EAiBA,OAAA,EAAA,MAAA;EAOA,MAAA,CAAA,EAAA,OAAA;AAYjB;AAYiB,UAhFA,WAAA,SAAoB,QAgFA,CAAA;EAK3B,IAAA,EAAA,SAAA;EACG,KAAA,EAAA,MAAA;EANgC,IAAA,EAAA,MAAA;EAAQ,QAAA,EA5EzC,UA4EyC,EAAA;AAUrD;AAKiB,UAxFA,aAAA,SAAsB,QAwFL,CAAQ;EAQzB,IAAA,EAAA,WAAU;EAOV,QAAA,EArGL,UAqGuB,EAAA;EAIlB,aAAA,CAAA,EAAA,OAAgB;AASjC;AASiB,UAvHA,UAAA,SAAmB,QAyHxB,CAF4B;EAKvB,IAAA,EAAA,QAAU;EAEjB,QAAA,EA5HE,UA4HF,EAAA;EACF,OAAA,CAAA,EAAA,MAAA;;AAHmC,UAtH1B,QAAA,SAAiB,QAsHS,CAAA;EAM1B,IAAA,EAAA,MAAA;EAKA,OAAA,EAA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,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EStD6B,kBTsD7B,CAAA,EStDoD,UTsDpD"}
|
package/dist/index.js
CHANGED
|
@@ -8498,6 +8498,7 @@ function applyMath(md, mathOpts) {
|
|
|
8498
8498
|
const mathInline = (state, silent) => {
|
|
8499
8499
|
const s = state;
|
|
8500
8500
|
const strict = !!mathOpts?.strictDelimiters;
|
|
8501
|
+
const allowLoading = !s?.env?.__markstreamFinal;
|
|
8501
8502
|
if (/^\*[^*]+/.test(s.src)) return false;
|
|
8502
8503
|
const delimiters = [["$", "$"], ["\\(", "\\)"]];
|
|
8503
8504
|
let searchPos = 0;
|
|
@@ -8505,6 +8506,9 @@ function applyMath(md, mathOpts) {
|
|
|
8505
8506
|
for (const [open, close] of delimiters) {
|
|
8506
8507
|
const src = s.src;
|
|
8507
8508
|
let foundAny = false;
|
|
8509
|
+
let lastIndex = -1;
|
|
8510
|
+
let lastSearchPos = -1;
|
|
8511
|
+
let stallCount = 0;
|
|
8508
8512
|
const pushText = (text$1) => {
|
|
8509
8513
|
if (text$1 === "undefined" || text$1 == null) text$1 = "";
|
|
8510
8514
|
if (text$1 === "\\") {
|
|
@@ -8530,6 +8534,17 @@ function applyMath(md, mathOpts) {
|
|
|
8530
8534
|
if (searchPos >= src.length) break;
|
|
8531
8535
|
const index = src.indexOf(open, searchPos);
|
|
8532
8536
|
if (index === -1) break;
|
|
8537
|
+
if (index === lastIndex && searchPos === lastSearchPos) {
|
|
8538
|
+
stallCount++;
|
|
8539
|
+
if (stallCount > 2) {
|
|
8540
|
+
searchPos = index + Math.max(1, open.length);
|
|
8541
|
+
continue;
|
|
8542
|
+
}
|
|
8543
|
+
} else {
|
|
8544
|
+
stallCount = 0;
|
|
8545
|
+
lastIndex = index;
|
|
8546
|
+
lastSearchPos = searchPos;
|
|
8547
|
+
}
|
|
8533
8548
|
if (index > 0) {
|
|
8534
8549
|
let i = index - 1;
|
|
8535
8550
|
while (i >= 0 && src[i] === " ") i--;
|
|
@@ -8543,7 +8558,7 @@ function applyMath(md, mathOpts) {
|
|
|
8543
8558
|
continue;
|
|
8544
8559
|
}
|
|
8545
8560
|
if (endIdx === -1) {
|
|
8546
|
-
if (!strict && isMathLike(content$1) && !content$1.includes("`")) {
|
|
8561
|
+
if (allowLoading && !strict && isMathLike(content$1) && !content$1.includes("`")) {
|
|
8547
8562
|
searchPos = index + open.length;
|
|
8548
8563
|
foundAny = true;
|
|
8549
8564
|
if (!silent) {
|
|
@@ -8584,7 +8599,8 @@ function applyMath(md, mathOpts) {
|
|
|
8584
8599
|
}
|
|
8585
8600
|
const content = src.slice(index + open.length, endIdx);
|
|
8586
8601
|
const hasBacktick = content.includes("`");
|
|
8587
|
-
|
|
8602
|
+
const isEmpty = !content || !content.trim();
|
|
8603
|
+
if (strict ? hasBacktick || isEmpty : hasBacktick || isEmpty || !(open === "$") && !isMathLike(content)) {
|
|
8588
8604
|
searchPos = endIdx + close.length;
|
|
8589
8605
|
const text$1 = src.slice(s.pos, searchPos);
|
|
8590
8606
|
if (!s.pending) pushText(text$1);
|
|
@@ -8619,14 +8635,11 @@ function applyMath(md, mathOpts) {
|
|
|
8619
8635
|
token.markup = open === "$$" ? "$$" : open === "\\(" ? "\\(\\)" : open === "$" ? "$" : "()";
|
|
8620
8636
|
token.raw = `${open}${content}${close}`;
|
|
8621
8637
|
token.loading = false;
|
|
8622
|
-
const
|
|
8623
|
-
const isBeforeClose = raw.startsWith(strongMarker);
|
|
8638
|
+
const isBeforeClose = src.slice(endIdx + close.length).startsWith(strongMarker);
|
|
8624
8639
|
if (isBeforeClose) s.push("strong_close", "", 0);
|
|
8625
|
-
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
preMathPos = searchPos;
|
|
8629
|
-
}
|
|
8640
|
+
s.pos = endIdx + close.length;
|
|
8641
|
+
searchPos = s.pos;
|
|
8642
|
+
preMathPos = searchPos;
|
|
8630
8643
|
if (!isBeforeClose) s.push("strong_close", "", 0);
|
|
8631
8644
|
continue;
|
|
8632
8645
|
} else {
|
|
@@ -8653,6 +8666,7 @@ function applyMath(md, mathOpts) {
|
|
|
8653
8666
|
};
|
|
8654
8667
|
const mathBlock = (state, startLine, endLine, silent) => {
|
|
8655
8668
|
const s = state;
|
|
8669
|
+
const allowLoading = !s?.env?.__markstreamFinal;
|
|
8656
8670
|
const strict = mathOpts?.strictDelimiters;
|
|
8657
8671
|
const delimiters = strict ? [["\\[", "\\]"], ["$$", "$$"]] : [
|
|
8658
8672
|
["\\[", "\\]"],
|
|
@@ -8760,7 +8774,7 @@ function applyMath(md, mathOpts) {
|
|
|
8760
8774
|
content += (content ? "\n" : "") + currentLine;
|
|
8761
8775
|
}
|
|
8762
8776
|
}
|
|
8763
|
-
if (strict && !found) return false;
|
|
8777
|
+
if ((!allowLoading || strict) && !found) return false;
|
|
8764
8778
|
if (!(openDelim === "[" ? isPlainBracketMathLike(content) : isMathLike(content))) return false;
|
|
8765
8779
|
const token = s.push("math_block", "math", 0);
|
|
8766
8780
|
token.content = normalizeStandaloneBackslashT(content);
|
|
@@ -11045,14 +11059,73 @@ function parseParagraph(tokens, index, options) {
|
|
|
11045
11059
|
//#endregion
|
|
11046
11060
|
//#region src/parser/index.ts
|
|
11047
11061
|
function stripDanglingHtmlLikeTail(markdown) {
|
|
11062
|
+
const isWs = (ch) => ch === " " || ch === " " || ch === "\n" || ch === "\r";
|
|
11063
|
+
const isLikelyHtmlTagPrefix = (tail$1) => {
|
|
11064
|
+
if (!tail$1 || tail$1[0] !== "<") return false;
|
|
11065
|
+
if (tail$1.includes(">")) return false;
|
|
11066
|
+
let i = 1;
|
|
11067
|
+
if (i < tail$1.length && isWs(tail$1[i])) return false;
|
|
11068
|
+
if (tail$1[i] === "/") {
|
|
11069
|
+
i++;
|
|
11070
|
+
if (i < tail$1.length && isWs(tail$1[i])) return false;
|
|
11071
|
+
}
|
|
11072
|
+
const isAlpha = (ch) => {
|
|
11073
|
+
const c = ch.charCodeAt(0);
|
|
11074
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
11075
|
+
};
|
|
11076
|
+
const isDigit = (ch) => {
|
|
11077
|
+
const c = ch.charCodeAt(0);
|
|
11078
|
+
return c >= 48 && c <= 57;
|
|
11079
|
+
};
|
|
11080
|
+
const isNameStart = (ch) => ch === "!" || isAlpha(ch);
|
|
11081
|
+
const isNameChar = (ch) => isAlpha(ch) || isDigit(ch) || ch === ":" || ch === "-";
|
|
11082
|
+
const isAttrStart = (ch) => isAlpha(ch) || isDigit(ch) || ch === "_" || ch === "." || ch === ":" || ch === "-";
|
|
11083
|
+
const isAttrChar = isAttrStart;
|
|
11084
|
+
if (i >= tail$1.length || !isNameStart(tail$1[i])) return false;
|
|
11085
|
+
i++;
|
|
11086
|
+
while (i < tail$1.length && isNameChar(tail$1[i])) i++;
|
|
11087
|
+
while (i < tail$1.length) {
|
|
11088
|
+
while (i < tail$1.length && isWs(tail$1[i])) i++;
|
|
11089
|
+
if (i >= tail$1.length) return true;
|
|
11090
|
+
if (tail$1[i] === "/") {
|
|
11091
|
+
i++;
|
|
11092
|
+
while (i < tail$1.length && isWs(tail$1[i])) i++;
|
|
11093
|
+
return i >= tail$1.length;
|
|
11094
|
+
}
|
|
11095
|
+
if (!isAttrStart(tail$1[i])) return false;
|
|
11096
|
+
i++;
|
|
11097
|
+
while (i < tail$1.length && isAttrChar(tail$1[i])) i++;
|
|
11098
|
+
while (i < tail$1.length && isWs(tail$1[i])) i++;
|
|
11099
|
+
if (i < tail$1.length && tail$1[i] === "=") {
|
|
11100
|
+
i++;
|
|
11101
|
+
while (i < tail$1.length && isWs(tail$1[i])) i++;
|
|
11102
|
+
if (i >= tail$1.length) return true;
|
|
11103
|
+
const quote = tail$1[i];
|
|
11104
|
+
if (quote === "\"" || quote === "'") {
|
|
11105
|
+
i++;
|
|
11106
|
+
while (i < tail$1.length && tail$1[i] !== quote) i++;
|
|
11107
|
+
if (i >= tail$1.length) return true;
|
|
11108
|
+
i++;
|
|
11109
|
+
} else {
|
|
11110
|
+
while (i < tail$1.length) {
|
|
11111
|
+
const ch = tail$1[i];
|
|
11112
|
+
if (isWs(ch) || ch === "<" || ch === ">" || ch === "\"" || ch === "'" || ch === "`") break;
|
|
11113
|
+
i++;
|
|
11114
|
+
}
|
|
11115
|
+
if (i >= tail$1.length) return true;
|
|
11116
|
+
}
|
|
11117
|
+
}
|
|
11118
|
+
}
|
|
11119
|
+
return true;
|
|
11120
|
+
};
|
|
11048
11121
|
const isInsideFencedCodeBlock = (src, pos) => {
|
|
11049
11122
|
let inFence = false;
|
|
11050
11123
|
let fenceChar = "";
|
|
11051
11124
|
let fenceLen = 0;
|
|
11052
|
-
const
|
|
11125
|
+
const isIndentWs = (ch) => ch === " " || ch === " ";
|
|
11053
11126
|
const parseFenceMarker = (line) => {
|
|
11054
11127
|
let i = 0;
|
|
11055
|
-
while (i < line.length &&
|
|
11128
|
+
while (i < line.length && isIndentWs(line[i])) i++;
|
|
11056
11129
|
const ch = line[i];
|
|
11057
11130
|
if (ch !== "`" && ch !== "~") return null;
|
|
11058
11131
|
let j = i;
|
|
@@ -11067,12 +11140,12 @@ function stripDanglingHtmlLikeTail(markdown) {
|
|
|
11067
11140
|
};
|
|
11068
11141
|
const stripBlockquotePrefix = (line) => {
|
|
11069
11142
|
let i = 0;
|
|
11070
|
-
while (i < line.length &&
|
|
11143
|
+
while (i < line.length && isIndentWs(line[i])) i++;
|
|
11071
11144
|
let saw = false;
|
|
11072
11145
|
while (i < line.length && line[i] === ">") {
|
|
11073
11146
|
saw = true;
|
|
11074
11147
|
i++;
|
|
11075
|
-
while (i < line.length &&
|
|
11148
|
+
while (i < line.length && isIndentWs(line[i])) i++;
|
|
11076
11149
|
}
|
|
11077
11150
|
return saw ? line.slice(i) : null;
|
|
11078
11151
|
};
|
|
@@ -11116,25 +11189,35 @@ function stripDanglingHtmlLikeTail(markdown) {
|
|
|
11116
11189
|
const lastLt = s.lastIndexOf("<");
|
|
11117
11190
|
if (lastLt === -1) return s;
|
|
11118
11191
|
if (isInsideFencedCodeBlock(s, lastLt)) return s;
|
|
11192
|
+
if (lastLt > 0) {
|
|
11193
|
+
const prev = s[lastLt - 1];
|
|
11194
|
+
const prevIsWs = prev === " " || prev === " " || prev === "\n" || prev === "\r";
|
|
11195
|
+
const prev2 = s[lastLt - 2];
|
|
11196
|
+
if (!prevIsWs && !((prev === "n" || prev === "r") && prev2 === "\\")) return s;
|
|
11197
|
+
}
|
|
11119
11198
|
const tail = s.slice(lastLt);
|
|
11120
11199
|
if (tail.includes(">")) return s;
|
|
11121
|
-
if (
|
|
11200
|
+
if (tail.length > 1 && (tail[1] === " " || tail[1] === " " || tail[1] === "\n" || tail[1] === "\r")) return s;
|
|
11201
|
+
if (!isLikelyHtmlTagPrefix(tail)) return s;
|
|
11122
11202
|
return s.slice(0, lastLt);
|
|
11123
11203
|
}
|
|
11124
11204
|
function parseMarkdownToStructure(markdown, md, options = {}) {
|
|
11205
|
+
const isFinal = !!options.final;
|
|
11125
11206
|
let safeMarkdown = (markdown ?? "").toString().replace(/([^\\])\r(ight|ho)/g, "$1\\r$2").replace(/([^\\])\n(abla|eq|ot|exists)/g, "$1\\n$2");
|
|
11126
|
-
if (
|
|
11127
|
-
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
|
|
11133
|
-
|
|
11134
|
-
|
|
11135
|
-
|
|
11136
|
-
|
|
11137
|
-
|
|
11207
|
+
if (!isFinal) {
|
|
11208
|
+
if (safeMarkdown.endsWith("- *")) safeMarkdown = safeMarkdown.replace(/- \*$/, "- \\*");
|
|
11209
|
+
if (/(?:^|\n)\s*-\s*$/.test(safeMarkdown)) safeMarkdown = safeMarkdown.replace(/(?:^|\n)\s*-\s*$/, (m) => {
|
|
11210
|
+
return m.startsWith("\n") ? "\n" : "";
|
|
11211
|
+
});
|
|
11212
|
+
else if (/(?:^|\n)\s*--\s*$/.test(safeMarkdown)) safeMarkdown = safeMarkdown.replace(/(?:^|\n)\s*--\s*$/, (m) => {
|
|
11213
|
+
return m.startsWith("\n") ? "\n" : "";
|
|
11214
|
+
});
|
|
11215
|
+
else if (/(?:^|\n)\s*>\s*$/.test(safeMarkdown)) safeMarkdown = safeMarkdown.replace(/(?:^|\n)\s*>\s*$/, (m) => {
|
|
11216
|
+
return m.startsWith("\n") ? "\n" : "";
|
|
11217
|
+
});
|
|
11218
|
+
else if (/\n\s*[*+]\s*$/.test(safeMarkdown)) safeMarkdown = safeMarkdown.replace(/\n\s*[*+]\s*$/, "\n");
|
|
11219
|
+
else if (/\n[[(]\n*$/.test(safeMarkdown)) safeMarkdown = safeMarkdown.replace(/(\n\[|\n\()+\n*$/g, "\n");
|
|
11220
|
+
}
|
|
11138
11221
|
if (options.customHtmlTags?.length) {
|
|
11139
11222
|
const tags = options.customHtmlTags.map((t) => String(t ?? "").trim()).filter(Boolean).map((t) => {
|
|
11140
11223
|
return (t.match(/^[<\s/]*([A-Z][\w-]*)/i)?.[1] ?? "").toLowerCase();
|
|
@@ -11144,8 +11227,8 @@ function parseMarkdownToStructure(markdown, md, options = {}) {
|
|
|
11144
11227
|
safeMarkdown = safeMarkdown.replace(re, "$1$2$2");
|
|
11145
11228
|
}
|
|
11146
11229
|
}
|
|
11147
|
-
safeMarkdown = stripDanglingHtmlLikeTail(safeMarkdown);
|
|
11148
|
-
const tokens = md.parse(safeMarkdown, {});
|
|
11230
|
+
if (!isFinal) safeMarkdown = stripDanglingHtmlLikeTail(safeMarkdown);
|
|
11231
|
+
const tokens = md.parse(safeMarkdown, { __markstreamFinal: isFinal });
|
|
11149
11232
|
if (!tokens || !Array.isArray(tokens)) return [];
|
|
11150
11233
|
const pre = options.preTransformTokens;
|
|
11151
11234
|
const post = options.postTransformTokens;
|
|
@@ -11290,7 +11373,9 @@ function getMarkdown(msgId = `editor-${Date.now()}`, options = {}) {
|
|
|
11290
11373
|
md.use(footnote_plugin);
|
|
11291
11374
|
md.core.ruler.after("block", "mark_fence_closed", (state) => {
|
|
11292
11375
|
const s = state;
|
|
11293
|
-
const
|
|
11376
|
+
const src = s.src;
|
|
11377
|
+
const envFinal = !!s.env?.__markstreamFinal;
|
|
11378
|
+
const lines = src.split(/\r?\n/);
|
|
11294
11379
|
for (const token of s.tokens) {
|
|
11295
11380
|
if (token.type !== "fence" || !token.map || !token.markup) continue;
|
|
11296
11381
|
const openLine = token.map[0];
|
|
@@ -11305,7 +11390,7 @@ function getMarkdown(msgId = `editor-${Date.now()}`, options = {}) {
|
|
|
11305
11390
|
while (i + count < line.length && line[i + count] === marker) count++;
|
|
11306
11391
|
let j = i + count;
|
|
11307
11392
|
while (j < line.length && (line[j] === " " || line[j] === " ")) j++;
|
|
11308
|
-
const closed = endLine > openLine + 1 && count >= minLen && j === line.length;
|
|
11393
|
+
const closed = envFinal ? true : endLine > openLine + 1 && count >= minLen && j === line.length;
|
|
11309
11394
|
const tokenShape = token;
|
|
11310
11395
|
tokenShape.meta = tokenShape.meta ?? {};
|
|
11311
11396
|
tokenShape.meta.unclosed = !closed;
|