stream-markdown-parser 0.0.39 → 0.0.41
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 +34 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +239 -63
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6820,7 +6820,7 @@ const VOID_TAGS$2 = new Set([
|
|
|
6820
6820
|
"track",
|
|
6821
6821
|
"wbr"
|
|
6822
6822
|
]);
|
|
6823
|
-
const
|
|
6823
|
+
const BASE_COMMON_HTML_TAGS = new Set([
|
|
6824
6824
|
...Array.from(VOID_TAGS$2),
|
|
6825
6825
|
"a",
|
|
6826
6826
|
"abbr",
|
|
@@ -6888,24 +6888,52 @@ const COMMON_HTML_TAGS = new Set([
|
|
|
6888
6888
|
]);
|
|
6889
6889
|
const OPEN_TAG_RE = /<([A-Z][\w-]*)(?=[\s/>]|$)/gi;
|
|
6890
6890
|
const CLOSE_TAG_RE = /<\/\s*([A-Z][\w-]*)(?=[\s/>]|$)/gi;
|
|
6891
|
-
const
|
|
6891
|
+
const TAG_NAME_AT_START_RE = /^<\s*(?:\/\s*)?([A-Z][\w-]*)/i;
|
|
6892
|
+
function findTagCloseIndexOutsideQuotes(html) {
|
|
6893
|
+
let inSingle = false;
|
|
6894
|
+
let inDouble = false;
|
|
6895
|
+
for (let i = 0; i < html.length; i++) {
|
|
6896
|
+
const ch = html[i];
|
|
6897
|
+
if (ch === "\"" && !inSingle) {
|
|
6898
|
+
inDouble = !inDouble;
|
|
6899
|
+
continue;
|
|
6900
|
+
}
|
|
6901
|
+
if (ch === "'" && !inDouble) {
|
|
6902
|
+
inSingle = !inSingle;
|
|
6903
|
+
continue;
|
|
6904
|
+
}
|
|
6905
|
+
if (ch === ">" && !inSingle && !inDouble) return i;
|
|
6906
|
+
}
|
|
6907
|
+
return -1;
|
|
6908
|
+
}
|
|
6892
6909
|
function tokenToRaw$1(token) {
|
|
6893
6910
|
const shape = token;
|
|
6894
6911
|
return String(shape.raw ?? shape.content ?? shape.markup ?? "");
|
|
6895
6912
|
}
|
|
6896
|
-
function
|
|
6897
|
-
|
|
6898
|
-
for (const
|
|
6913
|
+
function buildCommonHtmlTagSet(extraTags) {
|
|
6914
|
+
const set = new Set(BASE_COMMON_HTML_TAGS);
|
|
6915
|
+
if (extraTags && Array.isArray(extraTags)) for (const t of extraTags) {
|
|
6916
|
+
const raw = String(t ?? "").trim();
|
|
6917
|
+
if (!raw) continue;
|
|
6918
|
+
const m = raw.match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
6919
|
+
if (!m) continue;
|
|
6920
|
+
set.add(m[1].toLowerCase());
|
|
6921
|
+
}
|
|
6922
|
+
return set;
|
|
6923
|
+
}
|
|
6924
|
+
function isCommonHtmlTagOrPrefix(tag, tagSet) {
|
|
6925
|
+
if (tagSet.has(tag)) return true;
|
|
6926
|
+
for (const common of tagSet) if (common.startsWith(tag)) return true;
|
|
6899
6927
|
return false;
|
|
6900
6928
|
}
|
|
6901
|
-
function findFirstIncompleteTag(content) {
|
|
6929
|
+
function findFirstIncompleteTag(content, tagSet) {
|
|
6902
6930
|
let first = null;
|
|
6903
6931
|
for (const m of content.matchAll(OPEN_TAG_RE)) {
|
|
6904
6932
|
const idx = m.index ?? -1;
|
|
6905
6933
|
if (idx < 0) continue;
|
|
6906
6934
|
const tag = (m[1] ?? "").toLowerCase();
|
|
6907
|
-
if (!
|
|
6908
|
-
if (content.slice(idx)
|
|
6935
|
+
if (!tagSet.has(tag)) continue;
|
|
6936
|
+
if (findTagCloseIndexOutsideQuotes(content.slice(idx)) !== -1) continue;
|
|
6909
6937
|
if (!first || idx < first.index) first = {
|
|
6910
6938
|
index: idx,
|
|
6911
6939
|
tag,
|
|
@@ -6916,8 +6944,8 @@ function findFirstIncompleteTag(content) {
|
|
|
6916
6944
|
const idx = m.index ?? -1;
|
|
6917
6945
|
if (idx < 0) continue;
|
|
6918
6946
|
const tag = (m[1] ?? "").toLowerCase();
|
|
6919
|
-
if (!isCommonHtmlTagOrPrefix(tag)) continue;
|
|
6920
|
-
if (content.slice(idx)
|
|
6947
|
+
if (!isCommonHtmlTagOrPrefix(tag, tagSet)) continue;
|
|
6948
|
+
if (findTagCloseIndexOutsideQuotes(content.slice(idx)) !== -1) continue;
|
|
6921
6949
|
if (!first || idx < first.index) first = {
|
|
6922
6950
|
index: idx,
|
|
6923
6951
|
tag,
|
|
@@ -6953,7 +6981,7 @@ function splitTextToken(token, content) {
|
|
|
6953
6981
|
raw: content
|
|
6954
6982
|
});
|
|
6955
6983
|
}
|
|
6956
|
-
function fixStreamingHtmlInlineChildren(children) {
|
|
6984
|
+
function fixStreamingHtmlInlineChildren(children, tagSet) {
|
|
6957
6985
|
if (!children.length) return { children };
|
|
6958
6986
|
const out = [];
|
|
6959
6987
|
let pending = null;
|
|
@@ -6976,15 +7004,22 @@ function fixStreamingHtmlInlineChildren(children) {
|
|
|
6976
7004
|
break;
|
|
6977
7005
|
}
|
|
6978
7006
|
pushTextPart(chunk.slice(cursor, lt), baseToken);
|
|
6979
|
-
const
|
|
6980
|
-
|
|
7007
|
+
const sub = chunk.slice(lt);
|
|
7008
|
+
const tagMatch = sub.match(TAG_NAME_AT_START_RE);
|
|
7009
|
+
if (!tagMatch) {
|
|
7010
|
+
pushTextPart("<", baseToken);
|
|
7011
|
+
cursor = lt + 1;
|
|
7012
|
+
continue;
|
|
7013
|
+
}
|
|
7014
|
+
const closeIdx = findTagCloseIndexOutsideQuotes(sub);
|
|
7015
|
+
if (closeIdx === -1) {
|
|
6981
7016
|
pushTextPart("<", baseToken);
|
|
6982
7017
|
cursor = lt + 1;
|
|
6983
7018
|
continue;
|
|
6984
7019
|
}
|
|
6985
|
-
const tagText =
|
|
6986
|
-
const tagName = (
|
|
6987
|
-
if (
|
|
7020
|
+
const tagText = sub.slice(0, closeIdx + 1);
|
|
7021
|
+
const tagName = (tagMatch[1] ?? "").toLowerCase();
|
|
7022
|
+
if (tagSet.has(tagName)) out.push({
|
|
6988
7023
|
type: "html_inline",
|
|
6989
7024
|
tag: "",
|
|
6990
7025
|
content: tagText,
|
|
@@ -6996,7 +7031,7 @@ function fixStreamingHtmlInlineChildren(children) {
|
|
|
6996
7031
|
}
|
|
6997
7032
|
function processTextChunk(chunk, baseToken) {
|
|
6998
7033
|
if (!chunk) return;
|
|
6999
|
-
const match = findFirstIncompleteTag(chunk);
|
|
7034
|
+
const match = findFirstIncompleteTag(chunk, tagSet);
|
|
7000
7035
|
if (!match) {
|
|
7001
7036
|
splitCompleteHtmlFromText(chunk, baseToken);
|
|
7002
7037
|
return;
|
|
@@ -7014,7 +7049,7 @@ function fixStreamingHtmlInlineChildren(children) {
|
|
|
7014
7049
|
if (pending) {
|
|
7015
7050
|
pending.buffer += tokenToRaw$1(child);
|
|
7016
7051
|
pendingAtEnd = pending.buffer;
|
|
7017
|
-
const closeIdx = pending.buffer
|
|
7052
|
+
const closeIdx = findTagCloseIndexOutsideQuotes(pending.buffer);
|
|
7018
7053
|
if (closeIdx === -1) continue;
|
|
7019
7054
|
const tagChunk = pending.buffer.slice(0, closeIdx + 1);
|
|
7020
7055
|
const afterChunk = pending.buffer.slice(closeIdx + 1);
|
|
@@ -7029,6 +7064,19 @@ function fixStreamingHtmlInlineChildren(children) {
|
|
|
7029
7064
|
if (afterChunk) processTextChunk(afterChunk);
|
|
7030
7065
|
continue;
|
|
7031
7066
|
}
|
|
7067
|
+
if (child.type === "html_inline") {
|
|
7068
|
+
const content = tokenToRaw$1(child);
|
|
7069
|
+
const tagName = (content.match(TAG_NAME_AT_START_RE)?.[1] ?? "").toLowerCase();
|
|
7070
|
+
if (tagName && tagSet.has(tagName) && findTagCloseIndexOutsideQuotes(content) === -1) {
|
|
7071
|
+
pending = {
|
|
7072
|
+
tag: tagName,
|
|
7073
|
+
buffer: content,
|
|
7074
|
+
closing: /^<\s*\//.test(content)
|
|
7075
|
+
};
|
|
7076
|
+
pendingAtEnd = pending.buffer;
|
|
7077
|
+
continue;
|
|
7078
|
+
}
|
|
7079
|
+
}
|
|
7032
7080
|
if (child.type === "text") {
|
|
7033
7081
|
const content = String(child.content ?? "");
|
|
7034
7082
|
if (!content.includes("<")) {
|
|
@@ -7045,7 +7093,27 @@ function fixStreamingHtmlInlineChildren(children) {
|
|
|
7045
7093
|
pendingBuffer: pendingAtEnd ?? void 0
|
|
7046
7094
|
};
|
|
7047
7095
|
}
|
|
7048
|
-
function applyFixHtmlInlineTokens(md) {
|
|
7096
|
+
function applyFixHtmlInlineTokens(md, options = {}) {
|
|
7097
|
+
const commonHtmlTags = buildCommonHtmlTagSet(options.customHtmlTags);
|
|
7098
|
+
const autoCloseInlineTagSet = new Set([
|
|
7099
|
+
"a",
|
|
7100
|
+
"span",
|
|
7101
|
+
"strong",
|
|
7102
|
+
"em",
|
|
7103
|
+
"b",
|
|
7104
|
+
"i",
|
|
7105
|
+
"u"
|
|
7106
|
+
]);
|
|
7107
|
+
const customTagSet = /* @__PURE__ */ new Set();
|
|
7108
|
+
if (options.customHtmlTags?.length) for (const t of options.customHtmlTags) {
|
|
7109
|
+
const raw = String(t ?? "").trim();
|
|
7110
|
+
if (!raw) continue;
|
|
7111
|
+
const m = raw.match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
7112
|
+
if (!m) continue;
|
|
7113
|
+
const name = m[1].toLowerCase();
|
|
7114
|
+
customTagSet.add(name);
|
|
7115
|
+
autoCloseInlineTagSet.add(name);
|
|
7116
|
+
}
|
|
7049
7117
|
md.core.ruler.after("inline", "fix_html_inline_streaming", (state) => {
|
|
7050
7118
|
const toks = state.tokens ?? [];
|
|
7051
7119
|
for (const t of toks) {
|
|
@@ -7059,7 +7127,7 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
7059
7127
|
}] : null;
|
|
7060
7128
|
if (!sourceChildren) continue;
|
|
7061
7129
|
try {
|
|
7062
|
-
const fixed = fixStreamingHtmlInlineChildren(sourceChildren);
|
|
7130
|
+
const fixed = fixStreamingHtmlInlineChildren(sourceChildren, commonHtmlTags);
|
|
7063
7131
|
tok.children = fixed.children;
|
|
7064
7132
|
if (fixed.pendingBuffer) {
|
|
7065
7133
|
const idx = originalContent.lastIndexOf(fixed.pendingBuffer);
|
|
@@ -7125,7 +7193,36 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
7125
7193
|
].includes(tag)) continue;
|
|
7126
7194
|
t.type = "inline";
|
|
7127
7195
|
const loading = t.content?.toLowerCase().includes(`</${tag}>`) ? false : t.loading !== void 0 ? t.loading : true;
|
|
7128
|
-
|
|
7196
|
+
const attrs = [];
|
|
7197
|
+
const attrRegex = /\s([\w:-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
7198
|
+
let match;
|
|
7199
|
+
while ((match = attrRegex.exec(t.content || "")) !== null) {
|
|
7200
|
+
const attrName = match[1];
|
|
7201
|
+
const attrValue = match[2] || match[3] || match[4] || "";
|
|
7202
|
+
attrs.push([attrName, attrValue]);
|
|
7203
|
+
}
|
|
7204
|
+
if (customTagSet.has(tag)) {
|
|
7205
|
+
const contentMatch = t.content?.match(new RegExp(`<\\s*${tag}[^>]*>([\\s\\S]*)`, "i"));
|
|
7206
|
+
const raw$1 = t.content;
|
|
7207
|
+
const endTagRegex = new RegExp(`</\\s*${tag}\\s*>`, "i");
|
|
7208
|
+
const endTagIndex = t.content?.toLowerCase().indexOf(`</${tag}>`) ?? -1;
|
|
7209
|
+
t.children = [{
|
|
7210
|
+
type: tag,
|
|
7211
|
+
content: endTagIndex !== -1 ? contentMatch[1].split(endTagRegex)[0] ? contentMatch ? contentMatch[1] : "" : "" : contentMatch ? contentMatch[1].replace(/<.*$/, "") : "",
|
|
7212
|
+
raw: raw$1,
|
|
7213
|
+
attrs,
|
|
7214
|
+
tag,
|
|
7215
|
+
loading
|
|
7216
|
+
}];
|
|
7217
|
+
if (endTagIndex !== -1) {
|
|
7218
|
+
const afterContent = t.content?.slice(endTagIndex + tag.length + 3) || "";
|
|
7219
|
+
if (afterContent.trim()) toks.splice(i + 1, 0, {
|
|
7220
|
+
type: "text",
|
|
7221
|
+
content: afterContent,
|
|
7222
|
+
raw: afterContent
|
|
7223
|
+
});
|
|
7224
|
+
}
|
|
7225
|
+
} else t.children = [{
|
|
7129
7226
|
type: "html_block",
|
|
7130
7227
|
content: t.content,
|
|
7131
7228
|
tag,
|
|
@@ -7135,16 +7232,8 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
7135
7232
|
}
|
|
7136
7233
|
if (!t || t.type !== "inline") continue;
|
|
7137
7234
|
if (t.children.length === 2 && t.children[0].type === "html_inline") {
|
|
7138
|
-
const tag = t.children[0].content?.match(/<([^\s>/]+)/)?.[1] ?? "";
|
|
7139
|
-
if (
|
|
7140
|
-
"a",
|
|
7141
|
-
"span",
|
|
7142
|
-
"strong",
|
|
7143
|
-
"em",
|
|
7144
|
-
"b",
|
|
7145
|
-
"i",
|
|
7146
|
-
"u"
|
|
7147
|
-
].includes(tag)) {
|
|
7235
|
+
const tag = (t.children[0].content?.match(/<([^\s>/]+)/)?.[1] ?? "").toLowerCase();
|
|
7236
|
+
if (autoCloseInlineTagSet.has(tag)) {
|
|
7148
7237
|
t.children[0].loading = true;
|
|
7149
7238
|
t.children[0].tag = tag;
|
|
7150
7239
|
t.children.push({
|
|
@@ -7161,16 +7250,8 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
7161
7250
|
}];
|
|
7162
7251
|
continue;
|
|
7163
7252
|
} else if (t.children.length === 3 && t.children[0].type === "html_inline" && t.children[2].type === "html_inline") {
|
|
7164
|
-
const tag = t.children[0].content?.match(/<([^\s>/]+)/)?.[1] ?? "";
|
|
7165
|
-
if (
|
|
7166
|
-
"a",
|
|
7167
|
-
"span",
|
|
7168
|
-
"strong",
|
|
7169
|
-
"em",
|
|
7170
|
-
"b",
|
|
7171
|
-
"i",
|
|
7172
|
-
"u"
|
|
7173
|
-
].includes(tag)) continue;
|
|
7253
|
+
const tag = (t.children[0].content?.match(/<([^\s>/]+)/)?.[1] ?? "").toLowerCase();
|
|
7254
|
+
if (autoCloseInlineTagSet.has(tag)) continue;
|
|
7174
7255
|
t.children = [{
|
|
7175
7256
|
type: "html_block",
|
|
7176
7257
|
loading: false,
|
|
@@ -8500,7 +8581,7 @@ function factory(opts = {}) {
|
|
|
8500
8581
|
applyFixListItem(md);
|
|
8501
8582
|
applyFixTableTokens(md);
|
|
8502
8583
|
applyRenderRules(md);
|
|
8503
|
-
applyFixHtmlInlineTokens(md);
|
|
8584
|
+
applyFixHtmlInlineTokens(md, { customHtmlTags: opts.customHtmlTags });
|
|
8504
8585
|
return md;
|
|
8505
8586
|
}
|
|
8506
8587
|
|
|
@@ -8549,7 +8630,10 @@ function parseEmphasisToken(tokens, startIndex, options) {
|
|
|
8549
8630
|
innerTokens.push(tokens[i]);
|
|
8550
8631
|
i++;
|
|
8551
8632
|
}
|
|
8552
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8633
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8634
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
8635
|
+
customHtmlTags: options?.customHtmlTags
|
|
8636
|
+
}));
|
|
8553
8637
|
return {
|
|
8554
8638
|
node: {
|
|
8555
8639
|
type: "emphasis",
|
|
@@ -8657,7 +8741,10 @@ function parseHighlightToken(tokens, startIndex, options) {
|
|
|
8657
8741
|
innerTokens.push(tokens[i]);
|
|
8658
8742
|
i++;
|
|
8659
8743
|
}
|
|
8660
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8744
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8745
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
8746
|
+
customHtmlTags: options?.customHtmlTags
|
|
8747
|
+
}));
|
|
8661
8748
|
return {
|
|
8662
8749
|
node: {
|
|
8663
8750
|
type: "highlight",
|
|
@@ -8696,6 +8783,12 @@ function isClosingTag(html) {
|
|
|
8696
8783
|
function isSelfClosing(tag, html) {
|
|
8697
8784
|
return /\/\s*>\s*$/.test(html) || VOID_TAGS$1.has(tag);
|
|
8698
8785
|
}
|
|
8786
|
+
function normalizeCustomTag(t) {
|
|
8787
|
+
const raw = String(t ?? "").trim();
|
|
8788
|
+
if (!raw) return "";
|
|
8789
|
+
const m = raw.match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
8790
|
+
return m ? m[1].toLowerCase() : "";
|
|
8791
|
+
}
|
|
8699
8792
|
function tokenToRaw(token) {
|
|
8700
8793
|
const shape = token;
|
|
8701
8794
|
const raw = shape.raw ?? shape.content ?? shape.markup ?? "";
|
|
@@ -8750,6 +8843,8 @@ function collectHtmlFragment(tokens, startIndex, tag) {
|
|
|
8750
8843
|
function parseHtmlInlineCodeToken(token, tokens, i, parseInlineTokens$1, raw, pPreToken, options) {
|
|
8751
8844
|
const code$1 = String(token.content ?? "");
|
|
8752
8845
|
const tag = getTagName(code$1);
|
|
8846
|
+
const customTags = options?.customHtmlTags;
|
|
8847
|
+
const customTagSet = customTags && customTags.length ? new Set(customTags.map(normalizeCustomTag).filter(Boolean)) : null;
|
|
8753
8848
|
if (!tag) return [{
|
|
8754
8849
|
type: "inline_code",
|
|
8755
8850
|
code: code$1,
|
|
@@ -8792,7 +8887,7 @@ function parseHtmlInlineCodeToken(token, tokens, i, parseInlineTokens$1, raw, pP
|
|
|
8792
8887
|
}, fragment$1.nextIndex];
|
|
8793
8888
|
}
|
|
8794
8889
|
if (selfClosing) return [{
|
|
8795
|
-
type: "html_inline",
|
|
8890
|
+
type: customTagSet?.has(tag) ? tag : "html_inline",
|
|
8796
8891
|
tag,
|
|
8797
8892
|
content: code$1,
|
|
8798
8893
|
children: [],
|
|
@@ -8815,9 +8910,27 @@ function parseHtmlInlineCodeToken(token, tokens, i, parseInlineTokens$1, raw, pP
|
|
|
8815
8910
|
autoClosed = true;
|
|
8816
8911
|
loading = true;
|
|
8817
8912
|
}
|
|
8913
|
+
const attrs = [];
|
|
8914
|
+
const attrRegex = /\s([\w:-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
8915
|
+
let match;
|
|
8916
|
+
while ((match = attrRegex.exec(code$1)) !== null) {
|
|
8917
|
+
const attrName = match[1];
|
|
8918
|
+
const attrValue = match[2] || match[3] || match[4] || "";
|
|
8919
|
+
attrs.push([attrName, attrValue]);
|
|
8920
|
+
}
|
|
8921
|
+
if (customTagSet?.has(tag)) return [{
|
|
8922
|
+
type: tag,
|
|
8923
|
+
tag,
|
|
8924
|
+
attrs,
|
|
8925
|
+
content: fragment.innerTokens.length ? stringifyTokens(fragment.innerTokens) : "",
|
|
8926
|
+
raw: content,
|
|
8927
|
+
loading: token.loading || loading,
|
|
8928
|
+
autoClosed
|
|
8929
|
+
}, fragment.nextIndex];
|
|
8818
8930
|
return [{
|
|
8819
8931
|
type: "html_inline",
|
|
8820
8932
|
tag,
|
|
8933
|
+
attrs,
|
|
8821
8934
|
content,
|
|
8822
8935
|
children,
|
|
8823
8936
|
raw: content,
|
|
@@ -8883,7 +8996,10 @@ function parseInsertToken(tokens, startIndex, options) {
|
|
|
8883
8996
|
innerTokens.push(tokens[i]);
|
|
8884
8997
|
i++;
|
|
8885
8998
|
}
|
|
8886
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8999
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9000
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9001
|
+
customHtmlTags: options?.customHtmlTags
|
|
9002
|
+
}));
|
|
8887
9003
|
return {
|
|
8888
9004
|
node: {
|
|
8889
9005
|
type: "insert",
|
|
@@ -8909,7 +9025,10 @@ function parseLinkToken(tokens, startIndex, options) {
|
|
|
8909
9025
|
i++;
|
|
8910
9026
|
}
|
|
8911
9027
|
if (tokens[i]?.type === "link_close") loading = false;
|
|
8912
|
-
const children = parseInlineTokens(linkTokens, void 0, void 0, {
|
|
9028
|
+
const children = parseInlineTokens(linkTokens, void 0, void 0, {
|
|
9029
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9030
|
+
customHtmlTags: options?.customHtmlTags
|
|
9031
|
+
});
|
|
8913
9032
|
const linkText = children.map((node) => {
|
|
8914
9033
|
const nodeAny = node;
|
|
8915
9034
|
if ("content" in node) return String(nodeAny.content ?? "");
|
|
@@ -8964,7 +9083,10 @@ function parseStrikethroughToken(tokens, startIndex, options) {
|
|
|
8964
9083
|
innerTokens.push(tokens[i]);
|
|
8965
9084
|
i++;
|
|
8966
9085
|
}
|
|
8967
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9086
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9087
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9088
|
+
customHtmlTags: options?.customHtmlTags
|
|
9089
|
+
}));
|
|
8968
9090
|
return {
|
|
8969
9091
|
node: {
|
|
8970
9092
|
type: "strikethrough",
|
|
@@ -8993,7 +9115,10 @@ function parseStrongToken(tokens, startIndex, raw, options) {
|
|
|
8993
9115
|
innerTokens.push(tokens[i]);
|
|
8994
9116
|
i++;
|
|
8995
9117
|
}
|
|
8996
|
-
children.push(...parseInlineTokens(innerTokens, raw, void 0, {
|
|
9118
|
+
children.push(...parseInlineTokens(innerTokens, raw, void 0, {
|
|
9119
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9120
|
+
customHtmlTags: options?.customHtmlTags
|
|
9121
|
+
}));
|
|
8997
9122
|
return {
|
|
8998
9123
|
node: {
|
|
8999
9124
|
type: "strong",
|
|
@@ -9016,7 +9141,10 @@ function parseSubscriptToken(tokens, startIndex, options) {
|
|
|
9016
9141
|
innerTokens.push(tokens[i]);
|
|
9017
9142
|
i++;
|
|
9018
9143
|
}
|
|
9019
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9144
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9145
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9146
|
+
customHtmlTags: options?.customHtmlTags
|
|
9147
|
+
}));
|
|
9020
9148
|
const startContent = String(tokens[startIndex].content ?? "");
|
|
9021
9149
|
const display = subText || startContent;
|
|
9022
9150
|
return {
|
|
@@ -9045,7 +9173,10 @@ function parseSuperscriptToken(tokens, startIndex, options) {
|
|
|
9045
9173
|
innerTokens.push(tokens[i]);
|
|
9046
9174
|
i++;
|
|
9047
9175
|
}
|
|
9048
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9176
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9177
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9178
|
+
customHtmlTags: options?.customHtmlTags
|
|
9179
|
+
}));
|
|
9049
9180
|
return {
|
|
9050
9181
|
node: {
|
|
9051
9182
|
type: "superscript",
|
|
@@ -9922,7 +10053,10 @@ function parseDefinitionList(tokens, index, options) {
|
|
|
9922
10053
|
let definitionNodes = [];
|
|
9923
10054
|
while (j < tokens.length && tokens[j].type !== "dl_close") if (tokens[j].type === "dt_open") {
|
|
9924
10055
|
const termToken = tokens[j + 1];
|
|
9925
|
-
termNodes = parseInlineTokens(termToken.children || [], void 0, void 0, {
|
|
10056
|
+
termNodes = parseInlineTokens(termToken.children || [], void 0, void 0, {
|
|
10057
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10058
|
+
customHtmlTags: options?.customHtmlTags
|
|
10059
|
+
});
|
|
9926
10060
|
j += 3;
|
|
9927
10061
|
} else if (tokens[j].type === "dd_open") {
|
|
9928
10062
|
let k = j + 1;
|
|
@@ -9931,7 +10065,10 @@ function parseDefinitionList(tokens, index, options) {
|
|
|
9931
10065
|
const contentToken = tokens[k + 1];
|
|
9932
10066
|
definitionNodes.push({
|
|
9933
10067
|
type: "paragraph",
|
|
9934
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10068
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10069
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10070
|
+
customHtmlTags: options?.customHtmlTags
|
|
10071
|
+
}),
|
|
9935
10072
|
raw: String(contentToken.content ?? "")
|
|
9936
10073
|
});
|
|
9937
10074
|
k += 3;
|
|
@@ -9967,7 +10104,10 @@ function parseFootnote(tokens, index, options) {
|
|
|
9967
10104
|
if (tokens[j + 2].type === "footnote_anchor") children.push(tokens[j + 2]);
|
|
9968
10105
|
footnoteChildren.push({
|
|
9969
10106
|
type: "paragraph",
|
|
9970
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10107
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10108
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10109
|
+
customHtmlTags: options?.customHtmlTags
|
|
10110
|
+
}),
|
|
9971
10111
|
raw: String(contentToken.content ?? "")
|
|
9972
10112
|
});
|
|
9973
10113
|
j += 3;
|
|
@@ -9992,7 +10132,10 @@ function parseHeading(tokens, index, options) {
|
|
|
9992
10132
|
type: "heading",
|
|
9993
10133
|
level: headingLevel,
|
|
9994
10134
|
text: headingContent,
|
|
9995
|
-
children: parseInlineTokens(headingContentToken.children || [], headingContent, void 0, {
|
|
10135
|
+
children: parseInlineTokens(headingContentToken.children || [], headingContent, void 0, {
|
|
10136
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10137
|
+
customHtmlTags: options?.customHtmlTags
|
|
10138
|
+
}),
|
|
9996
10139
|
raw: headingContent
|
|
9997
10140
|
};
|
|
9998
10141
|
}
|
|
@@ -10103,7 +10246,10 @@ function parseTable(tokens, index, options) {
|
|
|
10103
10246
|
cells.push({
|
|
10104
10247
|
type: "table_cell",
|
|
10105
10248
|
header: isHeaderCell || isHeader,
|
|
10106
|
-
children: parseInlineTokens(contentToken.children || [], content, void 0, {
|
|
10249
|
+
children: parseInlineTokens(contentToken.children || [], content, void 0, {
|
|
10250
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10251
|
+
customHtmlTags: options?.customHtmlTags
|
|
10252
|
+
}),
|
|
10107
10253
|
raw: content,
|
|
10108
10254
|
align
|
|
10109
10255
|
});
|
|
@@ -10150,7 +10296,19 @@ function parseBasicBlockToken(tokens, index, options) {
|
|
|
10150
10296
|
case "code_block": return [parseCodeBlock(token), index + 1];
|
|
10151
10297
|
case "fence": return [parseFenceToken(token), index + 1];
|
|
10152
10298
|
case "math_block": return [parseMathBlock(token), index + 1];
|
|
10153
|
-
case "html_block":
|
|
10299
|
+
case "html_block": {
|
|
10300
|
+
const htmlBlockNode = parseHtmlBlock(token);
|
|
10301
|
+
if (options?.customHtmlTags && htmlBlockNode.tag) {
|
|
10302
|
+
if (new Set(options.customHtmlTags.map((t) => {
|
|
10303
|
+
const m = String(t ?? "").trim().match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
10304
|
+
return m ? m[1].toLowerCase() : "";
|
|
10305
|
+
}).filter(Boolean)).has(htmlBlockNode.tag)) return [{
|
|
10306
|
+
...htmlBlockNode,
|
|
10307
|
+
type: htmlBlockNode.tag
|
|
10308
|
+
}, index + 1];
|
|
10309
|
+
}
|
|
10310
|
+
return [htmlBlockNode, index + 1];
|
|
10311
|
+
}
|
|
10154
10312
|
case "table_open": {
|
|
10155
10313
|
const [tableNode, newIndex] = parseTable(tokens, index, options);
|
|
10156
10314
|
return [tableNode, newIndex];
|
|
@@ -10211,7 +10369,10 @@ function parseList(tokens, index, options) {
|
|
|
10211
10369
|
}
|
|
10212
10370
|
itemChildren.push({
|
|
10213
10371
|
type: "paragraph",
|
|
10214
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), preToken, {
|
|
10372
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), preToken, {
|
|
10373
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10374
|
+
customHtmlTags: options?.customHtmlTags
|
|
10375
|
+
}),
|
|
10215
10376
|
raw: String(contentToken.content ?? "")
|
|
10216
10377
|
});
|
|
10217
10378
|
k += 3;
|
|
@@ -10265,7 +10426,10 @@ function parseAdmonition(tokens, index, match, options) {
|
|
|
10265
10426
|
const contentToken = tokens[j + 1];
|
|
10266
10427
|
if (contentToken) admonitionChildren.push({
|
|
10267
10428
|
type: "paragraph",
|
|
10268
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10429
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10430
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10431
|
+
customHtmlTags: options?.customHtmlTags
|
|
10432
|
+
}),
|
|
10269
10433
|
raw: String(contentToken.content ?? "")
|
|
10270
10434
|
});
|
|
10271
10435
|
j += 3;
|
|
@@ -10334,7 +10498,10 @@ function parseContainer(tokens, index, options) {
|
|
|
10334
10498
|
const _children = i !== -1 ? childrenArr.slice(0, i) : childrenArr;
|
|
10335
10499
|
children.push({
|
|
10336
10500
|
type: "paragraph",
|
|
10337
|
-
children: parseInlineTokens(_children || [], void 0, void 0, {
|
|
10501
|
+
children: parseInlineTokens(_children || [], void 0, void 0, {
|
|
10502
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10503
|
+
customHtmlTags: options?.customHtmlTags
|
|
10504
|
+
}),
|
|
10338
10505
|
raw: String(contentToken.content ?? "").replace(/\n:+$/, "").replace(/\n\s*:::\s*$/, "")
|
|
10339
10506
|
});
|
|
10340
10507
|
}
|
|
@@ -10388,7 +10555,10 @@ function parseBlockquote(tokens, index, options) {
|
|
|
10388
10555
|
const contentToken = tokens[j + 1];
|
|
10389
10556
|
blockquoteChildren.push({
|
|
10390
10557
|
type: "paragraph",
|
|
10391
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10558
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10559
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10560
|
+
customHtmlTags: options?.customHtmlTags
|
|
10561
|
+
}),
|
|
10392
10562
|
raw: String(contentToken.content ?? "")
|
|
10393
10563
|
});
|
|
10394
10564
|
j += 3;
|
|
@@ -10439,7 +10609,10 @@ function parseParagraph(tokens, index, options) {
|
|
|
10439
10609
|
const paragraphContent = String(paragraphContentToken.content ?? "");
|
|
10440
10610
|
return {
|
|
10441
10611
|
type: "paragraph",
|
|
10442
|
-
children: parseInlineTokens(paragraphContentToken.children || [], paragraphContent, void 0, {
|
|
10612
|
+
children: parseInlineTokens(paragraphContentToken.children || [], paragraphContent, void 0, {
|
|
10613
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10614
|
+
customHtmlTags: options?.customHtmlTags
|
|
10615
|
+
}),
|
|
10443
10616
|
raw: paragraphContent
|
|
10444
10617
|
};
|
|
10445
10618
|
}
|
|
@@ -10516,7 +10689,10 @@ function processTokens(tokens, options) {
|
|
|
10516
10689
|
i++;
|
|
10517
10690
|
break;
|
|
10518
10691
|
case "inline":
|
|
10519
|
-
result.push(...parseInlineTokens(token.children || [], String(token.content ?? ""), void 0, {
|
|
10692
|
+
result.push(...parseInlineTokens(token.children || [], String(token.content ?? ""), void 0, {
|
|
10693
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10694
|
+
customHtmlTags: options?.customHtmlTags
|
|
10695
|
+
}));
|
|
10520
10696
|
i += 1;
|
|
10521
10697
|
break;
|
|
10522
10698
|
default:
|