stream-markdown-parser 0.0.18 → 0.0.20
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.map +1 -1
- package/dist/index.js +147 -132
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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":";;;UAaiB,cAAA,SAAuB;sBAClB;;EADL,gBAAA,CAAe,EAAA,OAAA;;;;ECXf,CAAA;AAQjB;;;UARiB,QAAA;;EDWA,GAAA,EAAA,MAAA;;;;ACXjB;AAQiB,UAAA,QAAA,SAAiB,QAAQ,CAAA;EAMzB,IAAA,EAAA,MAAA;EAOA,OAAA,EAAA,MAAA;EAMA,MAAA,CAAA,EAAA,OAAW;AAM5B;AAQiB,UA3BA,WAAA,SAAoB,QA2BC,CAAA;EAKrB,IAAA,EAAA,SAAA;EAiBA,KAAA,EAAA,MAAA;EAOA,IAAA,EAAA,MAAA;EAMA,QAAA,EA1DL,UA0DoB,EAAA;AAKhC;AAQiB,UApEA,aAAA,SAAsB,QAoEI,CAAA;EAO1B,IAAA,EAAA,WAAA;EAIA,QAAA,EA7EL,UA6EqB,EAAA;EASrB,aAAA,CAAA,EAAA,OAAc;AAS1B;AAKiB,UAhGA,UAAA,SAAmB,QAgGT,CAAA;EAEjB,IAAA,EAAA,QAAA;EACF,QAAA,EAjGI,UAiGJ,EAAA;EAH2B,OAAA,CAAA,EAAA,MAAA;;AAMlB,UAhGA,QAAA,SAAiB,QAkGzB,CAAA;EAGQ,IAAA,EAAA,MAAA;EAMA,OAAA,EAAA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AAEA,UA3LW,iBAAA,SAA0B,QA2LrC,CAAA;EACA,IAAA,EAAA,gBAAA;;AAEA,UA1LW,gBAAA,CA0LX;EACA,IAAA,EAAA;IACA,IAAA,EAAA,YAAA;IACA,QAAA,EAAA,MAAA;IACA,IAAA,EAAA,MAAA;IACA,OAAA,CAAA,EAAA,OAAA;EACA,CAAA;;AAEA,KAzLM,cAAA,GAyLN;EACA,OAAA,EAAA,MAAA;EAAM,KAAA,CAAA,EAAA,SAAA;AACZ,CAAA,GAAiB;EAkCL,OAAA,CAAA,EAAA,SAAA;EAEK,KAAA,EAxNN,QAwNkB,EAAA;AAK7B,CAAA;UA3NiB,cAAA,SAAuB;;YAE5B;
|
|
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":";;;UAaiB,cAAA,SAAuB;sBAClB;;EADL,gBAAA,CAAe,EAAA,OAAA;;;;ECXf,CAAA;AAQjB;;;UARiB,QAAA;;EDWA,GAAA,EAAA,MAAA;;;;ACXjB;AAQiB,UAAA,QAAA,SAAiB,QAAQ,CAAA;EAMzB,IAAA,EAAA,MAAA;EAOA,OAAA,EAAA,MAAA;EAMA,MAAA,CAAA,EAAA,OAAW;AAM5B;AAQiB,UA3BA,WAAA,SAAoB,QA2BC,CAAA;EAKrB,IAAA,EAAA,SAAA;EAiBA,KAAA,EAAA,MAAA;EAOA,IAAA,EAAA,MAAA;EAMA,QAAA,EA1DL,UA0DoB,EAAA;AAKhC;AAQiB,UApEA,aAAA,SAAsB,QAoEI,CAAA;EAO1B,IAAA,EAAA,WAAA;EAIA,QAAA,EA7EL,UA6EqB,EAAA;EASrB,aAAA,CAAA,EAAA,OAAc;AAS1B;AAKiB,UAhGA,UAA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AAA;iBGiE9B,aAAA,SAAsB,kBAAkB;;;;;;AHjExD;;;;ACXA;AAQA;AAMiB,UGPA,WAAA,CHWL;EAGK;EAMA,QAAA,CAAA,EAAA,SAAW,MAEhB,EAAA;EAIK;EAQA,iBAAa,CAAA,EAAA,OAElB;AAGZ;AAiBiB,iBG/CD,qBAAA,CH+C+B,IAAA,EG/CH,WH+CG,GAAA,SAAA,CAAA,EAAA,IAAA;;;iBIjE/B,iBAAA;;;iBCoCA,eAAA,QAAuB,gBAAgB;;;iBCjCvC,eAAA,KAAoB;;;cCHvB;cAqBA;iBAuBG,UAAA;;;cC3BH;iBAuIG,6BAAA,mBAAgD;iBA4ChD,SAAA,KAAc,yBAAuB;;;ARjKpC,USCA,kBAAA,SAA2B,cTDF,CAAA;EAQzB,MAAA,CAAA,ESNN,KTMM,CAAa,OAAA,CAAA;EAKb,KAAA,CAAA,ESVP,KTUO,CAAA,CAAA,EAAc,ESVV,YTUkB,EAAA,GAAA,IAAQ,CAAA;EAiB9B;AAOjB;AAMA;AAKA;EAQiB,IAAA,CAAA,EAAA,CAAA,CAAA,GAAU,EAAA,MAAA,EAAA,GAAQ,MAAA,CAAA,GShDE,MTgDM,CAAA,MAAA,EAAA,MAAA,CAAA;AAO3C;AAIiB,iBSxDD,WAAA,CTwDiB,KAAA,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,ESxD4C,kBTwD5C,CAAA,ESxDmE,YTwDnE"}
|
package/dist/index.js
CHANGED
|
@@ -77,25 +77,25 @@ function applyContainers(md) {
|
|
|
77
77
|
|
|
78
78
|
//#endregion
|
|
79
79
|
//#region src/plugins/fixHtmlInline.ts
|
|
80
|
+
const VOID_TAGS$1 = new Set([
|
|
81
|
+
"area",
|
|
82
|
+
"base",
|
|
83
|
+
"br",
|
|
84
|
+
"col",
|
|
85
|
+
"embed",
|
|
86
|
+
"hr",
|
|
87
|
+
"img",
|
|
88
|
+
"input",
|
|
89
|
+
"link",
|
|
90
|
+
"meta",
|
|
91
|
+
"param",
|
|
92
|
+
"source",
|
|
93
|
+
"track",
|
|
94
|
+
"wbr"
|
|
95
|
+
]);
|
|
80
96
|
function applyFixHtmlInlineTokens(md) {
|
|
81
97
|
md.core.ruler.push("fix_html_inline_tokens", (state) => {
|
|
82
98
|
const toks = state.tokens ?? [];
|
|
83
|
-
const VOID_TAGS = new Set([
|
|
84
|
-
"area",
|
|
85
|
-
"base",
|
|
86
|
-
"br",
|
|
87
|
-
"col",
|
|
88
|
-
"embed",
|
|
89
|
-
"hr",
|
|
90
|
-
"img",
|
|
91
|
-
"input",
|
|
92
|
-
"link",
|
|
93
|
-
"meta",
|
|
94
|
-
"param",
|
|
95
|
-
"source",
|
|
96
|
-
"track",
|
|
97
|
-
"wbr"
|
|
98
|
-
]);
|
|
99
99
|
for (let i = 0; i < toks.length; i++) {
|
|
100
100
|
const t = toks[i];
|
|
101
101
|
if (!t || t.type !== "inline") continue;
|
|
@@ -116,7 +116,7 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
116
116
|
const raw = String(t.content);
|
|
117
117
|
const tagName = raw.match(/<([^\s>/]+)/)?.[1]?.toLowerCase() ?? "";
|
|
118
118
|
if (!tagName) continue;
|
|
119
|
-
const isVoid = /\/\s*>\s*$/.test(raw) || VOID_TAGS.has(tagName);
|
|
119
|
+
const isVoid = /\/\s*>\s*$/.test(raw) || VOID_TAGS$1.has(tagName);
|
|
120
120
|
const htmlToken = t;
|
|
121
121
|
if (isVoid) {
|
|
122
122
|
htmlToken.children = [{
|
|
@@ -132,6 +132,7 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
132
132
|
|
|
133
133
|
//#endregion
|
|
134
134
|
//#region src/plugins/fixLinkInline.ts
|
|
135
|
+
const LINK_PREFIX_RE = /^\[([^\]]*)\]\(([^)\s]*)/;
|
|
135
136
|
function applyFixLinkInline(md) {
|
|
136
137
|
const rule = (state, silent) => {
|
|
137
138
|
const s = state;
|
|
@@ -139,7 +140,7 @@ function applyFixLinkInline(md) {
|
|
|
139
140
|
if (s.src[start] !== "[") return false;
|
|
140
141
|
if (start > 0 && s.src[start - 1] === "!") return false;
|
|
141
142
|
const rest = s.src.slice(start);
|
|
142
|
-
const m =
|
|
143
|
+
const m = LINK_PREFIX_RE.exec(rest);
|
|
143
144
|
if (!m) return false;
|
|
144
145
|
if (silent) return true;
|
|
145
146
|
const text = m[1] ?? "";
|
|
@@ -360,7 +361,42 @@ function fixStrongTokens(tokens) {
|
|
|
360
361
|
const token = tokens[i];
|
|
361
362
|
const nextToken = tokens[i + 1];
|
|
362
363
|
const tokenContent = String(token.content ?? "");
|
|
363
|
-
if (token.type === "
|
|
364
|
+
if (token.type === "link_open" && tokens[i - 1].type === "em_open" && tokens[i - 2].type === "text" && tokens[i - 2].content?.endsWith("*")) {
|
|
365
|
+
const textContent = String(tokens[i - 2].content ?? "").slice(0, -1);
|
|
366
|
+
const replaceTokens = [
|
|
367
|
+
{
|
|
368
|
+
type: "strong_open",
|
|
369
|
+
tag: "strong",
|
|
370
|
+
attrs: null,
|
|
371
|
+
map: null,
|
|
372
|
+
children: null,
|
|
373
|
+
content: "",
|
|
374
|
+
markup: "**",
|
|
375
|
+
info: "",
|
|
376
|
+
meta: null
|
|
377
|
+
},
|
|
378
|
+
tokens[i],
|
|
379
|
+
tokens[i + 1],
|
|
380
|
+
tokens[i + 2],
|
|
381
|
+
{
|
|
382
|
+
type: "strong_close",
|
|
383
|
+
tag: "strong",
|
|
384
|
+
attrs: null,
|
|
385
|
+
map: null,
|
|
386
|
+
children: null,
|
|
387
|
+
content: "",
|
|
388
|
+
markup: "**",
|
|
389
|
+
info: "",
|
|
390
|
+
meta: null
|
|
391
|
+
}
|
|
392
|
+
];
|
|
393
|
+
if (textContent) replaceTokens.unshift({
|
|
394
|
+
type: "text",
|
|
395
|
+
content: textContent,
|
|
396
|
+
raw: textContent
|
|
397
|
+
});
|
|
398
|
+
fixedTokens.splice(i - 2, 6, ...replaceTokens);
|
|
399
|
+
} else if (token.type === "text" && tokenContent.endsWith("*") && nextToken.type === "em_open") {
|
|
364
400
|
const _nextToken = tokens[i + 2];
|
|
365
401
|
const count = _nextToken?.type === "text" ? 4 : 3;
|
|
366
402
|
const insert = [
|
|
@@ -602,37 +638,6 @@ function findMatchingClose(src, startIdx, open, close) {
|
|
|
602
638
|
}
|
|
603
639
|
var findMatchingClose_default = findMatchingClose;
|
|
604
640
|
|
|
605
|
-
//#endregion
|
|
606
|
-
//#region src/utils/lru.ts
|
|
607
|
-
var LRUCache = class {
|
|
608
|
-
constructor(max = 500) {
|
|
609
|
-
this.max = max;
|
|
610
|
-
this.map = /* @__PURE__ */ new Map();
|
|
611
|
-
}
|
|
612
|
-
get(key) {
|
|
613
|
-
if (!this.map.has(key)) return void 0;
|
|
614
|
-
const val = this.map.get(key);
|
|
615
|
-
this.map.delete(key);
|
|
616
|
-
this.map.set(key, val);
|
|
617
|
-
return val;
|
|
618
|
-
}
|
|
619
|
-
set(key, value) {
|
|
620
|
-
if (this.map.has(key)) this.map.delete(key);
|
|
621
|
-
this.map.set(key, value);
|
|
622
|
-
if (this.map.size > this.max) {
|
|
623
|
-
const firstKey = this.map.keys().next().value;
|
|
624
|
-
if (firstKey !== void 0) this.map.delete(firstKey);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
getOrCreate(key, factory$1) {
|
|
628
|
-
const existing = this.get(key);
|
|
629
|
-
if (existing !== void 0) return existing;
|
|
630
|
-
const v = factory$1();
|
|
631
|
-
this.set(key, v);
|
|
632
|
-
return v;
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
|
|
636
641
|
//#endregion
|
|
637
642
|
//#region src/plugins/isMathLike.ts
|
|
638
643
|
const TEX_BRACE_COMMANDS = [
|
|
@@ -744,6 +749,36 @@ const KATEX_COMMANDS = [
|
|
|
744
749
|
];
|
|
745
750
|
const ESCAPED_KATEX_COMMANDS = KATEX_COMMANDS.slice().sort((a, b) => b.length - a.length).map((c) => c.replace(/[.*+?^${}()|[\\]\\\]/g, "\\$&")).join("|");
|
|
746
751
|
const CONTROL_CHARS_CLASS = "[ \r\b\f\v]";
|
|
752
|
+
const SPAN_CURLY_RE = /span\{([^}]+)\}/;
|
|
753
|
+
const OPERATORNAME_SPAN_RE = /\\operatorname\{span\}\{((?:[^{}]|\{[^}]*\})+)\}/;
|
|
754
|
+
const SINGLE_BACKSLASH_NEWLINE_RE = /(^|[^\\])\\\r?\n/g;
|
|
755
|
+
const ENDING_SINGLE_BACKSLASH_RE = /(^|[^\\])\\$/g;
|
|
756
|
+
const DEFAULT_MATH_RE = new RegExp(`${CONTROL_CHARS_CLASS}|(?<!\\\\|\\w)(${ESCAPED_KATEX_COMMANDS})\\b`, "g");
|
|
757
|
+
const MATH_RE_CACHE = /* @__PURE__ */ new Map();
|
|
758
|
+
const BRACE_CMD_RE_CACHE = /* @__PURE__ */ new Map();
|
|
759
|
+
function getMathRegex(commands) {
|
|
760
|
+
if (!commands) return DEFAULT_MATH_RE;
|
|
761
|
+
const arr = [...commands];
|
|
762
|
+
arr.sort((a, b) => b.length - a.length);
|
|
763
|
+
const key = arr.join("");
|
|
764
|
+
const cached = MATH_RE_CACHE.get(key);
|
|
765
|
+
if (cached) return cached;
|
|
766
|
+
const commandPattern = `(?:${arr.map((c) => c.replace(/[.*+?^${}()|[\\]\\"\]/g, "\\$&")).join("|")})`;
|
|
767
|
+
const re = new RegExp(`${CONTROL_CHARS_CLASS}|(?<!\\\\|\\w)(${commandPattern})\\b`, "g");
|
|
768
|
+
MATH_RE_CACHE.set(key, re);
|
|
769
|
+
return re;
|
|
770
|
+
}
|
|
771
|
+
function getBraceCmdRegex(useDefault, commands) {
|
|
772
|
+
const arr = useDefault ? [] : [...commands ?? []];
|
|
773
|
+
if (!useDefault) arr.sort((a, b) => b.length - a.length);
|
|
774
|
+
const key = useDefault ? "__default__" : arr.join("");
|
|
775
|
+
const cached = BRACE_CMD_RE_CACHE.get(key);
|
|
776
|
+
if (cached) return cached;
|
|
777
|
+
const braceEscaped = useDefault ? [ESCAPED_TEX_BRACE_COMMANDS, ESCAPED_KATEX_COMMANDS].filter(Boolean).join("|") : [arr.map((c) => c.replace(/[.*+?^${}()|[\\]\\\]/g, "\\$&")).join("|"), ESCAPED_TEX_BRACE_COMMANDS].filter(Boolean).join("|");
|
|
778
|
+
const re = new RegExp(`(^|[^\\\\\\w])(${braceEscaped})\\s*\\{`, "g");
|
|
779
|
+
BRACE_CMD_RE_CACHE.set(key, re);
|
|
780
|
+
return re;
|
|
781
|
+
}
|
|
747
782
|
const CONTROL_MAP = {
|
|
748
783
|
" ": "t",
|
|
749
784
|
"\r": "r",
|
|
@@ -751,13 +786,6 @@ const CONTROL_MAP = {
|
|
|
751
786
|
"\f": "f",
|
|
752
787
|
"\v": "v"
|
|
753
788
|
};
|
|
754
|
-
const DEFAULT_STANDALONE_BACKSLASH_T_RE = new RegExp(`${CONTROL_CHARS_CLASS}|(?<!\\\\|\\w)(${ESCAPED_KATEX_COMMANDS})\\b`, "g");
|
|
755
|
-
const DEFAULT_BRACE_CMD_RE = (() => {
|
|
756
|
-
const combined = [ESCAPED_TEX_BRACE_COMMANDS, ESCAPED_KATEX_COMMANDS].filter(Boolean).join("|");
|
|
757
|
-
return combined ? new RegExp(`(^|[^\\\\\\w])(${combined})\\s*\\{`, "g") : null;
|
|
758
|
-
})();
|
|
759
|
-
const commandsRegexCache = new LRUCache(500);
|
|
760
|
-
const braceCmdRegexCache = new LRUCache(500);
|
|
761
789
|
function countUnescapedStrong(s) {
|
|
762
790
|
const re = /(^|[^\\])(__|\*\*)/g;
|
|
763
791
|
let c = 0;
|
|
@@ -768,41 +796,19 @@ function normalizeStandaloneBackslashT(s, opts) {
|
|
|
768
796
|
const commands = opts?.commands ?? KATEX_COMMANDS;
|
|
769
797
|
const escapeExclamation = opts?.escapeExclamation ?? true;
|
|
770
798
|
const useDefault = opts?.commands == null;
|
|
771
|
-
|
|
772
|
-
if (useDefault) re = DEFAULT_STANDALONE_BACKSLASH_T_RE;
|
|
773
|
-
else {
|
|
774
|
-
const key = commands.slice().sort((a, b) => b.length - a.length).join("|");
|
|
775
|
-
re = commandsRegexCache.getOrCreate(key, () => {
|
|
776
|
-
const commandPattern = `(?:${commands.slice().sort((a, b) => b.length - a.length).map((c) => c.replace(/[.*+?^${}()|[\\]\\"\\\]/g, "\\$&")).join("|")})`;
|
|
777
|
-
return new RegExp(`${CONTROL_CHARS_CLASS}|(?<!\\\\|\\w)(${commandPattern})\\b`, "g");
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
if (re && "lastIndex" in re) re.lastIndex = 0;
|
|
799
|
+
const re = getMathRegex(useDefault ? void 0 : commands);
|
|
781
800
|
let out = s.replace(re, (m, cmd) => {
|
|
782
801
|
if (CONTROL_MAP[m] !== void 0) return `\\${CONTROL_MAP[m]}`;
|
|
783
802
|
if (cmd && commands.includes(cmd)) return `\\${cmd}`;
|
|
784
803
|
return m;
|
|
785
804
|
});
|
|
786
805
|
if (escapeExclamation) out = out.replace(/(^|[^\\])!/g, "$1\\!");
|
|
787
|
-
const braceEscaped = useDefault ? [ESCAPED_TEX_BRACE_COMMANDS, ESCAPED_KATEX_COMMANDS].filter(Boolean).join("|") : [commands.map((c) => c.replace(/[.*+?^${}()|[\\]\\\]/g, "\\$&")).join("|"), ESCAPED_TEX_BRACE_COMMANDS].filter(Boolean).join("|");
|
|
788
806
|
let result = out;
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const combined = [commands.map((c) => c.replace(/[.*+?^${}()|[\\]\\"\]/g, "\\$&")).join("|"), ESCAPED_TEX_BRACE_COMMANDS].filter(Boolean).join("|");
|
|
795
|
-
if (combined) braceCmdRe = braceCmdRegexCache.getOrCreate(key, () => new RegExp(`(^|[^\\\\\\w])(${combined})\\s*\\{`, "g"));
|
|
796
|
-
else braceCmdRe = null;
|
|
797
|
-
}
|
|
798
|
-
if (braceCmdRe) {
|
|
799
|
-
if ("lastIndex" in braceCmdRe) braceCmdRe.lastIndex = 0;
|
|
800
|
-
result = result.replace(braceCmdRe, (_m, p1, p2) => `${p1}\\${p2}{`);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
result = result.replace(/span\{([^}]+)\}/, "span\\{$1\\}").replace(/\\operatorname\{span\}\{((?:[^{}]|\{[^}]*\})+)\}/, "\\operatorname{span}\\{$1\\}");
|
|
804
|
-
result = result.replace(/(^|[^\\])\\\r?\n/g, "$1\\\\\n");
|
|
805
|
-
result = result.replace(/(^|[^\\])\\$/g, "$1\\\\");
|
|
807
|
+
const braceCmdRe = getBraceCmdRegex(useDefault, useDefault ? void 0 : commands);
|
|
808
|
+
result = result.replace(braceCmdRe, (_m, p1, p2) => `${p1}\\${p2}{`);
|
|
809
|
+
result = result.replace(SPAN_CURLY_RE, "span\\{$1\\}").replace(OPERATORNAME_SPAN_RE, "\\operatorname{span}\\{$1\\}");
|
|
810
|
+
result = result.replace(SINGLE_BACKSLASH_NEWLINE_RE, "$1\\\\\n");
|
|
811
|
+
result = result.replace(ENDING_SINGLE_BACKSLASH_RE, "$1\\\\");
|
|
806
812
|
return result;
|
|
807
813
|
}
|
|
808
814
|
function applyMath(md, mathOpts) {
|
|
@@ -1155,14 +1161,23 @@ function parseEmphasisToken(tokens, startIndex) {
|
|
|
1155
1161
|
|
|
1156
1162
|
//#endregion
|
|
1157
1163
|
//#region src/parser/inline-parsers/fence-parser.ts
|
|
1164
|
+
const TRAILING_FENCE_LINE_RE = /\r?\n[ \t]*`+\s*$/;
|
|
1165
|
+
const DIFF_HEADER_PREFIXES = [
|
|
1166
|
+
"diff ",
|
|
1167
|
+
"index ",
|
|
1168
|
+
"--- ",
|
|
1169
|
+
"+++ ",
|
|
1170
|
+
"@@ "
|
|
1171
|
+
];
|
|
1172
|
+
const NEWLINE_RE = /\r?\n/;
|
|
1158
1173
|
function splitUnifiedDiff(content) {
|
|
1159
1174
|
const orig = [];
|
|
1160
1175
|
const updated = [];
|
|
1161
|
-
for (const rawLine of content.split(
|
|
1176
|
+
for (const rawLine of content.split(NEWLINE_RE)) {
|
|
1162
1177
|
const line = rawLine;
|
|
1163
|
-
if (
|
|
1164
|
-
if (line.
|
|
1165
|
-
else if (line.
|
|
1178
|
+
if (DIFF_HEADER_PREFIXES.some((p) => line.startsWith(p))) continue;
|
|
1179
|
+
if (line.length >= 2 && line[0] === "-" && line[1] === " ") orig.push(` ${line.slice(1)}`);
|
|
1180
|
+
else if (line.length >= 2 && line[0] === "+" && line[1] === " ") updated.push(` ${line.slice(1)}`);
|
|
1166
1181
|
else {
|
|
1167
1182
|
orig.push(line);
|
|
1168
1183
|
updated.push(line);
|
|
@@ -1179,10 +1194,13 @@ function parseFenceToken(token) {
|
|
|
1179
1194
|
const closed = typeof tokenMeta.closed === "boolean" ? tokenMeta.closed : void 0;
|
|
1180
1195
|
const info = String(token.info ?? "");
|
|
1181
1196
|
const diff = info.startsWith("diff");
|
|
1182
|
-
const language = diff ?
|
|
1197
|
+
const language = diff ? (() => {
|
|
1198
|
+
const s = info;
|
|
1199
|
+
const sp = s.indexOf(" ");
|
|
1200
|
+
return sp === -1 ? "" : String(s.slice(sp + 1) ?? "");
|
|
1201
|
+
})() : info;
|
|
1183
1202
|
let content = String(token.content ?? "");
|
|
1184
|
-
|
|
1185
|
-
if (trailingFenceLine.test(content)) content = content.replace(trailingFenceLine, "");
|
|
1203
|
+
if (TRAILING_FENCE_LINE_RE.test(content)) content = content.replace(TRAILING_FENCE_LINE_RE, "");
|
|
1186
1204
|
if (diff) {
|
|
1187
1205
|
const { original, updated } = splitUnifiedDiff(content);
|
|
1188
1206
|
return {
|
|
@@ -1385,11 +1403,12 @@ function parseLinkToken(tokens, startIndex) {
|
|
|
1385
1403
|
const title = _title === null ? null : String(_title);
|
|
1386
1404
|
let i = startIndex + 1;
|
|
1387
1405
|
const linkTokens = [];
|
|
1388
|
-
|
|
1406
|
+
let loading = true;
|
|
1389
1407
|
while (i < tokens.length && tokens[i].type !== "link_close") {
|
|
1390
1408
|
linkTokens.push(tokens[i]);
|
|
1391
1409
|
i++;
|
|
1392
1410
|
}
|
|
1411
|
+
if (tokens[i]?.type === "link_close") loading = false;
|
|
1393
1412
|
const children = parseInlineTokens(linkTokens);
|
|
1394
1413
|
const linkText = children.map((node) => {
|
|
1395
1414
|
const nodeAny = node;
|
|
@@ -1546,18 +1565,16 @@ function parseTextToken(token) {
|
|
|
1546
1565
|
|
|
1547
1566
|
//#endregion
|
|
1548
1567
|
//#region src/parser/inline-parsers/index.ts
|
|
1568
|
+
const STRONG_PAIR_RE = /\*\*([\s\S]*?)\*\*/;
|
|
1569
|
+
function escapeRegExp(str) {
|
|
1570
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1571
|
+
}
|
|
1549
1572
|
const AUTOLINK_PROTOCOL_RE = /^(?:https?:\/\/|mailto:|ftp:\/\/)/i;
|
|
1550
1573
|
const AUTOLINK_GENERIC_RE = /:\/\//;
|
|
1551
1574
|
function isLikelyUrl(href) {
|
|
1552
1575
|
if (!href) return false;
|
|
1553
1576
|
return AUTOLINK_PROTOCOL_RE.test(href) || AUTOLINK_GENERIC_RE.test(href);
|
|
1554
1577
|
}
|
|
1555
|
-
function escapeRegExp(str) {
|
|
1556
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1557
|
-
}
|
|
1558
|
-
const bracketRegexCache = new LRUCache(500);
|
|
1559
|
-
const parenHrefRegexCache = new LRUCache(500);
|
|
1560
|
-
const linkMatchRegexCache = new LRUCache(500);
|
|
1561
1578
|
function parseInlineTokens(tokens, raw, pPreToken) {
|
|
1562
1579
|
if (!tokens || tokens.length === 0) return [];
|
|
1563
1580
|
const result = [];
|
|
@@ -1621,7 +1638,7 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
1621
1638
|
i++;
|
|
1622
1639
|
return true;
|
|
1623
1640
|
}
|
|
1624
|
-
const exec =
|
|
1641
|
+
const exec = STRONG_PAIR_RE.exec(content);
|
|
1625
1642
|
let inner = "";
|
|
1626
1643
|
let after = "";
|
|
1627
1644
|
if (exec && typeof exec.index === "number") {
|
|
@@ -1993,7 +2010,7 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
1993
2010
|
if (raw && tokens[i + 1].type === "text") {
|
|
1994
2011
|
const text = String(tokens[i + 1]?.content ?? "");
|
|
1995
2012
|
const escText = escapeRegExp(text);
|
|
1996
|
-
if (!
|
|
2013
|
+
if (!(/* @__PURE__ */ new RegExp(`\\[${escText}\\s*\\]`)).test(raw)) {
|
|
1997
2014
|
const hrefAttr$1 = token.attrs?.find(([name]) => name === "href")?.[1] ?? "";
|
|
1998
2015
|
if (!raw.includes("[") && isLikelyUrl(String(hrefAttr$1))) {
|
|
1999
2016
|
resetCurrentTextNode();
|
|
@@ -2018,11 +2035,7 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
2018
2035
|
}
|
|
2019
2036
|
}
|
|
2020
2037
|
if (raw && href) {
|
|
2021
|
-
const
|
|
2022
|
-
const loadingMath = parenHrefRegexCache.getOrCreate(hrefStrLocal, () => {
|
|
2023
|
-
const escHref = escapeRegExp(hrefStrLocal);
|
|
2024
|
-
return /* @__PURE__ */ new RegExp(`\\(\\s*${escHref}\\s*\\)`);
|
|
2025
|
-
});
|
|
2038
|
+
const loadingMath = /* @__PURE__ */ new RegExp(`\\(\\s*${escapeRegExp(href)}\\s*\\)`);
|
|
2026
2039
|
const pre = result.length > 0 ? result[result.length - 1] : void 0;
|
|
2027
2040
|
const loading = !loadingMath.test(raw);
|
|
2028
2041
|
if (loading && pre) {
|
|
@@ -2032,7 +2045,7 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
2032
2045
|
else if (pre.type === "text") preText = String(pre.content ?? "");
|
|
2033
2046
|
else if (pre.content && typeof pre.content === "string") preText = String(pre.content ?? "").slice(1, -1);
|
|
2034
2047
|
}
|
|
2035
|
-
if (
|
|
2048
|
+
if ((/* @__PURE__ */ new RegExp(`\\[${escapeRegExp(preText)}\\s*\\]\\(`)).test(raw)) {
|
|
2036
2049
|
const text = String(preText ?? "");
|
|
2037
2050
|
resetCurrentTextNode();
|
|
2038
2051
|
const node$1 = {
|
|
@@ -2570,7 +2583,6 @@ function parseAdmonition(tokens, index, match) {
|
|
|
2570
2583
|
|
|
2571
2584
|
//#endregion
|
|
2572
2585
|
//#region src/parser/node-parsers/container-parser.ts
|
|
2573
|
-
const containerCloseTypeCache = new LRUCache(50);
|
|
2574
2586
|
function parseContainer(tokens, index) {
|
|
2575
2587
|
const openToken = tokens[index];
|
|
2576
2588
|
let kind = "note";
|
|
@@ -2580,9 +2592,7 @@ function parseContainer(tokens, index) {
|
|
|
2580
2592
|
kind = typeMatch[1];
|
|
2581
2593
|
const info = String(openToken.info ?? "").trim();
|
|
2582
2594
|
if (info && !info.startsWith(":::")) {
|
|
2583
|
-
|
|
2584
|
-
if (maybe.startsWith(kind)) maybe = maybe.slice(kind.length).trim();
|
|
2585
|
-
maybe = maybe.trim();
|
|
2595
|
+
const maybe = info.replace(/* @__PURE__ */ new RegExp(`^${kind}`), "").trim();
|
|
2586
2596
|
if (maybe) title = maybe;
|
|
2587
2597
|
}
|
|
2588
2598
|
} else {
|
|
@@ -2596,8 +2606,7 @@ function parseContainer(tokens, index) {
|
|
|
2596
2606
|
if (!title) title = kind.charAt(0).toUpperCase() + kind.slice(1);
|
|
2597
2607
|
const children = [];
|
|
2598
2608
|
let j = index + 1;
|
|
2599
|
-
const
|
|
2600
|
-
const closeType = containerCloseTypeCache.getOrCreate(key, () => /* @__PURE__ */ new RegExp(`^container_${kind}_close$`));
|
|
2609
|
+
const closeType = /* @__PURE__ */ new RegExp(`^container_${kind}_close$`);
|
|
2601
2610
|
while (j < tokens.length && tokens[j].type !== "container_close" && !closeType.test(tokens[j].type)) if (tokens[j].type === "paragraph_open") {
|
|
2602
2611
|
const contentToken = tokens[j + 1];
|
|
2603
2612
|
if (contentToken) {
|
|
@@ -2643,7 +2652,23 @@ function parseHardBreak() {
|
|
|
2643
2652
|
|
|
2644
2653
|
//#endregion
|
|
2645
2654
|
//#region src/parser/node-parsers/html-block-parser.ts
|
|
2646
|
-
const
|
|
2655
|
+
const VOID_TAGS = new Set([
|
|
2656
|
+
"area",
|
|
2657
|
+
"base",
|
|
2658
|
+
"br",
|
|
2659
|
+
"col",
|
|
2660
|
+
"embed",
|
|
2661
|
+
"hr",
|
|
2662
|
+
"img",
|
|
2663
|
+
"input",
|
|
2664
|
+
"link",
|
|
2665
|
+
"meta",
|
|
2666
|
+
"param",
|
|
2667
|
+
"source",
|
|
2668
|
+
"track",
|
|
2669
|
+
"wbr"
|
|
2670
|
+
]);
|
|
2671
|
+
const CLOSE_TAG_RE_CACHE = /* @__PURE__ */ new Map();
|
|
2647
2672
|
function parseHtmlBlock(token) {
|
|
2648
2673
|
const raw = String(token.content ?? "");
|
|
2649
2674
|
if (/^\s*<!--/.test(raw) || /^\s*<!/.test(raw) || /^\s*<\?/.test(raw)) return {
|
|
@@ -2661,25 +2686,14 @@ function parseHtmlBlock(token) {
|
|
|
2661
2686
|
tag: "",
|
|
2662
2687
|
loading: false
|
|
2663
2688
|
};
|
|
2664
|
-
const VOID_TAGS = new Set([
|
|
2665
|
-
"area",
|
|
2666
|
-
"base",
|
|
2667
|
-
"br",
|
|
2668
|
-
"col",
|
|
2669
|
-
"embed",
|
|
2670
|
-
"hr",
|
|
2671
|
-
"img",
|
|
2672
|
-
"input",
|
|
2673
|
-
"link",
|
|
2674
|
-
"meta",
|
|
2675
|
-
"param",
|
|
2676
|
-
"source",
|
|
2677
|
-
"track",
|
|
2678
|
-
"wbr"
|
|
2679
|
-
]);
|
|
2680
2689
|
const selfClosing = /^\s*<[^>]*\/\s*>/.test(raw);
|
|
2681
2690
|
const isVoid = VOID_TAGS.has(tag);
|
|
2682
|
-
|
|
2691
|
+
let closeRe = CLOSE_TAG_RE_CACHE.get(tag);
|
|
2692
|
+
if (!closeRe) {
|
|
2693
|
+
closeRe = new RegExp(`<\\/\\s*${tag}\\b`, "i");
|
|
2694
|
+
CLOSE_TAG_RE_CACHE.set(tag, closeRe);
|
|
2695
|
+
}
|
|
2696
|
+
const hasClosing = closeRe.test(raw);
|
|
2683
2697
|
const loading = !(isVoid || selfClosing || hasClosing);
|
|
2684
2698
|
return {
|
|
2685
2699
|
type: "html_block",
|
|
@@ -2913,10 +2927,11 @@ function getMarkdown(msgId = `editor-${Date.now()}`, options = {}) {
|
|
|
2913
2927
|
<div class="code-editor"></div>
|
|
2914
2928
|
</div>`;
|
|
2915
2929
|
};
|
|
2930
|
+
const RE_REFERENCE = /^\[(\d+)\]/;
|
|
2916
2931
|
const referenceInline = (state, silent) => {
|
|
2917
2932
|
const s = state;
|
|
2918
2933
|
if (s.src[s.pos] !== "[") return false;
|
|
2919
|
-
const match =
|
|
2934
|
+
const match = RE_REFERENCE.exec(s.src.slice(s.pos));
|
|
2920
2935
|
if (!match) return false;
|
|
2921
2936
|
if (!silent) {
|
|
2922
2937
|
const id = match[1];
|