stream-markdown-parser 0.0.69 → 0.0.71
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 +320 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,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,CAAA,MAAA,EAAoB,MAAA,GAAA,OAAA,CAAA;EAK3B,QAAA,EAjFE,UAiFF,EAAA;;AALmC,UAzE5B,aAAA,SAAsB,QAyEM,CAAA;EAAQ,IAAA,EAAA,WAAA;EAU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A,MAAA,EAAA,MAAA,CAAA,EAAA,GAhOA,MAgOA,CAAA,MAAA,EAAA,MAAA,GAAA,OAAA,CAAA,GA/NA,KA+NA,CAAA;EACA,IAAA,EAAA,MAAA;EACA,KAAA,EAAA,MAAA,GAAA,OAAA;CACA,CAAA,GAAA,IAAA;;;;;;;AAOA,UAhOW,mBAAA,SAA4B,QAgOvC,CAAA;EACA;EACA,IAAA,EAAA,MAAA;EACA,GAAA,EAAA,MAAA;EACA,OAAA,EAAA,MAAA;EACA,KAAA,CAAA,EAhOI,oBAgOJ;EACA,QAAA,CAAA,EAhOO,UAgOP,EAAA;EACA,UAAA,CAAA,EAAA,OAAA;;AAEA,UA/NW,cAAA,SAAuB,QA+NlC,CAAA;EACA,IAAA,EAAA,aAAA;EACA,IAAA,EAAA,MAAA;;AAEA,UA9NW,QAAA,SAAiB,QA8N5B,CAAA;EACA,IAAA,EAAA,MAAA;EACA,IAAA,EAAA,MAAA;EACA,KAAA,EAAA,MAAA,GAAA,IAAA;EACA,IAAA,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":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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);
|
|
@@ -9556,9 +9558,11 @@ function applyMath(md, mathOpts) {
|
|
|
9556
9558
|
["$", "$"],
|
|
9557
9559
|
["\\(", "\\)"]
|
|
9558
9560
|
];
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
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;
|
|
9562
9566
|
for (const [open, close] of delimiters) {
|
|
9563
9567
|
const src = s.src;
|
|
9564
9568
|
const codeSpanRanges = buildCodeSpanRanges(src);
|
|
@@ -10680,6 +10684,14 @@ function parseStrikethroughToken(tokens, startIndex, options) {
|
|
|
10680
10684
|
|
|
10681
10685
|
//#endregion
|
|
10682
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
|
+
}
|
|
10683
10695
|
function parseStrongToken(tokens, startIndex, raw, options) {
|
|
10684
10696
|
const children = [];
|
|
10685
10697
|
let strongText = "";
|
|
@@ -10696,7 +10708,7 @@ function parseStrongToken(tokens, startIndex, raw, options) {
|
|
|
10696
10708
|
innerTokens.push(tokens[i]);
|
|
10697
10709
|
i++;
|
|
10698
10710
|
}
|
|
10699
|
-
children.push(...parseInlineTokens(innerTokens, raw, void 0, {
|
|
10711
|
+
children.push(...parseInlineTokens(innerTokens, resolveInnerRaw(raw, strongText), void 0, {
|
|
10700
10712
|
requireClosingStrong: options?.requireClosingStrong,
|
|
10701
10713
|
final: options?.final,
|
|
10702
10714
|
customHtmlTags: options?.customHtmlTags,
|
|
@@ -10809,6 +10821,8 @@ const ESCAPABLE_PUNCTUATION = new Set([
|
|
|
10809
10821
|
"-",
|
|
10810
10822
|
"!"
|
|
10811
10823
|
]);
|
|
10824
|
+
const AUTOLINK_PROTOCOL_RE = /^(?:https?:\/\/|mailto:|ftp:\/\/)/i;
|
|
10825
|
+
const AUTOLINK_GENERIC_RE = /:\/\//;
|
|
10812
10826
|
function countUnescapedAsterisks(str) {
|
|
10813
10827
|
let count = 0;
|
|
10814
10828
|
let i = 0;
|
|
@@ -10890,6 +10904,16 @@ function getAsteriskRunInfo(content, start) {
|
|
|
10890
10904
|
intraword: isWordChar(prev) && isWordChar(next)
|
|
10891
10905
|
};
|
|
10892
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
|
+
}
|
|
10893
10917
|
function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
10894
10918
|
if (!tokens || tokens.length === 0) return [];
|
|
10895
10919
|
const result = [];
|
|
@@ -11407,8 +11431,12 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
11407
11431
|
resetCurrentTextNode();
|
|
11408
11432
|
const displayText = String(token.text ?? "");
|
|
11409
11433
|
pushText(displayText, displayText);
|
|
11410
|
-
|
|
11411
|
-
i++;
|
|
11434
|
+
i++;
|
|
11435
|
+
} else if (recoverMarkdownLinkFromTrailingText(token)) i++;
|
|
11436
|
+
else {
|
|
11437
|
+
pushToken(token);
|
|
11438
|
+
i++;
|
|
11439
|
+
}
|
|
11412
11440
|
break;
|
|
11413
11441
|
}
|
|
11414
11442
|
}
|
|
@@ -11487,6 +11515,19 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
11487
11515
|
resetCurrentTextNode();
|
|
11488
11516
|
const { node, nextIndex } = parseLinkToken(tokens, i, options);
|
|
11489
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
|
+
}
|
|
11490
11531
|
if (options?.validateLink && !options.validateLink(node.href)) {
|
|
11491
11532
|
pushText(node.text, node.text);
|
|
11492
11533
|
return;
|
|
@@ -11503,23 +11544,43 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
11503
11544
|
}
|
|
11504
11545
|
}
|
|
11505
11546
|
}
|
|
11547
|
+
if (recoverMarkdownLinkFromTrailingText(node)) return;
|
|
11506
11548
|
pushParsed(node);
|
|
11507
11549
|
}
|
|
11508
11550
|
function handleReference(token) {
|
|
11509
11551
|
resetCurrentTextNode();
|
|
11510
|
-
|
|
11511
|
-
const preToken = tokens[i - 1];
|
|
11512
|
-
const preResult = result[result.length - 1];
|
|
11513
|
-
const nextIsTextNotStartingParens = nextToken?.type === "text" && !String(nextToken.content ?? "").startsWith("(");
|
|
11514
|
-
const preIsTextEndingBracketOrOnlySpace = preToken?.type === "text" && /\]$|^\s*$/.test(String(preToken.content ?? ""));
|
|
11515
|
-
if (nextIsTextNotStartingParens || preIsTextEndingBracketOrOnlySpace) pushNode(parseReferenceToken(token));
|
|
11516
|
-
else if (nextToken && nextToken.type === "text") nextToken.content = String(token.markup ?? "") + String(nextToken.content ?? "");
|
|
11517
|
-
else if (preResult && preResult.type === "text") {
|
|
11518
|
-
preResult.content = String(preResult.content ?? "") + String(token.markup ?? "");
|
|
11519
|
-
preResult.raw = String(preResult.raw ?? "") + String(token.markup ?? "");
|
|
11520
|
-
}
|
|
11552
|
+
pushNode(parseReferenceToken(token));
|
|
11521
11553
|
i++;
|
|
11522
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
|
+
}
|
|
11523
11584
|
function handleInlineLinkContent(content, _token) {
|
|
11524
11585
|
const linkStart = content.indexOf("[");
|
|
11525
11586
|
if (linkStart === -1) return false;
|
|
@@ -12322,7 +12383,8 @@ function getHtmlTagSets(customTags) {
|
|
|
12322
12383
|
return entry;
|
|
12323
12384
|
}
|
|
12324
12385
|
function parseVmrContainer(tokens, index, options) {
|
|
12325
|
-
const
|
|
12386
|
+
const openToken = tokens[index];
|
|
12387
|
+
const attrs = openToken.attrs;
|
|
12326
12388
|
let name = "";
|
|
12327
12389
|
const containerAttrs = {};
|
|
12328
12390
|
if (attrs) {
|
|
@@ -12377,7 +12439,7 @@ function parseVmrContainer(tokens, index, options) {
|
|
|
12377
12439
|
if (Object.keys(containerAttrs).length > 0) raw += ` ${JSON.stringify(containerAttrs)}`;
|
|
12378
12440
|
raw += "\n";
|
|
12379
12441
|
if (children.length > 0) {
|
|
12380
|
-
raw += children.map((c) => c.raw).join("\n");
|
|
12442
|
+
raw += openToken.raw ?? children.map((c) => c.raw).join("\n");
|
|
12381
12443
|
raw += "\n";
|
|
12382
12444
|
}
|
|
12383
12445
|
raw += ":::";
|
|
@@ -12707,6 +12769,12 @@ function normalizeTagName(t) {
|
|
|
12707
12769
|
const m = raw.match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
12708
12770
|
return m ? m[1].toLowerCase() : "";
|
|
12709
12771
|
}
|
|
12772
|
+
function getCustomHtmlTagSet(options) {
|
|
12773
|
+
const custom = options?.customHtmlTags;
|
|
12774
|
+
if (!Array.isArray(custom) || custom.length === 0) return null;
|
|
12775
|
+
const normalized = custom.map(normalizeTagName).filter(Boolean);
|
|
12776
|
+
return normalized.length ? new Set(normalized) : null;
|
|
12777
|
+
}
|
|
12710
12778
|
function buildAllowedHtmlTagSet(options) {
|
|
12711
12779
|
const custom = options?.customHtmlTags;
|
|
12712
12780
|
if (!Array.isArray(custom) || custom.length === 0) return STANDARD_HTML_TAGS;
|
|
@@ -12717,6 +12785,48 @@ function buildAllowedHtmlTagSet(options) {
|
|
|
12717
12785
|
}
|
|
12718
12786
|
return set;
|
|
12719
12787
|
}
|
|
12788
|
+
function stringifyInlineNodeRaw(node) {
|
|
12789
|
+
const raw = node?.raw;
|
|
12790
|
+
if (typeof raw === "string") return raw;
|
|
12791
|
+
const content = node?.content;
|
|
12792
|
+
if (typeof content === "string") return content;
|
|
12793
|
+
if (node?.type === "hardbreak") return "<br>";
|
|
12794
|
+
return "";
|
|
12795
|
+
}
|
|
12796
|
+
function buildParagraphFromInlineChildren(children) {
|
|
12797
|
+
return {
|
|
12798
|
+
type: "paragraph",
|
|
12799
|
+
children,
|
|
12800
|
+
raw: children.map(stringifyInlineNodeRaw).join("")
|
|
12801
|
+
};
|
|
12802
|
+
}
|
|
12803
|
+
function maybePromoteCustomNodeFromParagraph(node, options) {
|
|
12804
|
+
if (node.type !== "paragraph") return null;
|
|
12805
|
+
const children = Array.isArray(node.children) ? node.children : [];
|
|
12806
|
+
if (children.length === 0) return null;
|
|
12807
|
+
const customTagSet = getCustomHtmlTagSet(options);
|
|
12808
|
+
if (!customTagSet?.size) return null;
|
|
12809
|
+
let customIndex = -1;
|
|
12810
|
+
for (let i = 0; i < children.length; i++) {
|
|
12811
|
+
const child = children[i];
|
|
12812
|
+
if (!customTagSet.has(String(child?.type ?? "").toLowerCase())) continue;
|
|
12813
|
+
const prefixChildren$1 = children.slice(0, i);
|
|
12814
|
+
if (!String(child?.content ?? "").trim()) continue;
|
|
12815
|
+
if (!prefixChildren$1.some((prefixChild) => prefixChild?.type === "hardbreak")) continue;
|
|
12816
|
+
customIndex = i;
|
|
12817
|
+
break;
|
|
12818
|
+
}
|
|
12819
|
+
if (customIndex === -1) return null;
|
|
12820
|
+
const prefixChildren = children.slice(0, customIndex);
|
|
12821
|
+
const promoted = children[customIndex];
|
|
12822
|
+
if (!promoted) return null;
|
|
12823
|
+
const result = [];
|
|
12824
|
+
if (prefixChildren.length) result.push(buildParagraphFromInlineChildren(prefixChildren));
|
|
12825
|
+
result.push(promoted);
|
|
12826
|
+
const suffixChildren = children.slice(customIndex + 1);
|
|
12827
|
+
if (suffixChildren.length) result.push(buildParagraphFromInlineChildren(suffixChildren));
|
|
12828
|
+
return result;
|
|
12829
|
+
}
|
|
12720
12830
|
function parseStandaloneHtmlDocument(markdown) {
|
|
12721
12831
|
const trimmed = markdown.trim();
|
|
12722
12832
|
if (!trimmed) return null;
|
|
@@ -12874,6 +12984,170 @@ function stripDanglingHtmlLikeTail(markdown) {
|
|
|
12874
12984
|
if (!isLikelyHtmlTagPrefix(tail)) return s;
|
|
12875
12985
|
return s.slice(0, lastLt);
|
|
12876
12986
|
}
|
|
12987
|
+
function ensureBlankLineBeforeInlineMultilineCustomHtmlBlocks(markdown, tags) {
|
|
12988
|
+
if (!markdown || !tags.length) return markdown;
|
|
12989
|
+
const tagSet = new Set(tags.map((t) => String(t ?? "").toLowerCase()).filter(Boolean));
|
|
12990
|
+
if (!tagSet.size) return markdown;
|
|
12991
|
+
const isIndentWs = (ch) => ch === " " || ch === " ";
|
|
12992
|
+
const isNameChar = (ch) => {
|
|
12993
|
+
const c = ch.charCodeAt(0);
|
|
12994
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122 || c >= 48 && c <= 57 || ch === "_" || ch === "-" || ch === ":";
|
|
12995
|
+
};
|
|
12996
|
+
const isIndentedCodeLine = (line) => {
|
|
12997
|
+
if (!line) return false;
|
|
12998
|
+
if (line[0] === " ") return true;
|
|
12999
|
+
let spaces = 0;
|
|
13000
|
+
for (let i = 0; i < line.length; i++) {
|
|
13001
|
+
const ch = line[i];
|
|
13002
|
+
if (ch === " ") {
|
|
13003
|
+
spaces++;
|
|
13004
|
+
if (spaces >= 4) return true;
|
|
13005
|
+
continue;
|
|
13006
|
+
}
|
|
13007
|
+
if (ch === " ") return true;
|
|
13008
|
+
break;
|
|
13009
|
+
}
|
|
13010
|
+
return false;
|
|
13011
|
+
};
|
|
13012
|
+
const findTagCloseIndexOutsideQuotes$2 = (input) => {
|
|
13013
|
+
let inSingle = false;
|
|
13014
|
+
let inDouble = false;
|
|
13015
|
+
for (let i = 0; i < input.length; i++) {
|
|
13016
|
+
const ch = input[i];
|
|
13017
|
+
if (ch === "\\") {
|
|
13018
|
+
i++;
|
|
13019
|
+
continue;
|
|
13020
|
+
}
|
|
13021
|
+
if (!inDouble && ch === "'") {
|
|
13022
|
+
inSingle = !inSingle;
|
|
13023
|
+
continue;
|
|
13024
|
+
}
|
|
13025
|
+
if (!inSingle && ch === "\"") {
|
|
13026
|
+
inDouble = !inDouble;
|
|
13027
|
+
continue;
|
|
13028
|
+
}
|
|
13029
|
+
if (!inSingle && !inDouble && ch === ">") return i;
|
|
13030
|
+
}
|
|
13031
|
+
return -1;
|
|
13032
|
+
};
|
|
13033
|
+
const parseFenceMarker = (line) => {
|
|
13034
|
+
let i = 0;
|
|
13035
|
+
while (i < line.length && isIndentWs(line[i])) i++;
|
|
13036
|
+
const ch = line[i];
|
|
13037
|
+
if (ch !== "`" && ch !== "~") return null;
|
|
13038
|
+
let j = i;
|
|
13039
|
+
while (j < line.length && line[j] === ch) j++;
|
|
13040
|
+
const len = j - i;
|
|
13041
|
+
if (len < 3) return null;
|
|
13042
|
+
return {
|
|
13043
|
+
markerChar: ch,
|
|
13044
|
+
markerLen: len,
|
|
13045
|
+
rest: line.slice(j)
|
|
13046
|
+
};
|
|
13047
|
+
};
|
|
13048
|
+
const findInlineCustomBlockSplitIndex = (line, lineStart) => {
|
|
13049
|
+
if (isIndentedCodeLine(line)) return -1;
|
|
13050
|
+
const trimmed = line.replace(/^[ \t]+/, "");
|
|
13051
|
+
if (!trimmed || trimmed.startsWith(">") || trimmed.startsWith("|") || /^(?:[*+-]|\d+[.)])[\t ]+/.test(trimmed)) return -1;
|
|
13052
|
+
let hasRenderablePrefix = false;
|
|
13053
|
+
let i = 0;
|
|
13054
|
+
while (i < line.length) {
|
|
13055
|
+
const ch = line[i];
|
|
13056
|
+
if (ch !== "<") {
|
|
13057
|
+
if (!isIndentWs(ch)) hasRenderablePrefix = true;
|
|
13058
|
+
i++;
|
|
13059
|
+
continue;
|
|
13060
|
+
}
|
|
13061
|
+
const closeIdxRel = findTagCloseIndexOutsideQuotes$2(line.slice(i));
|
|
13062
|
+
if (closeIdxRel === -1) {
|
|
13063
|
+
hasRenderablePrefix = true;
|
|
13064
|
+
i++;
|
|
13065
|
+
continue;
|
|
13066
|
+
}
|
|
13067
|
+
const tagSlice = line.slice(i, i + closeIdxRel + 1);
|
|
13068
|
+
let cursor = 1;
|
|
13069
|
+
while (cursor < tagSlice.length && isIndentWs(tagSlice[cursor])) cursor++;
|
|
13070
|
+
if (cursor >= tagSlice.length) {
|
|
13071
|
+
hasRenderablePrefix = true;
|
|
13072
|
+
i++;
|
|
13073
|
+
continue;
|
|
13074
|
+
}
|
|
13075
|
+
const marker = tagSlice[cursor];
|
|
13076
|
+
if (marker === "!" || marker === "?") {
|
|
13077
|
+
hasRenderablePrefix = true;
|
|
13078
|
+
i += closeIdxRel + 1;
|
|
13079
|
+
continue;
|
|
13080
|
+
}
|
|
13081
|
+
if (marker === "/") {
|
|
13082
|
+
hasRenderablePrefix = true;
|
|
13083
|
+
i += closeIdxRel + 1;
|
|
13084
|
+
continue;
|
|
13085
|
+
}
|
|
13086
|
+
const nameStart = cursor;
|
|
13087
|
+
while (cursor < tagSlice.length && isNameChar(tagSlice[cursor])) cursor++;
|
|
13088
|
+
if (cursor === nameStart) {
|
|
13089
|
+
hasRenderablePrefix = true;
|
|
13090
|
+
i++;
|
|
13091
|
+
continue;
|
|
13092
|
+
}
|
|
13093
|
+
const tagName = tagSlice.slice(nameStart, cursor).toLowerCase();
|
|
13094
|
+
const boundary = tagSlice[cursor];
|
|
13095
|
+
if (boundary && boundary !== " " && boundary !== " " && boundary !== ">" && boundary !== "/") {
|
|
13096
|
+
hasRenderablePrefix = true;
|
|
13097
|
+
i++;
|
|
13098
|
+
continue;
|
|
13099
|
+
}
|
|
13100
|
+
const sameLineCloseRe = new RegExp(String.raw`<\s*\/\s*${tagName}\s*>`, "i");
|
|
13101
|
+
const selfClosing = /\/\s*>$/.test(tagSlice);
|
|
13102
|
+
const closesOnSameLine = sameLineCloseRe.test(line.slice(i + closeIdxRel + 1));
|
|
13103
|
+
const closesLater = sameLineCloseRe.test(markdown.slice(lineStart + i + closeIdxRel + 1));
|
|
13104
|
+
const continuesOnLaterLine = /[\r\n]/.test(markdown.slice(lineStart + i + closeIdxRel + 1));
|
|
13105
|
+
if (hasRenderablePrefix && tagSet.has(tagName) && !selfClosing && !closesOnSameLine && (closesLater || continuesOnLaterLine)) return i;
|
|
13106
|
+
hasRenderablePrefix = true;
|
|
13107
|
+
i += closeIdxRel + 1;
|
|
13108
|
+
}
|
|
13109
|
+
return -1;
|
|
13110
|
+
};
|
|
13111
|
+
let inFence = false;
|
|
13112
|
+
let fenceChar = "";
|
|
13113
|
+
let fenceLen = 0;
|
|
13114
|
+
let out = "";
|
|
13115
|
+
let idx = 0;
|
|
13116
|
+
while (idx < markdown.length) {
|
|
13117
|
+
const nl = markdown.indexOf("\n", idx);
|
|
13118
|
+
const hasNl = nl !== -1;
|
|
13119
|
+
const isCrlf = hasNl && nl > idx && markdown[nl - 1] === "\r";
|
|
13120
|
+
const lineEnd = hasNl ? isCrlf ? nl - 1 : nl : markdown.length;
|
|
13121
|
+
const line = markdown.slice(idx, lineEnd);
|
|
13122
|
+
const newline$1 = hasNl ? isCrlf ? "\r\n" : "\n" : "";
|
|
13123
|
+
const fenceMatch = parseFenceMarker(line);
|
|
13124
|
+
let nextLine = line;
|
|
13125
|
+
if (!inFence && !fenceMatch) {
|
|
13126
|
+
const splitAt = findInlineCustomBlockSplitIndex(line, idx);
|
|
13127
|
+
if (splitAt !== -1) {
|
|
13128
|
+
const separator = newline$1 || "\n";
|
|
13129
|
+
nextLine = `${line.slice(0, splitAt).replace(/[ \t]+$/, "")}${separator}${separator}${line.slice(splitAt).replace(/^[ \t]+/, "")}`;
|
|
13130
|
+
}
|
|
13131
|
+
}
|
|
13132
|
+
out += nextLine;
|
|
13133
|
+
out += newline$1;
|
|
13134
|
+
if (fenceMatch) if (inFence) {
|
|
13135
|
+
if (fenceMatch.markerChar === fenceChar && fenceMatch.markerLen >= fenceLen) {
|
|
13136
|
+
if (/^\s*$/.test(fenceMatch.rest)) {
|
|
13137
|
+
inFence = false;
|
|
13138
|
+
fenceChar = "";
|
|
13139
|
+
fenceLen = 0;
|
|
13140
|
+
}
|
|
13141
|
+
}
|
|
13142
|
+
} else {
|
|
13143
|
+
inFence = true;
|
|
13144
|
+
fenceChar = fenceMatch.markerChar;
|
|
13145
|
+
fenceLen = fenceMatch.markerLen;
|
|
13146
|
+
}
|
|
13147
|
+
idx = hasNl ? nl + 1 : markdown.length;
|
|
13148
|
+
}
|
|
13149
|
+
return out;
|
|
13150
|
+
}
|
|
12877
13151
|
function normalizeCustomHtmlOpeningTagSameLine(markdown, tags) {
|
|
12878
13152
|
if (!markdown || !tags.length) return markdown;
|
|
12879
13153
|
const tagSet = new Set(tags.map((t) => String(t ?? "").toLowerCase()));
|
|
@@ -13335,6 +13609,7 @@ function parseMarkdownToStructure(markdown, md, options = {}) {
|
|
|
13335
13609
|
return (t.match(/^[<\s/]*([A-Z][\w-]*)/i)?.[1] ?? "").toLowerCase();
|
|
13336
13610
|
}).filter(Boolean);
|
|
13337
13611
|
if (tags.length) {
|
|
13612
|
+
safeMarkdown = ensureBlankLineBeforeInlineMultilineCustomHtmlBlocks(safeMarkdown, tags);
|
|
13338
13613
|
safeMarkdown = normalizeCustomHtmlOpeningTagSameLine(safeMarkdown, tags);
|
|
13339
13614
|
safeMarkdown = ensureBlankLineBeforeCustomHtmlBlocks(safeMarkdown, tags);
|
|
13340
13615
|
safeMarkdown = ensureBlankLineAfterCustomHtmlCloseBeforeBlockMarkerSameLine(safeMarkdown, tags);
|
|
@@ -13396,10 +13671,14 @@ function processTokens(tokens, options) {
|
|
|
13396
13671
|
}
|
|
13397
13672
|
const token = tokens[i];
|
|
13398
13673
|
switch (token.type) {
|
|
13399
|
-
case "paragraph_open":
|
|
13400
|
-
|
|
13674
|
+
case "paragraph_open": {
|
|
13675
|
+
const paragraphNode = parseParagraph(tokens, i, options);
|
|
13676
|
+
const promoted = maybePromoteCustomNodeFromParagraph(paragraphNode, options);
|
|
13677
|
+
if (promoted) result.push(...promoted);
|
|
13678
|
+
else result.push(paragraphNode);
|
|
13401
13679
|
i += 3;
|
|
13402
13680
|
break;
|
|
13681
|
+
}
|
|
13403
13682
|
case "bullet_list_open":
|
|
13404
13683
|
case "ordered_list_open": {
|
|
13405
13684
|
const [listNode, newIndex] = parseList(tokens, i, options);
|
|
@@ -13451,11 +13730,16 @@ function processTokens(tokens, options) {
|
|
|
13451
13730
|
validateLink: options?.validateLink
|
|
13452
13731
|
});
|
|
13453
13732
|
if (parsed.length === 0) {} else if (parsed.every((n) => n.type === "html_block")) result.push(...parsed);
|
|
13454
|
-
else
|
|
13455
|
-
|
|
13456
|
-
|
|
13457
|
-
|
|
13458
|
-
|
|
13733
|
+
else {
|
|
13734
|
+
const paragraphNode = {
|
|
13735
|
+
type: "paragraph",
|
|
13736
|
+
raw: String(token.content ?? ""),
|
|
13737
|
+
children: parsed
|
|
13738
|
+
};
|
|
13739
|
+
const promoted = maybePromoteCustomNodeFromParagraph(paragraphNode, options);
|
|
13740
|
+
if (promoted) result.push(...promoted);
|
|
13741
|
+
else result.push(paragraphNode);
|
|
13742
|
+
}
|
|
13459
13743
|
}
|
|
13460
13744
|
i += 1;
|
|
13461
13745
|
break;
|
|
@@ -13570,6 +13854,15 @@ function getMarkdown(msgId = `editor-${Date.now()}`, options = {}) {
|
|
|
13570
13854
|
</div>`;
|
|
13571
13855
|
};
|
|
13572
13856
|
const RE_REFERENCE = /^\[(\d+)\]/;
|
|
13857
|
+
const RE_REFERENCE_LABEL = /^\[([^\]\n]+)\]/;
|
|
13858
|
+
const shouldPreserveReferenceStyleLink = (afterMatch) => {
|
|
13859
|
+
if (!afterMatch.startsWith("[")) return false;
|
|
13860
|
+
const nextLabelMatch = RE_REFERENCE_LABEL.exec(afterMatch);
|
|
13861
|
+
if (!nextLabelMatch) return afterMatch !== "[" && !/^\[\d+$/.test(afterMatch);
|
|
13862
|
+
const nextLabel = String(nextLabelMatch[1] ?? "");
|
|
13863
|
+
if (afterMatch.slice(nextLabelMatch[0].length).startsWith("(")) return false;
|
|
13864
|
+
return !/^\d+$/.test(nextLabel);
|
|
13865
|
+
};
|
|
13573
13866
|
const referenceInline = (state, silent) => {
|
|
13574
13867
|
const s = state;
|
|
13575
13868
|
if (s.src[s.pos] !== "[") return false;
|
|
@@ -13578,7 +13871,7 @@ function getMarkdown(msgId = `editor-${Date.now()}`, options = {}) {
|
|
|
13578
13871
|
const lookbehind = s.src.slice(Math.max(0, s.pos - 120), s.pos);
|
|
13579
13872
|
if (/"[^"\n]{1,80}"\s*:\s*$/.test(lookbehind)) return false;
|
|
13580
13873
|
const afterMatch = s.src.slice(s.pos + match[0].length);
|
|
13581
|
-
if (afterMatch.startsWith("](") || afterMatch.startsWith("(") || afterMatch
|
|
13874
|
+
if (afterMatch.startsWith("](") || afterMatch.startsWith("(") || shouldPreserveReferenceStyleLink(afterMatch)) return false;
|
|
13582
13875
|
if (!silent) {
|
|
13583
13876
|
const id = match[1];
|
|
13584
13877
|
const token = s.push("reference", "span", 0);
|