stream-markdown-parser 0.0.70 → 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 +230 -8
- 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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/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;EAUpC,QAAA,EAjFL,UAiFoB,EAAA;EAKf,aAAS,CAAA,EAAA,OAMd;AAGZ;AAOiB,UAlGA,UAAA,SAAmB,QAkGO,CAAQ;EAIlC,IAAA,EAAA,QAAA;EASL,QAAA,EA7GA,UA6Gc,EAAA;EAST,OAAA,CAAA,EAAA,MAAA;AAKjB;AAEU,UAzHO,QAAA,SAAiB,QAyHxB,CAAA;EACF,IAAA,EAAA,MAAA;EAH2B,OAAA,EAAA,OAAA;EAAQ,KAAA,CAAA,EAAA,M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BSlDM,WAAA,CTkDN,KAAA,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,ESlDmE,kBTkDnE,CAAA,ESlD0F,UTkD1F"}
|
package/dist/index.js
CHANGED
|
@@ -11556,7 +11556,7 @@ function parseInlineTokens(tokens, raw, pPreToken, options) {
|
|
|
11556
11556
|
if (token.type !== "link") return false;
|
|
11557
11557
|
const previous = result[result.length - 1];
|
|
11558
11558
|
if (!previous || previous.type !== "text") return false;
|
|
11559
|
-
const match = String(previous.content ?? "").match(/^(
|
|
11559
|
+
const match = String(previous.content ?? "").match(/^([^[]*)\[([^\]\n]+)\]\($/);
|
|
11560
11560
|
if (!match) return false;
|
|
11561
11561
|
const linkToken = token;
|
|
11562
11562
|
const href = String(linkToken.href ?? "");
|
|
@@ -12769,6 +12769,12 @@ function normalizeTagName(t) {
|
|
|
12769
12769
|
const m = raw.match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
12770
12770
|
return m ? m[1].toLowerCase() : "";
|
|
12771
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
|
+
}
|
|
12772
12778
|
function buildAllowedHtmlTagSet(options) {
|
|
12773
12779
|
const custom = options?.customHtmlTags;
|
|
12774
12780
|
if (!Array.isArray(custom) || custom.length === 0) return STANDARD_HTML_TAGS;
|
|
@@ -12779,6 +12785,48 @@ function buildAllowedHtmlTagSet(options) {
|
|
|
12779
12785
|
}
|
|
12780
12786
|
return set;
|
|
12781
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
|
+
}
|
|
12782
12830
|
function parseStandaloneHtmlDocument(markdown) {
|
|
12783
12831
|
const trimmed = markdown.trim();
|
|
12784
12832
|
if (!trimmed) return null;
|
|
@@ -12936,6 +12984,170 @@ function stripDanglingHtmlLikeTail(markdown) {
|
|
|
12936
12984
|
if (!isLikelyHtmlTagPrefix(tail)) return s;
|
|
12937
12985
|
return s.slice(0, lastLt);
|
|
12938
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
|
+
}
|
|
12939
13151
|
function normalizeCustomHtmlOpeningTagSameLine(markdown, tags) {
|
|
12940
13152
|
if (!markdown || !tags.length) return markdown;
|
|
12941
13153
|
const tagSet = new Set(tags.map((t) => String(t ?? "").toLowerCase()));
|
|
@@ -13397,6 +13609,7 @@ function parseMarkdownToStructure(markdown, md, options = {}) {
|
|
|
13397
13609
|
return (t.match(/^[<\s/]*([A-Z][\w-]*)/i)?.[1] ?? "").toLowerCase();
|
|
13398
13610
|
}).filter(Boolean);
|
|
13399
13611
|
if (tags.length) {
|
|
13612
|
+
safeMarkdown = ensureBlankLineBeforeInlineMultilineCustomHtmlBlocks(safeMarkdown, tags);
|
|
13400
13613
|
safeMarkdown = normalizeCustomHtmlOpeningTagSameLine(safeMarkdown, tags);
|
|
13401
13614
|
safeMarkdown = ensureBlankLineBeforeCustomHtmlBlocks(safeMarkdown, tags);
|
|
13402
13615
|
safeMarkdown = ensureBlankLineAfterCustomHtmlCloseBeforeBlockMarkerSameLine(safeMarkdown, tags);
|
|
@@ -13458,10 +13671,14 @@ function processTokens(tokens, options) {
|
|
|
13458
13671
|
}
|
|
13459
13672
|
const token = tokens[i];
|
|
13460
13673
|
switch (token.type) {
|
|
13461
|
-
case "paragraph_open":
|
|
13462
|
-
|
|
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);
|
|
13463
13679
|
i += 3;
|
|
13464
13680
|
break;
|
|
13681
|
+
}
|
|
13465
13682
|
case "bullet_list_open":
|
|
13466
13683
|
case "ordered_list_open": {
|
|
13467
13684
|
const [listNode, newIndex] = parseList(tokens, i, options);
|
|
@@ -13513,11 +13730,16 @@ function processTokens(tokens, options) {
|
|
|
13513
13730
|
validateLink: options?.validateLink
|
|
13514
13731
|
});
|
|
13515
13732
|
if (parsed.length === 0) {} else if (parsed.every((n) => n.type === "html_block")) result.push(...parsed);
|
|
13516
|
-
else
|
|
13517
|
-
|
|
13518
|
-
|
|
13519
|
-
|
|
13520
|
-
|
|
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
|
+
}
|
|
13521
13743
|
}
|
|
13522
13744
|
i += 1;
|
|
13523
13745
|
break;
|