stream-markdown-parser 0.0.68 → 0.0.70
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 +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +241 -40
- package/dist/index.js.map +1 -1
- package/package.json +14 -12
package/dist/index.d.ts
CHANGED
|
@@ -350,11 +350,7 @@ interface ParseOptions {
|
|
|
350
350
|
type PostTransformNodesHook = (nodes: ParsedNode[]) => ParsedNode[];
|
|
351
351
|
//#endregion
|
|
352
352
|
//#region src/parser/inline-parsers/index.d.ts
|
|
353
|
-
declare function parseInlineTokens(tokens: MarkdownToken[], raw?: string, pPreToken?: MarkdownToken, options?:
|
|
354
|
-
requireClosingStrong?: boolean;
|
|
355
|
-
customHtmlTags?: readonly string[];
|
|
356
|
-
validateLink?: (url: string) => boolean;
|
|
357
|
-
}): ParsedNode[];
|
|
353
|
+
declare function parseInlineTokens(tokens: MarkdownToken[], raw?: string, pPreToken?: MarkdownToken, options?: ParseOptions): ParsedNode[];
|
|
358
354
|
//#endregion
|
|
359
355
|
//#region src/parser/index.d.ts
|
|
360
356
|
declare function parseMarkdownToStructure(markdown: string, md: MarkdownIt$1, options?: ParseOptions): ParsedNode[];
|
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;EAaL;AAEZ;AAMA;;EAKY,cAAA,CAAA,EAAA,SAAA,MAAA,EAAA;EALyB;;AAQrC;AAMA;EAMiB,0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A,EAAA,MAAA;EACA,KAAA,CAAA,EAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA;EACA,QAAA,EA9NM,UA8NN,EAAA;;AAEA,UA7NW,SAAA,SAAkB,QA6N7B,CAAA;EACA,IAAA,EAAA,OAAA;EACA,GAAA,EAAA,MAAA;EACA,GAAA,EAAA,MAAA;EACA,KAAA,EAAA,MAAA,GAAA,IAAA;;AACW,UA3NA,iBAAA,SAA0B,QA2N1B,CAAA;EACA,IAAA,EAAA,gBAAgB;AAmCjC;AAEiB,UA7PA,gBAAA,CA8PM;EA6BX,IAAA,EAAA;;;;
|
|
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;;EAKY,cAAA,CAAA,EAAA,SAAA,MAAA,EAAA;EALyB;;AAQrC;AAMA;EAMiB,0BAKR,CAAA,EAAA,OAAA;AAGT;;;UAjDiB,QAAA;;EDWA,GAAA,EAAA,MAAA;;;;ACXjB;AAaA;AAEA;AAMA;;;AAAqC,KARzB,WAAA,GAAc,QAQW,GARA,MAQA,CAAA,MAAA,EAAA,OAAA,CAAA;AAAQ,UAN5B,QAAA,SAAiB,QAMW,CAAA;EAQ5B,IAAA,EAAA,MAAA;EAMA,OAAA,EAAA,MAAW;EAMX,MAAA,CAAA,EAAA,OAAS;AAQ1B;AAKiB,UAjCA,WAAA,SAAoB,QAiCU,CAAA;EAiB9B,IAAA,EAAA,SAAA;EAOA,KAAA,EAAA,MAAA;EAYL,IAAA,EAAA,MAAA;EAYK,KAAA,CAAA,EA7EP,MA6EO,C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AgD;iBA0MhD,SAAA,KAAc,yBAAuB;;;ATvXpC,iBUQD,sBAAA,CVRwB,MAAM,EAAA,OAAA,CAAA,EAAA,IAAA;iBUY9B,8BAAA,CAAA;ATMC,USkBA,kBAAA,SAA2B,cTlBG,CAAA;EAM9B,MAAA,CAAA,ESaN,KTbiB,CAAA,OAAA,CAAA;EAMX,KAAA,CAAA,ESQP,KTRgB,CAAA,CAAA,EAAA,ESQL,UTHZ,EAAA,GAAA,IALyB,CAAA;EAQjB;AAKjB;AAiBA;AAOA;EAYY,IAAA,CAAA,EAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAoB,MAAA,CAAA,GSpCK,MTsC/B,CAAA,MACA,EAAK,MAAA,CAAA;AASX;AAKU,iBSlDM,WAAA,CTkDN,KAAA,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,ESlDmE,kBTkDnE,CAAA,ESlD0F,UTkD1F"}
|
package/dist/index.js
CHANGED
|
@@ -7535,6 +7535,8 @@ function applyContainers(md) {
|
|
|
7535
7535
|
let innerSrc = contentLines.join("\n");
|
|
7536
7536
|
if (!innerSrc.endsWith("\n")) innerSrc += "\n";
|
|
7537
7537
|
if (!innerSrc.endsWith("\n\n")) innerSrc += "\n";
|
|
7538
|
+
const prevToken = s.tokens[s.tokens.length - 1];
|
|
7539
|
+
if (prevToken) prevToken.raw = innerSrc;
|
|
7538
7540
|
const innerTokens = [];
|
|
7539
7541
|
s.md.block.parse(innerSrc, s.md, s.env, innerTokens);
|
|
7540
7542
|
s.tokens.push(...innerTokens);
|
|
@@ -9499,6 +9501,41 @@ function findCodeSpanRangeAt(ranges, index) {
|
|
|
9499
9501
|
for (const range of ranges) if (index >= range[0] && index < range[1]) return range;
|
|
9500
9502
|
return null;
|
|
9501
9503
|
}
|
|
9504
|
+
function isEscapedAt(src, index) {
|
|
9505
|
+
let cursor = index - 1;
|
|
9506
|
+
let backslashes = 0;
|
|
9507
|
+
while (cursor >= 0 && src[cursor] === "\\") {
|
|
9508
|
+
backslashes++;
|
|
9509
|
+
cursor--;
|
|
9510
|
+
}
|
|
9511
|
+
return backslashes % 2 === 1;
|
|
9512
|
+
}
|
|
9513
|
+
function findNextUnescapedDollar(src, startIdx) {
|
|
9514
|
+
let searchPos = startIdx;
|
|
9515
|
+
while (searchPos < src.length) {
|
|
9516
|
+
const index = src.indexOf("$", searchPos);
|
|
9517
|
+
if (index === -1) return -1;
|
|
9518
|
+
if (isEscapedAt(src, index)) {
|
|
9519
|
+
searchPos = index + 1;
|
|
9520
|
+
continue;
|
|
9521
|
+
}
|
|
9522
|
+
return index;
|
|
9523
|
+
}
|
|
9524
|
+
return -1;
|
|
9525
|
+
}
|
|
9526
|
+
function findSingleDollarClose(src, startIdx) {
|
|
9527
|
+
let searchPos = startIdx;
|
|
9528
|
+
while (searchPos < src.length) {
|
|
9529
|
+
const index = findNextUnescapedDollar(src, searchPos);
|
|
9530
|
+
if (index === -1) return -1;
|
|
9531
|
+
if (index > 0 && src[index - 1] === "$" || index + 1 < src.length && src[index + 1] === "$") {
|
|
9532
|
+
searchPos = index + 1;
|
|
9533
|
+
continue;
|
|
9534
|
+
}
|
|
9535
|
+
return index;
|
|
9536
|
+
}
|
|
9537
|
+
return -1;
|
|
9538
|
+
}
|
|
9502
9539
|
function isLikelyCurrencyRangeDollar(content, nextChar) {
|
|
9503
9540
|
const stripped = String(content ?? "").trim();
|
|
9504
9541
|
if (!stripped) return false;
|
|
@@ -9521,9 +9558,11 @@ function applyMath(md, mathOpts) {
|
|
|
9521
9558
|
["$", "$"],
|
|
9522
9559
|
["\\(", "\\)"]
|
|
9523
9560
|
];
|
|
9524
|
-
|
|
9525
|
-
|
|
9526
|
-
|
|
9561
|
+
const pending = String(s.pending ?? "");
|
|
9562
|
+
const currentStart = Math.max(0, s.pos - pending.length);
|
|
9563
|
+
let searchPos = currentStart;
|
|
9564
|
+
let preMathPos = currentStart;
|
|
9565
|
+
const initialPos = currentStart;
|
|
9527
9566
|
for (const [open, close] of delimiters) {
|
|
9528
9567
|
const src = s.src;
|
|
9529
9568
|
const codeSpanRanges = buildCodeSpanRanges(src);
|
|
@@ -9551,7 +9590,7 @@ function applyMath(md, mathOpts) {
|
|
|
9551
9590
|
if (open === "$$" && text$1.includes("$")) {
|
|
9552
9591
|
let localPos = 0;
|
|
9553
9592
|
while (localPos < text$1.length) {
|
|
9554
|
-
const dollarIndex = text$1
|
|
9593
|
+
const dollarIndex = findNextUnescapedDollar(text$1, localPos);
|
|
9555
9594
|
if (dollarIndex === -1) {
|
|
9556
9595
|
const rest = text$1.slice(localPos);
|
|
9557
9596
|
if (rest) {
|
|
@@ -9580,7 +9619,7 @@ function applyMath(md, mathOpts) {
|
|
|
9580
9619
|
s.pos = s.pos + before.length;
|
|
9581
9620
|
searchPos = s.pos;
|
|
9582
9621
|
}
|
|
9583
|
-
const closingDollarIndex = text$1
|
|
9622
|
+
const closingDollarIndex = findSingleDollarClose(text$1, dollarIndex + 1);
|
|
9584
9623
|
if (closingDollarIndex === -1) {
|
|
9585
9624
|
const rest = text$1.slice(dollarIndex);
|
|
9586
9625
|
const t$2 = s.push("text", "", 0);
|
|
@@ -9659,6 +9698,10 @@ function applyMath(md, mathOpts) {
|
|
|
9659
9698
|
if (searchPos >= src.length) break;
|
|
9660
9699
|
const index = src.indexOf(open, searchPos);
|
|
9661
9700
|
if (index === -1) break;
|
|
9701
|
+
if (isEscapedAt(src, index)) {
|
|
9702
|
+
searchPos = index + Math.max(1, open.length);
|
|
9703
|
+
continue;
|
|
9704
|
+
}
|
|
9662
9705
|
const codeSpanAtIndex = findCodeSpanRangeAt(codeSpanRanges, index);
|
|
9663
9706
|
if (codeSpanAtIndex) {
|
|
9664
9707
|
searchPos = codeSpanAtIndex[1];
|
|
@@ -9691,7 +9734,7 @@ function applyMath(md, mathOpts) {
|
|
|
9691
9734
|
searchPos = index + 2;
|
|
9692
9735
|
continue;
|
|
9693
9736
|
}
|
|
9694
|
-
const endIdx = findMatchingClose_default(src, index + open.length, open, close);
|
|
9737
|
+
const endIdx = open === "$" ? findSingleDollarClose(src, index + open.length) : findMatchingClose_default(src, index + open.length, open, close);
|
|
9695
9738
|
if (endIdx === -1) {
|
|
9696
9739
|
const content$1 = src.slice(index + open.length);
|
|
9697
9740
|
if (content$1.includes(open)) {
|
|
@@ -9808,7 +9851,7 @@ function applyMath(md, mathOpts) {
|
|
|
9808
9851
|
let remainingPos = searchPos;
|
|
9809
9852
|
while (true) {
|
|
9810
9853
|
if (remainingPos >= src.length) break;
|
|
9811
|
-
const dollarIndex = src
|
|
9854
|
+
const dollarIndex = findNextUnescapedDollar(src, remainingPos);
|
|
9812
9855
|
if (dollarIndex === -1) break;
|
|
9813
9856
|
if (dollarIndex + 1 < src.length && src[dollarIndex + 1] === "$") {
|
|
9814
9857
|
remainingPos = dollarIndex + 2;
|
|
@@ -9818,12 +9861,8 @@ function applyMath(md, mathOpts) {
|
|
|
9818
9861
|
remainingPos = dollarIndex + 1;
|
|
9819
9862
|
continue;
|
|
9820
9863
|
}
|
|
9821
|
-
const closingDollarIndex = src
|
|
9864
|
+
const closingDollarIndex = findSingleDollarClose(src, dollarIndex + 1);
|
|
9822
9865
|
if (closingDollarIndex === -1) break;
|
|
9823
|
-
if (closingDollarIndex + 1 < src.length && src[closingDollarIndex + 1] === "$") {
|
|
9824
|
-
remainingPos = dollarIndex + 1;
|
|
9825
|
-
continue;
|
|
9826
|
-
}
|
|
9827
9866
|
const content = src.slice(dollarIndex + 1, closingDollarIndex);
|
|
9828
9867
|
const hasBacktick = content.includes("`");
|
|
9829
9868
|
const isEmpty = !content || !content.trim();
|
|
@@ -10076,6 +10115,7 @@ function parseEmphasisToken(tokens, startIndex, options) {
|
|
|
10076
10115
|
}
|
|
10077
10116
|
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
10078
10117
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10118
|
+
final: options?.final,
|
|
10079
10119
|
customHtmlTags: options?.customHtmlTags,
|
|
10080
10120
|
validateLink: options?.validateLink
|
|
10081
10121
|
}));
|
|
@@ -10188,7 +10228,9 @@ function parseHighlightToken(tokens, startIndex, options) {
|
|
|
10188
10228
|
}
|
|
10189
10229
|
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
10190
10230
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10191
|
-
|
|
10231
|
+
final: options?.final,
|
|
10232
|
+
customHtmlTags: options?.customHtmlTags,
|
|
10233
|
+
validateLink: options?.validateLink
|
|
10192
10234
|
}));
|
|
10193
10235
|
return {
|
|
10194
10236
|
node: {
|
|
@@ -10508,7 +10550,9 @@ function parseInsertToken(tokens, startIndex, options) {
|
|
|
10508
10550
|
}
|
|
10509
10551
|
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
10510
10552
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10511
|
-
|
|
10553
|
+
final: options?.final,
|
|
10554
|
+
customHtmlTags: options?.customHtmlTags,
|
|
10555
|
+
validateLink: options?.validateLink
|
|
10512
10556
|
}));
|
|
10513
10557
|
return {
|
|
10514
10558
|
node: {
|
|
@@ -10562,7 +10606,9 @@ function parseLinkToken(tokens, startIndex, options) {
|
|
|
10562
10606
|
if (tokens[i]?.type === "link_close") loading = false;
|
|
10563
10607
|
const children = parseInlineTokens(linkTokens, void 0, void 0, {
|
|
10564
10608
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10565
|
-
|
|
10609
|
+
final: options?.final,
|
|
10610
|
+
customHtmlTags: options?.customHtmlTags,
|
|
10611
|
+
validateLink: options?.validateLink
|
|
10566
10612
|
});
|
|
10567
10613
|
const linkText = children.map((node) => {
|
|
10568
10614
|
const nodeAny = node;
|
|
@@ -10622,7 +10668,9 @@ function parseStrikethroughToken(tokens, startIndex, options) {
|
|
|
10622
10668
|
}
|
|
10623
10669
|
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
10624
10670
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10625
|
-
|
|
10671
|
+
final: options?.final,
|
|
10672
|
+
customHtmlTags: options?.customHtmlTags,
|
|
10673
|
+
validateLink: options?.validateLink
|
|
10626
10674
|
}));
|
|
10627
10675
|
return {
|
|
10628
10676
|
node: {
|
|
@@ -10636,6 +10684,14 @@ function parseStrikethroughToken(tokens, startIndex, options) {
|
|
|
10636
10684
|
|
|
10637
10685
|
//#endregion
|
|
10638
10686
|
//#region src/parser/inline-parsers/strong-parser.ts
|
|
10687
|
+
const ESCAPED_PUNCTUATION_RE$1 = /\\([\\()[\]`$|*_\-!])/g;
|
|
10688
|
+
function resolveInnerRaw(raw, strongText) {
|
|
10689
|
+
if (!raw) return void 0;
|
|
10690
|
+
const rawText = String(raw);
|
|
10691
|
+
if (!rawText) return void 0;
|
|
10692
|
+
if (rawText === strongText) return rawText;
|
|
10693
|
+
if (rawText.replace(ESCAPED_PUNCTUATION_RE$1, "$1") === strongText) return rawText;
|
|
10694
|
+
}
|
|
10639
10695
|
function parseStrongToken(tokens, startIndex, raw, options) {
|
|
10640
10696
|
const children = [];
|
|
10641
10697
|
let strongText = "";
|
|
@@ -10652,8 +10708,9 @@ function parseStrongToken(tokens, startIndex, raw, options) {
|
|
|
10652
10708
|
innerTokens.push(tokens[i]);
|
|
10653
10709
|
i++;
|
|
10654
10710
|
}
|
|
10655
|
-
children.push(...parseInlineTokens(innerTokens, raw, void 0, {
|
|
10711
|
+
children.push(...parseInlineTokens(innerTokens, resolveInnerRaw(raw, strongText), void 0, {
|
|
10656
10712
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10713
|
+
final: options?.final,
|
|
10657
10714
|
customHtmlTags: options?.customHtmlTags,
|
|
10658
10715
|
validateLink: options?.validateLink
|
|
10659
10716
|
}));
|
|
@@ -10681,7 +10738,9 @@ function parseSubscriptToken(tokens, startIndex, options) {
|
|
|
10681
10738
|
}
|
|
10682
10739
|
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
10683
10740
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10684
|
-
|
|
10741
|
+
final: options?.final,
|
|
10742
|
+
customHtmlTags: options?.customHtmlTags,
|
|
10743
|
+
validateLink: options?.validateLink
|
|
10685
10744
|
}));
|
|
10686
10745
|
const startContent = String(tokens[startIndex].content ?? "");
|
|
10687
10746
|
const display = subText || startContent;
|
|
@@ -10713,7 +10772,9 @@ function parseSuperscriptToken(tokens, startIndex, options) {
|
|
|
10713
10772
|
}
|
|
10714
10773
|
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
10715
10774
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10716
|
-
|
|
10775
|
+
final: options?.final,
|
|
10776
|
+
customHtmlTags: options?.customHtmlTags,
|
|
10777
|
+
validateLink: options?.validateLink
|
|
10717
10778
|
}));
|
|
10718
10779
|
return {
|
|
10719
10780
|
node: {
|
|
@@ -10746,6 +10807,22 @@ const STRONG_PAIR_RE = /\*\*([\s\S]*?)\*\*/;
|
|
|
10746
10807
|
const STRIKETHROUGH_RE = /[^~]*~{2,}[^~]+/;
|
|
10747
10808
|
const HAS_STRONG_RE = /\*\*/;
|
|
10748
10809
|
const ESCAPED_PUNCTUATION_RE = /\\([\\()[\]`$|*_\-!])/g;
|
|
10810
|
+
const ESCAPABLE_PUNCTUATION = new Set([
|
|
10811
|
+
"\\",
|
|
10812
|
+
"(",
|
|
10813
|
+
")",
|
|
10814
|
+
"[",
|
|
10815
|
+
"]",
|
|
10816
|
+
"`",
|
|
10817
|
+
"$",
|
|
10818
|
+
"|",
|
|
10819
|
+
"*",
|
|
10820
|
+
"_",
|
|
10821
|
+
"-",
|
|
10822
|
+
"!"
|
|
10823
|
+
]);
|
|
10824
|
+
const AUTOLINK_PROTOCOL_RE = /^(?:https?:\/\/|mailto:|ftp:\/\/)/i;
|
|
10825
|
+
const AUTOLINK_GENERIC_RE = /:\/\//;
|
|
10749
10826
|
function countUnescapedAsterisks(str) {
|
|
10750
10827
|
let count = 0;
|
|
10751
10828
|
let i = 0;
|
|
@@ -10759,6 +10836,52 @@ function countUnescapedAsterisks(str) {
|
|
|
10759
10836
|
}
|
|
10760
10837
|
return count;
|
|
10761
10838
|
}
|
|
10839
|
+
function findNextUnescapedAsterisk(rawContent, startContentIndex = 0) {
|
|
10840
|
+
if (!rawContent) return -1;
|
|
10841
|
+
let contentIndex = 0;
|
|
10842
|
+
for (let rawIndex = 0; rawIndex < rawContent.length; rawIndex++) {
|
|
10843
|
+
const char = rawContent[rawIndex];
|
|
10844
|
+
const nextChar = rawContent[rawIndex + 1];
|
|
10845
|
+
if (char === "\\" && nextChar && ESCAPABLE_PUNCTUATION.has(nextChar)) {
|
|
10846
|
+
if (nextChar === "*" && contentIndex >= startContentIndex) {
|
|
10847
|
+
contentIndex++;
|
|
10848
|
+
rawIndex++;
|
|
10849
|
+
continue;
|
|
10850
|
+
}
|
|
10851
|
+
contentIndex++;
|
|
10852
|
+
rawIndex++;
|
|
10853
|
+
continue;
|
|
10854
|
+
}
|
|
10855
|
+
if (char === "*" && contentIndex >= startContentIndex) return contentIndex;
|
|
10856
|
+
contentIndex++;
|
|
10857
|
+
}
|
|
10858
|
+
return -1;
|
|
10859
|
+
}
|
|
10860
|
+
function decodeVisibleTextFromRaw(rawText) {
|
|
10861
|
+
let output = "";
|
|
10862
|
+
let index = 0;
|
|
10863
|
+
while (index < rawText.length) {
|
|
10864
|
+
if (rawText[index] !== "\\") {
|
|
10865
|
+
output += rawText[index];
|
|
10866
|
+
index++;
|
|
10867
|
+
continue;
|
|
10868
|
+
}
|
|
10869
|
+
let slashCount = 0;
|
|
10870
|
+
while (index + slashCount < rawText.length && rawText[index + slashCount] === "\\") slashCount++;
|
|
10871
|
+
const nextChar = rawText[index + slashCount];
|
|
10872
|
+
output += "\\".repeat(Math.floor(slashCount / 2));
|
|
10873
|
+
if (slashCount % 2 === 1) {
|
|
10874
|
+
if (nextChar && ESCAPABLE_PUNCTUATION.has(nextChar)) {
|
|
10875
|
+
output += nextChar;
|
|
10876
|
+
index += slashCount + 1;
|
|
10877
|
+
continue;
|
|
10878
|
+
}
|
|
10879
|
+
output += "\\";
|
|
10880
|
+
}
|
|
10881
|
+
index += slashCount;
|
|
10882
|
+
}
|
|
10883
|
+
return output;
|
|
10884
|
+
}
|
|
10762
10885
|
const WORD_CHAR_RE = /[\p{L}\p{N}]/u;
|
|
10763
10886
|
const WORD_ONLY_RE = /^[\p{L}\p{N}]+$/u;
|
|
10764
10887
|
function isWordChar(ch) {
|
|
@@ -10781,6 +10904,16 @@ function getAsteriskRunInfo(content, start) {
|
|
|
10781
10904
|
intraword: isWordChar(prev) && isWordChar(next)
|
|
10782
10905
|
};
|
|
10783
10906
|
}
|
|
10907
|
+
function isLikelyUrl(href) {
|
|
10908
|
+
if (!href) return false;
|
|
10909
|
+
return AUTOLINK_PROTOCOL_RE.test(href) || AUTOLINK_GENERIC_RE.test(href);
|
|
10910
|
+
}
|
|
10911
|
+
function recoverTrailingMarkdownLinkLabel(raw, href) {
|
|
10912
|
+
if (!raw || !href) return null;
|
|
10913
|
+
const match = raw.match(/\[([^\]\n]+)\]\(([^)]*)$/);
|
|
10914
|
+
if (!match) return null;
|
|
10915
|
+
return match[2] === href ? match[1] : null;
|
|
10916
|
+
}
|
|
10784
10917
|
function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
10785
10918
|
if (!tokens || tokens.length === 0) return [];
|
|
10786
10919
|
const result = [];
|
|
@@ -10949,7 +11082,9 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
10949
11082
|
return true;
|
|
10950
11083
|
}
|
|
10951
11084
|
if (/[^*]*\*[^*]+/.test(content)) {
|
|
10952
|
-
|
|
11085
|
+
const rawSource = tokens.length === 1 ? raw : String(token.content ?? "");
|
|
11086
|
+
let idx = rawSource ? findNextUnescapedAsterisk(rawSource, 0) : content.indexOf("*");
|
|
11087
|
+
if (rawSource && idx === -1) return false;
|
|
10953
11088
|
if (idx === -1) idx = 0;
|
|
10954
11089
|
const _text = content.slice(0, idx);
|
|
10955
11090
|
if (_text) if (currentTextNode) {
|
|
@@ -10964,8 +11099,14 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
10964
11099
|
result.push(currentTextNode);
|
|
10965
11100
|
}
|
|
10966
11101
|
const runInfo = getAsteriskRunInfo(content, idx);
|
|
10967
|
-
const closeIndex = content.indexOf("*", idx + 1);
|
|
10968
|
-
|
|
11102
|
+
const closeIndex = rawSource ? findNextUnescapedAsterisk(rawSource, idx + 1) : content.indexOf("*", idx + 1);
|
|
11103
|
+
const nextInlineToken = tokens[i + 1];
|
|
11104
|
+
if (options?.final && nextInlineToken?.type === "em_open" && closeIndex !== -1 && content.slice(idx + 1, closeIndex).trim() !== content.slice(idx + 1, closeIndex)) {
|
|
11105
|
+
pushText(content.slice(idx), content.slice(idx));
|
|
11106
|
+
i++;
|
|
11107
|
+
return true;
|
|
11108
|
+
}
|
|
11109
|
+
if (closeIndex === -1 && (options?.final || runInfo.intraword || !isWordChar(content[idx + 1]))) {
|
|
10969
11110
|
pushText(content.slice(idx), content.slice(idx));
|
|
10970
11111
|
i++;
|
|
10971
11112
|
return true;
|
|
@@ -11290,8 +11431,12 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
11290
11431
|
resetCurrentTextNode();
|
|
11291
11432
|
const displayText = String(token.text ?? "");
|
|
11292
11433
|
pushText(displayText, displayText);
|
|
11293
|
-
|
|
11294
|
-
i++;
|
|
11434
|
+
i++;
|
|
11435
|
+
} else if (recoverMarkdownLinkFromTrailingText(token)) i++;
|
|
11436
|
+
else {
|
|
11437
|
+
pushToken(token);
|
|
11438
|
+
i++;
|
|
11439
|
+
}
|
|
11295
11440
|
break;
|
|
11296
11441
|
}
|
|
11297
11442
|
}
|
|
@@ -11314,7 +11459,8 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
11314
11459
|
function handleTextToken(token) {
|
|
11315
11460
|
let index = result.length - 1;
|
|
11316
11461
|
const rawContent = String(token.content ?? "");
|
|
11317
|
-
|
|
11462
|
+
const rawSource = tokens.length === 1 && rawContent.includes("\\") && typeof raw === "string" ? String(raw) : "";
|
|
11463
|
+
let content = rawSource ? decodeVisibleTextFromRaw(rawSource) : rawContent.replace(ESCAPED_PUNCTUATION_RE, "$1");
|
|
11318
11464
|
if (token.content === "<" || content === "1" && tokens[i - 1]?.tag === "br") {
|
|
11319
11465
|
i++;
|
|
11320
11466
|
return;
|
|
@@ -11367,8 +11513,21 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
11367
11513
|
}
|
|
11368
11514
|
function handleLinkOpen(token) {
|
|
11369
11515
|
resetCurrentTextNode();
|
|
11370
|
-
const { node, nextIndex } = parseLinkToken(tokens, i,
|
|
11516
|
+
const { node, nextIndex } = parseLinkToken(tokens, i, options);
|
|
11371
11517
|
i = nextIndex;
|
|
11518
|
+
const hasSingleTextChild = node.children.length === 1 && node.children[0]?.type === "text";
|
|
11519
|
+
if (node.loading && raw && node.text === node.href && hasSingleTextChild) {
|
|
11520
|
+
const recoveredLabel = recoverTrailingMarkdownLinkLabel(raw, node.href);
|
|
11521
|
+
if (recoveredLabel) {
|
|
11522
|
+
node.text = recoveredLabel;
|
|
11523
|
+
node.children = [{
|
|
11524
|
+
type: "text",
|
|
11525
|
+
content: recoveredLabel,
|
|
11526
|
+
raw: recoveredLabel
|
|
11527
|
+
}];
|
|
11528
|
+
node.raw = String(`[${recoveredLabel}](${node.href}${node.title ? ` "${node.title}"` : ""})`);
|
|
11529
|
+
}
|
|
11530
|
+
}
|
|
11372
11531
|
if (options?.validateLink && !options.validateLink(node.href)) {
|
|
11373
11532
|
pushText(node.text, node.text);
|
|
11374
11533
|
return;
|
|
@@ -11385,23 +11544,43 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
11385
11544
|
}
|
|
11386
11545
|
}
|
|
11387
11546
|
}
|
|
11547
|
+
if (recoverMarkdownLinkFromTrailingText(node)) return;
|
|
11388
11548
|
pushParsed(node);
|
|
11389
11549
|
}
|
|
11390
11550
|
function handleReference(token) {
|
|
11391
11551
|
resetCurrentTextNode();
|
|
11392
|
-
|
|
11393
|
-
const preToken = tokens[i - 1];
|
|
11394
|
-
const preResult = result[result.length - 1];
|
|
11395
|
-
const nextIsTextNotStartingParens = nextToken?.type === "text" && !String(nextToken.content ?? "").startsWith("(");
|
|
11396
|
-
const preIsTextEndingBracketOrOnlySpace = preToken?.type === "text" && /\]$|^\s*$/.test(String(preToken.content ?? ""));
|
|
11397
|
-
if (nextIsTextNotStartingParens || preIsTextEndingBracketOrOnlySpace) pushNode(parseReferenceToken(token));
|
|
11398
|
-
else if (nextToken && nextToken.type === "text") nextToken.content = String(token.markup ?? "") + String(nextToken.content ?? "");
|
|
11399
|
-
else if (preResult && preResult.type === "text") {
|
|
11400
|
-
preResult.content = String(preResult.content ?? "") + String(token.markup ?? "");
|
|
11401
|
-
preResult.raw = String(preResult.raw ?? "") + String(token.markup ?? "");
|
|
11402
|
-
}
|
|
11552
|
+
pushNode(parseReferenceToken(token));
|
|
11403
11553
|
i++;
|
|
11404
11554
|
}
|
|
11555
|
+
function recoverMarkdownLinkFromTrailingText(token) {
|
|
11556
|
+
if (token.type !== "link") return false;
|
|
11557
|
+
const previous = result[result.length - 1];
|
|
11558
|
+
if (!previous || previous.type !== "text") return false;
|
|
11559
|
+
const match = String(previous.content ?? "").match(/^(.*)\[([^\]\n]+)\]\($/);
|
|
11560
|
+
if (!match) return false;
|
|
11561
|
+
const linkToken = token;
|
|
11562
|
+
const href = String(linkToken.href ?? "");
|
|
11563
|
+
const linkText = String(linkToken.text ?? "");
|
|
11564
|
+
const label = String(match[2] ?? "");
|
|
11565
|
+
const visibleHref = href.replace(/^(?:https?:\/\/|mailto:|ftp:\/\/)/i, "");
|
|
11566
|
+
if (!href || !(linkText === href || linkText === visibleHref || isLikelyUrl(linkText))) return false;
|
|
11567
|
+
const before = String(match[1] ?? "");
|
|
11568
|
+
if (before) {
|
|
11569
|
+
previous.content = before;
|
|
11570
|
+
previous.raw = before;
|
|
11571
|
+
} else result.pop();
|
|
11572
|
+
pushParsed({
|
|
11573
|
+
...token,
|
|
11574
|
+
text: label,
|
|
11575
|
+
children: [{
|
|
11576
|
+
type: "text",
|
|
11577
|
+
content: label,
|
|
11578
|
+
raw: label
|
|
11579
|
+
}],
|
|
11580
|
+
raw: String(`[${label}](${href}${linkToken.title ? ` "${linkToken.title}"` : ""})`)
|
|
11581
|
+
});
|
|
11582
|
+
return true;
|
|
11583
|
+
}
|
|
11405
11584
|
function handleInlineLinkContent(content, _token) {
|
|
11406
11585
|
const linkStart = content.indexOf("[");
|
|
11407
11586
|
if (linkStart === -1) return false;
|
|
@@ -11665,6 +11844,7 @@ function parseList(tokens, index, options) {
|
|
|
11665
11844
|
type: "paragraph",
|
|
11666
11845
|
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), preToken, {
|
|
11667
11846
|
requireClosingStrong: options?.requireClosingStrong,
|
|
11847
|
+
final: options?.final,
|
|
11668
11848
|
customHtmlTags: options?.customHtmlTags,
|
|
11669
11849
|
validateLink: options?.validateLink
|
|
11670
11850
|
}),
|
|
@@ -11723,6 +11903,7 @@ function parseAdmonition(tokens, index, match, options) {
|
|
|
11723
11903
|
type: "paragraph",
|
|
11724
11904
|
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
11725
11905
|
requireClosingStrong: options?.requireClosingStrong,
|
|
11906
|
+
final: options?.final,
|
|
11726
11907
|
customHtmlTags: options?.customHtmlTags,
|
|
11727
11908
|
validateLink: options?.validateLink
|
|
11728
11909
|
}),
|
|
@@ -11796,6 +11977,7 @@ function parseContainer(tokens, index, options) {
|
|
|
11796
11977
|
type: "paragraph",
|
|
11797
11978
|
children: parseInlineTokens(_children || [], void 0, void 0, {
|
|
11798
11979
|
requireClosingStrong: options?.requireClosingStrong,
|
|
11980
|
+
final: options?.final,
|
|
11799
11981
|
customHtmlTags: options?.customHtmlTags,
|
|
11800
11982
|
validateLink: options?.validateLink
|
|
11801
11983
|
}),
|
|
@@ -11854,6 +12036,7 @@ function parseBlockquote(tokens, index, options) {
|
|
|
11854
12036
|
type: "paragraph",
|
|
11855
12037
|
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
11856
12038
|
requireClosingStrong: options?.requireClosingStrong,
|
|
12039
|
+
final: options?.final,
|
|
11857
12040
|
customHtmlTags: options?.customHtmlTags,
|
|
11858
12041
|
validateLink: options?.validateLink
|
|
11859
12042
|
}),
|
|
@@ -11919,6 +12102,7 @@ function parseDefinitionList(tokens, index, options) {
|
|
|
11919
12102
|
const termToken = tokens[j + 1];
|
|
11920
12103
|
termNodes = parseInlineTokens(termToken.children || [], void 0, void 0, {
|
|
11921
12104
|
requireClosingStrong: options?.requireClosingStrong,
|
|
12105
|
+
final: options?.final,
|
|
11922
12106
|
customHtmlTags: options?.customHtmlTags,
|
|
11923
12107
|
validateLink: options?.validateLink
|
|
11924
12108
|
});
|
|
@@ -11932,6 +12116,7 @@ function parseDefinitionList(tokens, index, options) {
|
|
|
11932
12116
|
type: "paragraph",
|
|
11933
12117
|
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
11934
12118
|
requireClosingStrong: options?.requireClosingStrong,
|
|
12119
|
+
final: options?.final,
|
|
11935
12120
|
customHtmlTags: options?.customHtmlTags,
|
|
11936
12121
|
validateLink: options?.validateLink
|
|
11937
12122
|
}),
|
|
@@ -11972,6 +12157,7 @@ function parseFootnote(tokens, index, options) {
|
|
|
11972
12157
|
type: "paragraph",
|
|
11973
12158
|
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
11974
12159
|
requireClosingStrong: options?.requireClosingStrong,
|
|
12160
|
+
final: options?.final,
|
|
11975
12161
|
customHtmlTags: options?.customHtmlTags,
|
|
11976
12162
|
validateLink: options?.validateLink
|
|
11977
12163
|
}),
|
|
@@ -12004,6 +12190,7 @@ function parseHeading(tokens, index, options) {
|
|
|
12004
12190
|
...attrsRecord ? { attrs: attrsRecord } : {},
|
|
12005
12191
|
children: parseInlineTokens(headingContentToken.children || [], headingContent, void 0, {
|
|
12006
12192
|
requireClosingStrong: options?.requireClosingStrong,
|
|
12193
|
+
final: options?.final,
|
|
12007
12194
|
customHtmlTags: options?.customHtmlTags,
|
|
12008
12195
|
validateLink: options?.validateLink
|
|
12009
12196
|
}),
|
|
@@ -12120,6 +12307,7 @@ function parseTable(tokens, index, options) {
|
|
|
12120
12307
|
header: isHeaderCell || isHeader,
|
|
12121
12308
|
children: parseInlineTokens(contentToken.children || [], content, void 0, {
|
|
12122
12309
|
requireClosingStrong: options?.requireClosingStrong,
|
|
12310
|
+
final: options?.final,
|
|
12123
12311
|
customHtmlTags: options?.customHtmlTags,
|
|
12124
12312
|
validateLink: options?.validateLink
|
|
12125
12313
|
}),
|
|
@@ -12195,7 +12383,8 @@ function getHtmlTagSets(customTags) {
|
|
|
12195
12383
|
return entry;
|
|
12196
12384
|
}
|
|
12197
12385
|
function parseVmrContainer(tokens, index, options) {
|
|
12198
|
-
const
|
|
12386
|
+
const openToken = tokens[index];
|
|
12387
|
+
const attrs = openToken.attrs;
|
|
12199
12388
|
let name = "";
|
|
12200
12389
|
const containerAttrs = {};
|
|
12201
12390
|
if (attrs) {
|
|
@@ -12221,6 +12410,7 @@ function parseVmrContainer(tokens, index, options) {
|
|
|
12221
12410
|
type: "paragraph",
|
|
12222
12411
|
children: parseInlineTokens(childrenArr || [], void 0, void 0, {
|
|
12223
12412
|
requireClosingStrong: options?.requireClosingStrong,
|
|
12413
|
+
final: options?.final,
|
|
12224
12414
|
customHtmlTags: options?.customHtmlTags,
|
|
12225
12415
|
validateLink: options?.validateLink
|
|
12226
12416
|
}),
|
|
@@ -12249,7 +12439,7 @@ function parseVmrContainer(tokens, index, options) {
|
|
|
12249
12439
|
if (Object.keys(containerAttrs).length > 0) raw += ` ${JSON.stringify(containerAttrs)}`;
|
|
12250
12440
|
raw += "\n";
|
|
12251
12441
|
if (children.length > 0) {
|
|
12252
|
-
raw += children.map((c) => c.raw).join("\n");
|
|
12442
|
+
raw += openToken.raw ?? children.map((c) => c.raw).join("\n");
|
|
12253
12443
|
raw += "\n";
|
|
12254
12444
|
}
|
|
12255
12445
|
raw += ":::";
|
|
@@ -12485,6 +12675,7 @@ function parseParagraph(tokens, index, options) {
|
|
|
12485
12675
|
type: "paragraph",
|
|
12486
12676
|
children: parseInlineTokens(paragraphContentToken.children || [], paragraphContent, void 0, {
|
|
12487
12677
|
requireClosingStrong: options?.requireClosingStrong,
|
|
12678
|
+
final: options?.final,
|
|
12488
12679
|
customHtmlTags: options?.customHtmlTags,
|
|
12489
12680
|
validateLink: options?.validateLink
|
|
12490
12681
|
}),
|
|
@@ -13317,6 +13508,7 @@ function processTokens(tokens, options) {
|
|
|
13317
13508
|
{
|
|
13318
13509
|
const parsed = parseInlineTokens(token.children || [], String(token.content ?? ""), void 0, {
|
|
13319
13510
|
requireClosingStrong: options?.requireClosingStrong,
|
|
13511
|
+
final: options?.final,
|
|
13320
13512
|
customHtmlTags: options?.customHtmlTags,
|
|
13321
13513
|
validateLink: options?.validateLink
|
|
13322
13514
|
});
|
|
@@ -13440,6 +13632,15 @@ function getMarkdown(msgId = `editor-${Date.now()}`, options = {}) {
|
|
|
13440
13632
|
</div>`;
|
|
13441
13633
|
};
|
|
13442
13634
|
const RE_REFERENCE = /^\[(\d+)\]/;
|
|
13635
|
+
const RE_REFERENCE_LABEL = /^\[([^\]\n]+)\]/;
|
|
13636
|
+
const shouldPreserveReferenceStyleLink = (afterMatch) => {
|
|
13637
|
+
if (!afterMatch.startsWith("[")) return false;
|
|
13638
|
+
const nextLabelMatch = RE_REFERENCE_LABEL.exec(afterMatch);
|
|
13639
|
+
if (!nextLabelMatch) return afterMatch !== "[" && !/^\[\d+$/.test(afterMatch);
|
|
13640
|
+
const nextLabel = String(nextLabelMatch[1] ?? "");
|
|
13641
|
+
if (afterMatch.slice(nextLabelMatch[0].length).startsWith("(")) return false;
|
|
13642
|
+
return !/^\d+$/.test(nextLabel);
|
|
13643
|
+
};
|
|
13443
13644
|
const referenceInline = (state, silent) => {
|
|
13444
13645
|
const s = state;
|
|
13445
13646
|
if (s.src[s.pos] !== "[") return false;
|
|
@@ -13448,7 +13649,7 @@ function getMarkdown(msgId = `editor-${Date.now()}`, options = {}) {
|
|
|
13448
13649
|
const lookbehind = s.src.slice(Math.max(0, s.pos - 120), s.pos);
|
|
13449
13650
|
if (/"[^"\n]{1,80}"\s*:\s*$/.test(lookbehind)) return false;
|
|
13450
13651
|
const afterMatch = s.src.slice(s.pos + match[0].length);
|
|
13451
|
-
if (afterMatch.startsWith("](") || afterMatch.startsWith("(") || afterMatch
|
|
13652
|
+
if (afterMatch.startsWith("](") || afterMatch.startsWith("(") || shouldPreserveReferenceStyleLink(afterMatch)) return false;
|
|
13452
13653
|
if (!silent) {
|
|
13453
13654
|
const id = match[1];
|
|
13454
13655
|
const token = s.push("reference", "span", 0);
|