stream-markdown-parser 0.0.58-beta.7 → 0.0.58-beta.9
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 +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +129 -152
- package/dist/index.js.map +1 -1
- package/package.json +15 -13
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,11 @@ interface FactoryOptions extends Record<string, unknown> {
|
|
|
14
14
|
* suppression and be emitted as custom nodes (e.g. ['thinking']).
|
|
15
15
|
*/
|
|
16
16
|
customHtmlTags?: readonly string[];
|
|
17
|
+
/**
|
|
18
|
+
* Whether to enable the fix for indented code blocks that should be paragraphs.
|
|
19
|
+
* Default: true
|
|
20
|
+
*/
|
|
21
|
+
enableFixIndentedCodeBlock?: boolean;
|
|
17
22
|
}
|
|
18
23
|
//#endregion
|
|
19
24
|
//#region src/types.d.ts
|
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":";;;
|
|
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;EAaL;AAEZ;AAMA;AAOA;EAMiB,cAAW,CAAA,EAAA,SAEhB,MAAA,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QiB;EAMjB;EAOA,QAAA,CAAA,EAAA,SAAc,MAAA,EAEnB;EAIK;EAMA,iBAAS,CAAA,EAAA,OAKjB;EAGQ;AAKjB;AAiBA;AAOA;AAYA;AAYA;;;;;AAUA;EAKiB,gBAAS,CAAA,EAAA,OAKd;AAGZ;AAOiB,iBGvGD,qBAAA,CHuGmC,IAAA,EGvGP,WHuGO,GAAA,SAAA,CAAA,EAAA,IAAA;;;iBIrInC,iBAAA;;;iBCoCA,eAAA,QAAuB,gBAAgB;;;iBC6FvC,eAAA,KAAoB;;;cCjIvB;cAoBA;iBA6BG,UAAA;;;cChCH;iBAyKG,6BAAA,mBAAgD;iBA2EhD,SAAA,KAAc,yBAAuB;;;ATxPpC,iBUQD,sBAAA,CVRwB,MAAM,EAAA,OAAA,CAAA,EAAA,IAAA;iBUY9B,8BAAA,CAAA;AT8BC,USNA,kBAAA,SAA2B,cTMG,CAAA;EAiB9B,MAAA,CAAA,EStBN,KTsBM,CAAA,OAAc,CAAA;EAOd,KAAA,CAAA,ES5BP,KT4BO,CAAA,CAAA,EAAe,ES5BX,UTgCT,EAAA,GAAA,IAAA,CAAA;EAQA;AAYZ;;;EAA6C,IAAA,CAAA,EAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,MAAA,CAAA,GS/CR,MT+CQ,CAAA,MAAA,EAAA,MAAA,CAAA;;AAU5B,iBStDD,WAAA,CTsDwB,KAAQ,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EStD6B,kBTsD7B,CAAA,EStDoD,UTsDpD"}
|
package/dist/index.js
CHANGED
|
@@ -7484,18 +7484,33 @@ function applyFixHtmlInlineTokens(md, options = {}) {
|
|
|
7484
7484
|
const t = toks[i];
|
|
7485
7485
|
if (t.type === "html_block") {
|
|
7486
7486
|
const tag = (t.content?.match(/<([^\s>/]+)/)?.[1] ?? "").toLowerCase();
|
|
7487
|
+
if (tag.startsWith("!") || tag.startsWith("?")) {
|
|
7488
|
+
t.loading = false;
|
|
7489
|
+
continue;
|
|
7490
|
+
}
|
|
7487
7491
|
if (customTagSet.has(tag)) {
|
|
7488
|
-
const raw$
|
|
7492
|
+
const raw$2 = String(t.content ?? "");
|
|
7489
7493
|
const closeRe = new RegExp(`<\\/\\s*${tag}\\s*>`, "i");
|
|
7490
|
-
t.loading = closeRe.test(raw$
|
|
7491
|
-
const closeMatch = closeRe.exec(raw$
|
|
7492
|
-
const endTagIndex = closeMatch ? closeMatch.index : -1;
|
|
7493
|
-
const closeLen = closeMatch ? closeMatch[0].length : 0;
|
|
7494
|
-
if (endTagIndex !== -1) {
|
|
7495
|
-
const rawForNode = raw$
|
|
7494
|
+
t.loading = closeRe.test(raw$2) ? false : t.loading !== void 0 ? t.loading : true;
|
|
7495
|
+
const closeMatch$1 = closeRe.exec(raw$2);
|
|
7496
|
+
const endTagIndex$1 = closeMatch$1 ? closeMatch$1.index : -1;
|
|
7497
|
+
const closeLen$1 = closeMatch$1 ? closeMatch$1[0].length : 0;
|
|
7498
|
+
if (endTagIndex$1 !== -1) {
|
|
7499
|
+
const rawForNode = raw$2.slice(0, endTagIndex$1 + closeLen$1);
|
|
7500
|
+
let inner = "";
|
|
7501
|
+
const openEnd = findTagCloseIndexOutsideQuotes$1(raw$2);
|
|
7502
|
+
if (openEnd !== -1 && openEnd < endTagIndex$1) inner = raw$2.slice(openEnd + 1, endTagIndex$1);
|
|
7503
|
+
t.children = [{
|
|
7504
|
+
type: tag,
|
|
7505
|
+
content: inner,
|
|
7506
|
+
raw: rawForNode,
|
|
7507
|
+
attrs: [],
|
|
7508
|
+
tag,
|
|
7509
|
+
loading: false
|
|
7510
|
+
}];
|
|
7496
7511
|
t.content = rawForNode;
|
|
7497
7512
|
t.raw = rawForNode;
|
|
7498
|
-
const afterTrimmed = (raw$
|
|
7513
|
+
const afterTrimmed = (raw$2.slice(endTagIndex$1 + closeLen$1) || "").replace(/^\s+/, "");
|
|
7499
7514
|
if (afterTrimmed) toks.splice(i + 1, 0, afterTrimmed.startsWith("<") ? {
|
|
7500
7515
|
type: "html_block",
|
|
7501
7516
|
content: afterTrimmed
|
|
@@ -7504,11 +7519,14 @@ function applyFixHtmlInlineTokens(md, options = {}) {
|
|
|
7504
7519
|
content: afterTrimmed,
|
|
7505
7520
|
raw: afterTrimmed
|
|
7506
7521
|
});
|
|
7507
|
-
}
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7522
|
+
} else t.children = [{
|
|
7523
|
+
type: tag,
|
|
7524
|
+
content: "",
|
|
7525
|
+
raw: raw$2,
|
|
7526
|
+
attrs: [],
|
|
7527
|
+
tag,
|
|
7528
|
+
loading: true
|
|
7529
|
+
}];
|
|
7512
7530
|
continue;
|
|
7513
7531
|
}
|
|
7514
7532
|
if ([
|
|
@@ -7524,7 +7542,6 @@ function applyFixHtmlInlineTokens(md, options = {}) {
|
|
|
7524
7542
|
"li"
|
|
7525
7543
|
].includes(tag)) continue;
|
|
7526
7544
|
t.type = "inline";
|
|
7527
|
-
const loading = new RegExp(`<\\/\\s*${tag}\\s*>`, "i").test(String(t.content ?? "")) ? false : t.loading !== void 0 ? t.loading : true;
|
|
7528
7545
|
const attrs = [];
|
|
7529
7546
|
const attrRegex = /\s([\w:-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
7530
7547
|
let match;
|
|
@@ -7533,44 +7550,34 @@ function applyFixHtmlInlineTokens(md, options = {}) {
|
|
|
7533
7550
|
const attrValue = match[2] || match[3] || match[4] || "";
|
|
7534
7551
|
attrs.push([attrName, attrValue]);
|
|
7535
7552
|
}
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
const rawForNode =
|
|
7542
|
-
|
|
7543
|
-
const openEnd = findTagCloseIndexOutsideQuotes$1(raw$1);
|
|
7544
|
-
if (openEnd !== -1) {
|
|
7545
|
-
if (endTagIndex !== -1 && openEnd < endTagIndex) inner = raw$1.slice(openEnd + 1, endTagIndex);
|
|
7546
|
-
else if (endTagIndex === -1) inner = raw$1.slice(openEnd + 1).replace(/<.*$/, "");
|
|
7547
|
-
}
|
|
7553
|
+
const raw$1 = String(t.content ?? "");
|
|
7554
|
+
const closeMatch = new RegExp(`<\\/\\s*${tag}\\s*>`, "i").exec(raw$1);
|
|
7555
|
+
const endTagIndex = closeMatch ? closeMatch.index : -1;
|
|
7556
|
+
const closeLen = closeMatch ? closeMatch[0].length : 0;
|
|
7557
|
+
if (endTagIndex !== -1) {
|
|
7558
|
+
const rawForNode = raw$1.slice(0, endTagIndex + closeLen);
|
|
7559
|
+
const afterTrimmed = (raw$1.slice(endTagIndex + closeLen) || "").replace(/^\s+/, "");
|
|
7548
7560
|
t.children = [{
|
|
7549
|
-
type:
|
|
7550
|
-
content:
|
|
7551
|
-
raw: rawForNode,
|
|
7552
|
-
attrs,
|
|
7561
|
+
type: "html_block",
|
|
7562
|
+
content: rawForNode,
|
|
7553
7563
|
tag,
|
|
7554
|
-
loading
|
|
7564
|
+
loading: false
|
|
7555
7565
|
}];
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
raw: afterTrimmed
|
|
7567
|
-
});
|
|
7568
|
-
}
|
|
7566
|
+
t.content = rawForNode;
|
|
7567
|
+
t.raw = rawForNode;
|
|
7568
|
+
if (afterTrimmed) toks.splice(i + 1, 0, afterTrimmed.startsWith("<") ? {
|
|
7569
|
+
type: "html_block",
|
|
7570
|
+
content: afterTrimmed
|
|
7571
|
+
} : {
|
|
7572
|
+
type: "text",
|
|
7573
|
+
content: afterTrimmed,
|
|
7574
|
+
raw: afterTrimmed
|
|
7575
|
+
});
|
|
7569
7576
|
} else t.children = [{
|
|
7570
7577
|
type: "html_block",
|
|
7571
7578
|
content: t.content,
|
|
7572
7579
|
tag,
|
|
7573
|
-
loading
|
|
7580
|
+
loading: true
|
|
7574
7581
|
}];
|
|
7575
7582
|
continue;
|
|
7576
7583
|
}
|
|
@@ -7622,6 +7629,81 @@ function applyFixHtmlInlineTokens(md, options = {}) {
|
|
|
7622
7629
|
});
|
|
7623
7630
|
}
|
|
7624
7631
|
|
|
7632
|
+
//#endregion
|
|
7633
|
+
//#region src/plugins/fixIndentedCodeBlock.ts
|
|
7634
|
+
/**
|
|
7635
|
+
* Check if a line looks like code (vs plain text or HTML entities).
|
|
7636
|
+
* Returns true if the line appears to be code.
|
|
7637
|
+
*/
|
|
7638
|
+
function looksLikeCode(line) {
|
|
7639
|
+
const trimmed = line.trim();
|
|
7640
|
+
if (!trimmed) return false;
|
|
7641
|
+
if (/^&[a-z0-9#]+;/i.test(trimmed)) return false;
|
|
7642
|
+
if (/^(?:const|let|var|function|class|import|export|if|for|while|return|await|async|yield|try|catch|throw|new|typeof|instanceof|switch|case|break|continue|def|ruby|perl|print|echo|true|false|null|undefined|NaN|Infinity|this)\b/.test(trimmed)) return true;
|
|
7643
|
+
if (/[a-z_$][\w$]*(?:\.[a-z_$][\w$]*|\['[^']*'\]|\["[^"]*"\]|\[\d+\])*\s*\(/i.test(trimmed)) return true;
|
|
7644
|
+
if (/[a-z_$][\w$]*(?:\.[a-z_$][\w$]*|\['[^']*'\]|\["[^"]*"\]|\[[\d+\]])+/i.test(trimmed)) return true;
|
|
7645
|
+
if (/\w+\s*(?:===?|!==?|<=?|>=?|\+\+|--|&&|\|\||\?\.)/.test(trimmed)) return true;
|
|
7646
|
+
if (/^(?:!!|\+\+|--)\s*\w/.test(trimmed)) return true;
|
|
7647
|
+
if (/[\w$]+\s*(?:\+=|-=|\*=|\/=|%=|\*\*=|=)/.test(trimmed)) return true;
|
|
7648
|
+
if (/^(?:https?:\/\/|ftp:\/\/|file:\/\/|\/\/|www\.)/i.test(trimmed)) return true;
|
|
7649
|
+
if (/`[^`]*\$\{[^}]*\}[^`]*`/.test(trimmed)) return true;
|
|
7650
|
+
if (/<\/?[A-Z][a-zA-Z0-9]*/.test(trimmed)) return true;
|
|
7651
|
+
if (/<[a-z][a-z0-9]*\s[^>]+>/.test(trimmed)) return true;
|
|
7652
|
+
if (/^(["'`]).*\1\s*[;,]?$/.test(trimmed)) return true;
|
|
7653
|
+
if (/^\[[\s\S]*\]$/.test(trimmed) || /^\{[\s\S]*\}$/.test(trimmed) || /^\(\s*\)$/.test(trimmed)) return true;
|
|
7654
|
+
if (/[\w$]+(?:\s*[+\-*/%<>=!&|^~:]+\s*[\w$]+|\s*\.\s*[\w$]+)/.test(trimmed)) return true;
|
|
7655
|
+
if (/=>|->|::/.test(trimmed)) return true;
|
|
7656
|
+
if (/^@[\w.$]+$/.test(trimmed)) return true;
|
|
7657
|
+
if (/^(?:0x[0-9a-fA-F]+|0b[01]+|0o[0-7]+|\d+(?:\.\d*)?(?:px|em|rem|%|vh|vw|deg|s|ms)?)$/.test(trimmed)) return true;
|
|
7658
|
+
if (/^\$[\w$]+\s*[=:]/.test(trimmed)) return true;
|
|
7659
|
+
if (/\|\s*\w+|\w+\s*\|/.test(trimmed)) return true;
|
|
7660
|
+
if (/^(?:git|npm|yarn|pnpm|bun|pip|cargo|go|rust|python|node|java|mvn|gradle|docker|kubectl)\s+/.test(trimmed)) return true;
|
|
7661
|
+
if (/(?:console|window|document|Math|JSON|Date|Array|Object|String|Number|Boolean)\.[a-zA-Z]/.test(trimmed)) return true;
|
|
7662
|
+
if (/^(?:\/\/|#|\/\*|\*\/|<!--|-->)/.test(trimmed)) return true;
|
|
7663
|
+
if (/^(?:<<<|<<\s*['"]?\w+['"]?)/.test(trimmed)) return true;
|
|
7664
|
+
return false;
|
|
7665
|
+
}
|
|
7666
|
+
function applyFixIndentedCodeBlock(md, options = {}) {
|
|
7667
|
+
if (options.enabled === false) return;
|
|
7668
|
+
md.core.ruler.after("inline", "fix_indented_code_block", (state) => {
|
|
7669
|
+
const tokens = state.tokens;
|
|
7670
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
7671
|
+
const token = tokens[i];
|
|
7672
|
+
if (token.type !== "code_block") continue;
|
|
7673
|
+
const content = String(token.content ?? "").trim();
|
|
7674
|
+
if (!content) continue;
|
|
7675
|
+
const lines = content.split(/\r?\n/).filter((line) => line.trim().length > 0);
|
|
7676
|
+
if (lines.length === 1 && !looksLikeCode(lines[0] ?? "")) {
|
|
7677
|
+
const textContent = lines[0] ?? "";
|
|
7678
|
+
tokens.splice(i, 1, {
|
|
7679
|
+
type: "paragraph_open",
|
|
7680
|
+
tag: "p",
|
|
7681
|
+
nesting: 1,
|
|
7682
|
+
level: token.level
|
|
7683
|
+
}, {
|
|
7684
|
+
type: "inline",
|
|
7685
|
+
tag: "",
|
|
7686
|
+
nesting: 0,
|
|
7687
|
+
level: token.level,
|
|
7688
|
+
content: textContent,
|
|
7689
|
+
children: [{
|
|
7690
|
+
type: "text",
|
|
7691
|
+
content: textContent,
|
|
7692
|
+
level: token.level + 1
|
|
7693
|
+
}],
|
|
7694
|
+
block: true
|
|
7695
|
+
}, {
|
|
7696
|
+
type: "paragraph_close",
|
|
7697
|
+
tag: "p",
|
|
7698
|
+
nesting: -1,
|
|
7699
|
+
level: token.level
|
|
7700
|
+
});
|
|
7701
|
+
i += 2;
|
|
7702
|
+
}
|
|
7703
|
+
}
|
|
7704
|
+
});
|
|
7705
|
+
}
|
|
7706
|
+
|
|
7625
7707
|
//#endregion
|
|
7626
7708
|
//#region src/plugins/fixLinkTokens.ts
|
|
7627
7709
|
function textToken(content) {
|
|
@@ -7715,6 +7797,7 @@ function applyFixLinkTokens(md) {
|
|
|
7715
7797
|
}
|
|
7716
7798
|
function fixLinkToken(tokens) {
|
|
7717
7799
|
if (tokens.length < 4) return tokens;
|
|
7800
|
+
if (tokens.some((token) => token.type === "code_inline")) return tokens;
|
|
7718
7801
|
for (let i = 0; i <= tokens.length - 1; i++) {
|
|
7719
7802
|
if (i < 0) i = 0;
|
|
7720
7803
|
const curToken = tokens[i];
|
|
@@ -8988,6 +9071,7 @@ function factory(opts = {}) {
|
|
|
8988
9071
|
...opts.mathOptions ?? {}
|
|
8989
9072
|
});
|
|
8990
9073
|
if (opts.enableContainers ?? true) applyContainers(md);
|
|
9074
|
+
if (opts.enableFixIndentedCodeBlock !== false) applyFixIndentedCodeBlock(md);
|
|
8991
9075
|
applyFixLinkTokens(md);
|
|
8992
9076
|
applyFixStrongTokens(md);
|
|
8993
9077
|
applyFixListItem(md);
|
|
@@ -9618,15 +9702,6 @@ function parseTextToken(token) {
|
|
|
9618
9702
|
//#endregion
|
|
9619
9703
|
//#region src/parser/inline-parsers/index.ts
|
|
9620
9704
|
const STRONG_PAIR_RE = /\*\*([\s\S]*?)\*\*/;
|
|
9621
|
-
function escapeRegExp(str) {
|
|
9622
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9623
|
-
}
|
|
9624
|
-
const AUTOLINK_PROTOCOL_RE = /^(?:https?:\/\/|mailto:|ftp:\/\/)/i;
|
|
9625
|
-
const AUTOLINK_GENERIC_RE = /:\/\//;
|
|
9626
|
-
function isLikelyUrl(href) {
|
|
9627
|
-
if (!href) return false;
|
|
9628
|
-
return AUTOLINK_PROTOCOL_RE.test(href) || AUTOLINK_GENERIC_RE.test(href);
|
|
9629
|
-
}
|
|
9630
9705
|
function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
9631
9706
|
if (!tokens || tokens.length === 0) return [];
|
|
9632
9707
|
const result = [];
|
|
@@ -10167,104 +10242,6 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
10167
10242
|
}
|
|
10168
10243
|
function handleLinkOpen(token) {
|
|
10169
10244
|
resetCurrentTextNode();
|
|
10170
|
-
const href = token.attrs?.find(([name]) => name === "href")?.[1];
|
|
10171
|
-
if (raw && tokens[i + 1].type === "text") {
|
|
10172
|
-
let text$1 = String(tokens[i + 1]?.content ?? "");
|
|
10173
|
-
const escText = escapeRegExp(text$1);
|
|
10174
|
-
if (!(/* @__PURE__ */ new RegExp(`\\[${escText}\\s*\\]`)).test(raw)) {
|
|
10175
|
-
const hrefAttr$1 = token.attrs?.find(([name]) => name === "href")?.[1] ?? "";
|
|
10176
|
-
if (!raw.includes("[") && isLikelyUrl(String(hrefAttr$1))) {
|
|
10177
|
-
resetCurrentTextNode();
|
|
10178
|
-
pushParsed({
|
|
10179
|
-
type: "link",
|
|
10180
|
-
href: String(hrefAttr$1),
|
|
10181
|
-
title: null,
|
|
10182
|
-
text: text$1,
|
|
10183
|
-
children: [{
|
|
10184
|
-
type: "text",
|
|
10185
|
-
content: text$1,
|
|
10186
|
-
raw: text$1
|
|
10187
|
-
}],
|
|
10188
|
-
loading: false
|
|
10189
|
-
});
|
|
10190
|
-
i += 3;
|
|
10191
|
-
return;
|
|
10192
|
-
}
|
|
10193
|
-
if (tokens[i + 2]?.type === "strong_open") {
|
|
10194
|
-
i += 2;
|
|
10195
|
-
while (i < tokens.length - 1 && tokens[i] && tokens[i]?.type !== "link_close") {
|
|
10196
|
-
text$1 += String(tokens[i]?.markup || tokens[i]?.content || "");
|
|
10197
|
-
i++;
|
|
10198
|
-
}
|
|
10199
|
-
pushParsed({
|
|
10200
|
-
type: "link",
|
|
10201
|
-
href: String(hrefAttr$1),
|
|
10202
|
-
title: null,
|
|
10203
|
-
text: text$1,
|
|
10204
|
-
children: [{
|
|
10205
|
-
type: "text",
|
|
10206
|
-
content: text$1,
|
|
10207
|
-
raw: text$1
|
|
10208
|
-
}],
|
|
10209
|
-
loading: false
|
|
10210
|
-
});
|
|
10211
|
-
i += 1;
|
|
10212
|
-
} else {
|
|
10213
|
-
i += 2;
|
|
10214
|
-
while (i < tokens.length && tokens[i].type !== "link_close") {
|
|
10215
|
-
text$1 += String(tokens[i]?.content || "");
|
|
10216
|
-
i++;
|
|
10217
|
-
}
|
|
10218
|
-
const loading = tokens[i].type !== "link_close";
|
|
10219
|
-
pushParsed({
|
|
10220
|
-
type: "link",
|
|
10221
|
-
href: String(hrefAttr$1),
|
|
10222
|
-
title: null,
|
|
10223
|
-
text: text$1,
|
|
10224
|
-
children: [{
|
|
10225
|
-
type: "text",
|
|
10226
|
-
content: text$1,
|
|
10227
|
-
raw: text$1
|
|
10228
|
-
}],
|
|
10229
|
-
loading
|
|
10230
|
-
});
|
|
10231
|
-
}
|
|
10232
|
-
return;
|
|
10233
|
-
}
|
|
10234
|
-
}
|
|
10235
|
-
if (raw && href) {
|
|
10236
|
-
const loadingMath = /* @__PURE__ */ new RegExp(`\\(\\s*${escapeRegExp(href)}\\s*\\)`);
|
|
10237
|
-
const pre = result.length > 0 ? result[result.length - 1] : void 0;
|
|
10238
|
-
const loading = !loadingMath.test(raw);
|
|
10239
|
-
if (loading && pre) {
|
|
10240
|
-
let preText = "";
|
|
10241
|
-
if (pre) {
|
|
10242
|
-
if (pre.type === "link") preText = String(pre.text ?? "");
|
|
10243
|
-
else if (pre.type === "text") preText = String(pre.content ?? "");
|
|
10244
|
-
else if (pre.content && typeof pre.content === "string") preText = String(pre.content ?? "").slice(1, -1);
|
|
10245
|
-
}
|
|
10246
|
-
if ((/* @__PURE__ */ new RegExp(`\\[${escapeRegExp(preText)}\\s*\\]\\(`)).test(raw)) {
|
|
10247
|
-
const text$1 = String(preText ?? "");
|
|
10248
|
-
resetCurrentTextNode();
|
|
10249
|
-
const node$1 = {
|
|
10250
|
-
type: "link",
|
|
10251
|
-
href: "",
|
|
10252
|
-
title: null,
|
|
10253
|
-
text: text$1,
|
|
10254
|
-
children: [{
|
|
10255
|
-
type: "text",
|
|
10256
|
-
content: text$1,
|
|
10257
|
-
raw: text$1
|
|
10258
|
-
}],
|
|
10259
|
-
loading
|
|
10260
|
-
};
|
|
10261
|
-
result.splice(result.length - 1, 1, node$1);
|
|
10262
|
-
i += 3;
|
|
10263
|
-
if (String(tokens[i]?.content ?? "") === ".") i++;
|
|
10264
|
-
return;
|
|
10265
|
-
}
|
|
10266
|
-
}
|
|
10267
|
-
}
|
|
10268
10245
|
const { node, nextIndex } = parseLinkToken(tokens, i, { requireClosingStrong });
|
|
10269
10246
|
i = nextIndex;
|
|
10270
10247
|
const hrefAttr = token.attrs?.find(([name]) => name === "href")?.[1];
|