stream-markdown-parser 0.0.39 → 0.0.40
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 +184 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ interface FactoryOptions extends Record<string, unknown> {
|
|
|
9
9
|
commands?: string[];
|
|
10
10
|
escapeExclamation?: boolean;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Custom HTML-like tag names that should participate in streaming mid-state
|
|
14
|
+
* suppression and be emitted as custom nodes (e.g. ['thinking']).
|
|
15
|
+
*/
|
|
16
|
+
customHtmlTags?: readonly string[];
|
|
12
17
|
}
|
|
13
18
|
//#endregion
|
|
14
19
|
//#region src/types.d.ts
|
|
@@ -79,6 +84,25 @@ interface HtmlInlineNode extends BaseNode {
|
|
|
79
84
|
*/
|
|
80
85
|
autoClosed?: boolean;
|
|
81
86
|
}
|
|
87
|
+
type CustomComponentAttrs = [string, string][] | Record<string, string | boolean> | Array<{
|
|
88
|
+
name: string;
|
|
89
|
+
value: string | boolean;
|
|
90
|
+
}> | null;
|
|
91
|
+
/**
|
|
92
|
+
* A generic node shape for custom HTML-like components.
|
|
93
|
+
* When a tag name is included in `customHtmlTags`, the parser emits a node
|
|
94
|
+
* whose `type` equals that tag name and carries the raw HTML `content`
|
|
95
|
+
* plus any extracted `attrs` from user transforms.
|
|
96
|
+
*/
|
|
97
|
+
interface CustomComponentNode extends BaseNode {
|
|
98
|
+
/** The custom tag name (same as `tag`) */
|
|
99
|
+
type: string;
|
|
100
|
+
tag: string;
|
|
101
|
+
content: string;
|
|
102
|
+
attrs?: CustomComponentAttrs;
|
|
103
|
+
children?: ParsedNode[];
|
|
104
|
+
autoClosed?: boolean;
|
|
105
|
+
}
|
|
82
106
|
interface InlineCodeNode extends BaseNode {
|
|
83
107
|
type: 'inline_code';
|
|
84
108
|
code: string;
|
|
@@ -238,7 +262,7 @@ type MarkdownToken = (Token & {
|
|
|
238
262
|
loading?: boolean;
|
|
239
263
|
raw?: string;
|
|
240
264
|
}) | MarkdownTokenLite;
|
|
241
|
-
type ParsedNode = TextNode | HeadingNode | ParagraphNode | ListNode | ListItemNode | CodeBlockNode | InlineCodeNode | LinkNode | ImageNode | ThematicBreakNode | BlockquoteNode | TableNode | TableRowNode | TableCellNode | StrongNode | EmphasisNode | StrikethroughNode | HighlightNode | InsertNode | SubscriptNode | SuperscriptNode | CheckboxNode | CheckboxInputNode | EmojiNode | DefinitionListNode | DefinitionItemNode | FootnoteNode | FootnoteReferenceNode | AdmonitionNode | HardBreakNode | MathInlineNode | MathBlockNode | ReferenceNode | HtmlBlockNode | HtmlInlineNode | Record<string, unknown>;
|
|
265
|
+
type ParsedNode = TextNode | HeadingNode | ParagraphNode | ListNode | ListItemNode | CodeBlockNode | InlineCodeNode | LinkNode | ImageNode | ThematicBreakNode | BlockquoteNode | TableNode | TableRowNode | TableCellNode | StrongNode | EmphasisNode | StrikethroughNode | HighlightNode | InsertNode | SubscriptNode | SuperscriptNode | CheckboxNode | CheckboxInputNode | EmojiNode | DefinitionListNode | DefinitionItemNode | FootnoteNode | FootnoteReferenceNode | AdmonitionNode | HardBreakNode | MathInlineNode | MathBlockNode | ReferenceNode | HtmlBlockNode | HtmlInlineNode | CustomComponentNode | Record<string, unknown>;
|
|
242
266
|
interface CustomComponents {
|
|
243
267
|
text: unknown;
|
|
244
268
|
paragraph: unknown;
|
|
@@ -277,6 +301,13 @@ interface ParseOptions {
|
|
|
277
301
|
preTransformTokens?: TransformTokensHook;
|
|
278
302
|
postTransformTokens?: TransformTokensHook;
|
|
279
303
|
requireClosingStrong?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Custom HTML-like tag names that should be emitted as custom nodes
|
|
306
|
+
* instead of `html_inline` when encountered (e.g. ['thinking']).
|
|
307
|
+
* Used by inline parsing; pair with `getMarkdown({ customHtmlTags })`
|
|
308
|
+
* to enable mid-state suppression for the same tags during streaming.
|
|
309
|
+
*/
|
|
310
|
+
customHtmlTags?: string[];
|
|
280
311
|
debug?: boolean;
|
|
281
312
|
}
|
|
282
313
|
type PostTransformNodesHook = (nodes: ParsedNode[]) => ParsedNode[];
|
|
@@ -284,6 +315,7 @@ type PostTransformNodesHook = (nodes: ParsedNode[]) => ParsedNode[];
|
|
|
284
315
|
//#region src/parser/inline-parsers/index.d.ts
|
|
285
316
|
declare function parseInlineTokens(tokens: MarkdownToken[], raw?: string, pPreToken?: MarkdownToken, options?: {
|
|
286
317
|
requireClosingStrong?: boolean;
|
|
318
|
+
customHtmlTags?: readonly string[];
|
|
287
319
|
}): ParsedNode[];
|
|
288
320
|
//#endregion
|
|
289
321
|
//#region src/parser/index.d.ts
|
|
@@ -353,5 +385,5 @@ interface GetMarkdownOptions extends FactoryOptions {
|
|
|
353
385
|
}
|
|
354
386
|
declare function getMarkdown(msgId?: string, options?: GetMarkdownOptions): MarkdownIt;
|
|
355
387
|
//#endregion
|
|
356
|
-
export { AdmonitionNode, BaseNode, BlockquoteNode, CheckboxInputNode, CheckboxNode, CodeBlockNode, CustomComponents, DefinitionItemNode, DefinitionListNode, ESCAPED_TEX_BRACE_COMMANDS, EmojiNode, EmphasisNode, FootnoteAnchorNode, FootnoteNode, FootnoteReferenceNode, GetMarkdownOptions, HardBreakNode, HeadingNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, ImageNode, InlineCodeNode, InlineNode, InsertNode, KATEX_COMMANDS, LinkNode, ListItemNode, ListNode, type MarkdownIt, MarkdownRender, MarkdownToken, MarkdownTokenLite, MathBlockNode, MathInlineNode, type MathOptions, MermaidBlockNode, ParagraphNode, ParseOptions, ParsedNode, PostTransformNodesHook, ReferenceNode, StrikethroughNode, StrongNode, SubscriptNode, SuperscriptNode, TEX_BRACE_COMMANDS, TableCellNode, TableNode, TableRowNode, TextNode, ThematicBreakNode, TransformTokensHook, applyContainers, applyMath, clearRegisteredMarkdownPlugins, findMatchingClose, getMarkdown, isMathLike, normalizeStandaloneBackslashT, parseFenceToken, parseInlineTokens, parseMarkdownToStructure, processTokens, registerMarkdownPlugin, setDefaultMathOptions };
|
|
388
|
+
export { AdmonitionNode, BaseNode, BlockquoteNode, CheckboxInputNode, CheckboxNode, CodeBlockNode, CustomComponentAttrs, CustomComponentNode, CustomComponents, DefinitionItemNode, DefinitionListNode, ESCAPED_TEX_BRACE_COMMANDS, EmojiNode, EmphasisNode, FootnoteAnchorNode, FootnoteNode, FootnoteReferenceNode, GetMarkdownOptions, HardBreakNode, HeadingNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, ImageNode, InlineCodeNode, InlineNode, InsertNode, KATEX_COMMANDS, LinkNode, ListItemNode, ListNode, type MarkdownIt, MarkdownRender, MarkdownToken, MarkdownTokenLite, MathBlockNode, MathInlineNode, type MathOptions, MermaidBlockNode, ParagraphNode, ParseOptions, ParsedNode, PostTransformNodesHook, ReferenceNode, StrikethroughNode, StrongNode, SubscriptNode, SuperscriptNode, TEX_BRACE_COMMANDS, TableCellNode, TableNode, TableRowNode, TextNode, ThematicBreakNode, TransformTokensHook, applyContainers, applyMath, clearRegisteredMarkdownPlugins, findMatchingClose, getMarkdown, isMathLike, normalizeStandaloneBackslashT, parseFenceToken, parseInlineTokens, parseMarkdownToStructure, processTokens, registerMarkdownPlugin, setDefaultMathOptions };
|
|
357
389
|
//# sourceMappingURL=index.d.ts.map
|
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":";;;UAYiB,cAAA,SAAuB;sBAClB;;EADL,gBAAA,CAAe,EAAA,OAAA;;;;ECVf,CAAA;
|
|
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":";;;UAYiB,cAAA,SAAuB;sBAClB;;EADL,gBAAA,CAAe,EAAA,OAAA;;;;ECVf,CAAA;EAQA;AAMjB;AAOA;AAMA;EAMiB,cAAS,CAAA,EAAA,SAKjB,MAAA,EAAA;AAGT;;;UAzCiB,QAAA;;EDUA,GAAA,EAAA,MAAA;;;;ACVjB;AAQiB,UAAA,QAAA,SAAiB,QAAQ,CAAA;EAMzB,IAAA,EAAA,MAAA;EAOA,OAAA,EAAA,MAAA;EAMA,MAAA,CAAA,EAAA,OAAW;AAM5B;AAQiB,UA3BA,WAAA,SAAoB,QA2BC,CAAA;EAKrB,IAAA,EAAA,SAAA;EAiBA,KAAA,EAAA,MAAA;EAOA,IAAA,EAAA,MAAA;EAYL,QAAA,EAhEA,UAgEA,EAAA;AAYZ;AAKU,UA9EO,aAAA,SAAsB,QA8E7B,CAAA;EACG,IAAA,EAAA,WAAA;EANgC,QAAA,EAvEjC,UAuEiC,EAAA;EAAQ,aAAA,CAAA,EAAA,OAAA;AAUrD;AAKiB,UAlFA,UAAA,SAAmB,QAkFF,CAAA;EAQjB,IAAA,EAAA,QAAU;EAOV,QAAA,EA/FL,UA+FuB,EAAA;EAIlB,OAAA,CAAA,EAAA,MAAA;AASjB;AASiB,UAjHA,QAAA,SAAiB,QAmHtB,CAAA;EAGK,IAAA,EAAA,MAAU;EAEjB,OAAA,EAAA,OAAA;EACF,KAAA,CAAA,EAAA,MAAA;EAH2B,KAAA,EAjH1B,YAiH0B,EAAA;;AAMlB,UApHA,YAAA,SAAqB,QAoHA,CA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|
@@ -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",
|
|
@@ -6893,18 +6893,29 @@ function tokenToRaw$1(token) {
|
|
|
6893
6893
|
const shape = token;
|
|
6894
6894
|
return String(shape.raw ?? shape.content ?? shape.markup ?? "");
|
|
6895
6895
|
}
|
|
6896
|
-
function
|
|
6897
|
-
|
|
6898
|
-
for (const
|
|
6896
|
+
function buildCommonHtmlTagSet(extraTags) {
|
|
6897
|
+
const set = new Set(BASE_COMMON_HTML_TAGS);
|
|
6898
|
+
if (extraTags && Array.isArray(extraTags)) for (const t of extraTags) {
|
|
6899
|
+
const raw = String(t ?? "").trim();
|
|
6900
|
+
if (!raw) continue;
|
|
6901
|
+
const m = raw.match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
6902
|
+
if (!m) continue;
|
|
6903
|
+
set.add(m[1].toLowerCase());
|
|
6904
|
+
}
|
|
6905
|
+
return set;
|
|
6906
|
+
}
|
|
6907
|
+
function isCommonHtmlTagOrPrefix(tag, tagSet) {
|
|
6908
|
+
if (tagSet.has(tag)) return true;
|
|
6909
|
+
for (const common of tagSet) if (common.startsWith(tag)) return true;
|
|
6899
6910
|
return false;
|
|
6900
6911
|
}
|
|
6901
|
-
function findFirstIncompleteTag(content) {
|
|
6912
|
+
function findFirstIncompleteTag(content, tagSet) {
|
|
6902
6913
|
let first = null;
|
|
6903
6914
|
for (const m of content.matchAll(OPEN_TAG_RE)) {
|
|
6904
6915
|
const idx = m.index ?? -1;
|
|
6905
6916
|
if (idx < 0) continue;
|
|
6906
6917
|
const tag = (m[1] ?? "").toLowerCase();
|
|
6907
|
-
if (!
|
|
6918
|
+
if (!tagSet.has(tag)) continue;
|
|
6908
6919
|
if (content.slice(idx).includes(">")) continue;
|
|
6909
6920
|
if (!first || idx < first.index) first = {
|
|
6910
6921
|
index: idx,
|
|
@@ -6916,7 +6927,7 @@ function findFirstIncompleteTag(content) {
|
|
|
6916
6927
|
const idx = m.index ?? -1;
|
|
6917
6928
|
if (idx < 0) continue;
|
|
6918
6929
|
const tag = (m[1] ?? "").toLowerCase();
|
|
6919
|
-
if (!isCommonHtmlTagOrPrefix(tag)) continue;
|
|
6930
|
+
if (!isCommonHtmlTagOrPrefix(tag, tagSet)) continue;
|
|
6920
6931
|
if (content.slice(idx).includes(">")) continue;
|
|
6921
6932
|
if (!first || idx < first.index) first = {
|
|
6922
6933
|
index: idx,
|
|
@@ -6953,7 +6964,7 @@ function splitTextToken(token, content) {
|
|
|
6953
6964
|
raw: content
|
|
6954
6965
|
});
|
|
6955
6966
|
}
|
|
6956
|
-
function fixStreamingHtmlInlineChildren(children) {
|
|
6967
|
+
function fixStreamingHtmlInlineChildren(children, tagSet) {
|
|
6957
6968
|
if (!children.length) return { children };
|
|
6958
6969
|
const out = [];
|
|
6959
6970
|
let pending = null;
|
|
@@ -6984,7 +6995,7 @@ function fixStreamingHtmlInlineChildren(children) {
|
|
|
6984
6995
|
}
|
|
6985
6996
|
const tagText = fullMatch[0];
|
|
6986
6997
|
const tagName = (fullMatch[1] ?? "").toLowerCase();
|
|
6987
|
-
if (
|
|
6998
|
+
if (tagSet.has(tagName)) out.push({
|
|
6988
6999
|
type: "html_inline",
|
|
6989
7000
|
tag: "",
|
|
6990
7001
|
content: tagText,
|
|
@@ -6996,7 +7007,7 @@ function fixStreamingHtmlInlineChildren(children) {
|
|
|
6996
7007
|
}
|
|
6997
7008
|
function processTextChunk(chunk, baseToken) {
|
|
6998
7009
|
if (!chunk) return;
|
|
6999
|
-
const match = findFirstIncompleteTag(chunk);
|
|
7010
|
+
const match = findFirstIncompleteTag(chunk, tagSet);
|
|
7000
7011
|
if (!match) {
|
|
7001
7012
|
splitCompleteHtmlFromText(chunk, baseToken);
|
|
7002
7013
|
return;
|
|
@@ -7045,7 +7056,27 @@ function fixStreamingHtmlInlineChildren(children) {
|
|
|
7045
7056
|
pendingBuffer: pendingAtEnd ?? void 0
|
|
7046
7057
|
};
|
|
7047
7058
|
}
|
|
7048
|
-
function applyFixHtmlInlineTokens(md) {
|
|
7059
|
+
function applyFixHtmlInlineTokens(md, options = {}) {
|
|
7060
|
+
const commonHtmlTags = buildCommonHtmlTagSet(options.customHtmlTags);
|
|
7061
|
+
const autoCloseInlineTagSet = new Set([
|
|
7062
|
+
"a",
|
|
7063
|
+
"span",
|
|
7064
|
+
"strong",
|
|
7065
|
+
"em",
|
|
7066
|
+
"b",
|
|
7067
|
+
"i",
|
|
7068
|
+
"u"
|
|
7069
|
+
]);
|
|
7070
|
+
const customTagSet = /* @__PURE__ */ new Set();
|
|
7071
|
+
if (options.customHtmlTags?.length) for (const t of options.customHtmlTags) {
|
|
7072
|
+
const raw = String(t ?? "").trim();
|
|
7073
|
+
if (!raw) continue;
|
|
7074
|
+
const m = raw.match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
7075
|
+
if (!m) continue;
|
|
7076
|
+
const name = m[1].toLowerCase();
|
|
7077
|
+
customTagSet.add(name);
|
|
7078
|
+
autoCloseInlineTagSet.add(name);
|
|
7079
|
+
}
|
|
7049
7080
|
md.core.ruler.after("inline", "fix_html_inline_streaming", (state) => {
|
|
7050
7081
|
const toks = state.tokens ?? [];
|
|
7051
7082
|
for (const t of toks) {
|
|
@@ -7059,7 +7090,7 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
7059
7090
|
}] : null;
|
|
7060
7091
|
if (!sourceChildren) continue;
|
|
7061
7092
|
try {
|
|
7062
|
-
const fixed = fixStreamingHtmlInlineChildren(sourceChildren);
|
|
7093
|
+
const fixed = fixStreamingHtmlInlineChildren(sourceChildren, commonHtmlTags);
|
|
7063
7094
|
tok.children = fixed.children;
|
|
7064
7095
|
if (fixed.pendingBuffer) {
|
|
7065
7096
|
const idx = originalContent.lastIndexOf(fixed.pendingBuffer);
|
|
@@ -7125,7 +7156,26 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
7125
7156
|
].includes(tag)) continue;
|
|
7126
7157
|
t.type = "inline";
|
|
7127
7158
|
const loading = t.content?.toLowerCase().includes(`</${tag}>`) ? false : t.loading !== void 0 ? t.loading : true;
|
|
7128
|
-
|
|
7159
|
+
const attrs = [];
|
|
7160
|
+
const attrRegex = /\s([\w:-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
7161
|
+
let match;
|
|
7162
|
+
while ((match = attrRegex.exec(t.content || "")) !== null) {
|
|
7163
|
+
const attrName = match[1];
|
|
7164
|
+
const attrValue = match[2] || match[3] || match[4] || "";
|
|
7165
|
+
attrs.push([attrName, attrValue]);
|
|
7166
|
+
}
|
|
7167
|
+
if (customTagSet.has(tag)) {
|
|
7168
|
+
const contentMatch = t.content?.match(new RegExp(`<\\s*${tag}[^>]*>([\\s\\S]*?)<\\s*\\/\\s*${tag}\\s*>`, "i"));
|
|
7169
|
+
const raw$1 = t.content;
|
|
7170
|
+
t.children = [{
|
|
7171
|
+
type: tag,
|
|
7172
|
+
content: contentMatch ? contentMatch[1] : "",
|
|
7173
|
+
raw: raw$1,
|
|
7174
|
+
attrs,
|
|
7175
|
+
tag,
|
|
7176
|
+
loading
|
|
7177
|
+
}];
|
|
7178
|
+
} else t.children = [{
|
|
7129
7179
|
type: "html_block",
|
|
7130
7180
|
content: t.content,
|
|
7131
7181
|
tag,
|
|
@@ -7135,16 +7185,8 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
7135
7185
|
}
|
|
7136
7186
|
if (!t || t.type !== "inline") continue;
|
|
7137
7187
|
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)) {
|
|
7188
|
+
const tag = (t.children[0].content?.match(/<([^\s>/]+)/)?.[1] ?? "").toLowerCase();
|
|
7189
|
+
if (autoCloseInlineTagSet.has(tag)) {
|
|
7148
7190
|
t.children[0].loading = true;
|
|
7149
7191
|
t.children[0].tag = tag;
|
|
7150
7192
|
t.children.push({
|
|
@@ -7161,16 +7203,8 @@ function applyFixHtmlInlineTokens(md) {
|
|
|
7161
7203
|
}];
|
|
7162
7204
|
continue;
|
|
7163
7205
|
} 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;
|
|
7206
|
+
const tag = (t.children[0].content?.match(/<([^\s>/]+)/)?.[1] ?? "").toLowerCase();
|
|
7207
|
+
if (autoCloseInlineTagSet.has(tag)) continue;
|
|
7174
7208
|
t.children = [{
|
|
7175
7209
|
type: "html_block",
|
|
7176
7210
|
loading: false,
|
|
@@ -8500,7 +8534,7 @@ function factory(opts = {}) {
|
|
|
8500
8534
|
applyFixListItem(md);
|
|
8501
8535
|
applyFixTableTokens(md);
|
|
8502
8536
|
applyRenderRules(md);
|
|
8503
|
-
applyFixHtmlInlineTokens(md);
|
|
8537
|
+
applyFixHtmlInlineTokens(md, { customHtmlTags: opts.customHtmlTags });
|
|
8504
8538
|
return md;
|
|
8505
8539
|
}
|
|
8506
8540
|
|
|
@@ -8549,7 +8583,10 @@ function parseEmphasisToken(tokens, startIndex, options) {
|
|
|
8549
8583
|
innerTokens.push(tokens[i]);
|
|
8550
8584
|
i++;
|
|
8551
8585
|
}
|
|
8552
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8586
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8587
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
8588
|
+
customHtmlTags: options?.customHtmlTags
|
|
8589
|
+
}));
|
|
8553
8590
|
return {
|
|
8554
8591
|
node: {
|
|
8555
8592
|
type: "emphasis",
|
|
@@ -8657,7 +8694,10 @@ function parseHighlightToken(tokens, startIndex, options) {
|
|
|
8657
8694
|
innerTokens.push(tokens[i]);
|
|
8658
8695
|
i++;
|
|
8659
8696
|
}
|
|
8660
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8697
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8698
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
8699
|
+
customHtmlTags: options?.customHtmlTags
|
|
8700
|
+
}));
|
|
8661
8701
|
return {
|
|
8662
8702
|
node: {
|
|
8663
8703
|
type: "highlight",
|
|
@@ -8696,6 +8736,12 @@ function isClosingTag(html) {
|
|
|
8696
8736
|
function isSelfClosing(tag, html) {
|
|
8697
8737
|
return /\/\s*>\s*$/.test(html) || VOID_TAGS$1.has(tag);
|
|
8698
8738
|
}
|
|
8739
|
+
function normalizeCustomTag(t) {
|
|
8740
|
+
const raw = String(t ?? "").trim();
|
|
8741
|
+
if (!raw) return "";
|
|
8742
|
+
const m = raw.match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
8743
|
+
return m ? m[1].toLowerCase() : "";
|
|
8744
|
+
}
|
|
8699
8745
|
function tokenToRaw(token) {
|
|
8700
8746
|
const shape = token;
|
|
8701
8747
|
const raw = shape.raw ?? shape.content ?? shape.markup ?? "";
|
|
@@ -8750,6 +8796,8 @@ function collectHtmlFragment(tokens, startIndex, tag) {
|
|
|
8750
8796
|
function parseHtmlInlineCodeToken(token, tokens, i, parseInlineTokens$1, raw, pPreToken, options) {
|
|
8751
8797
|
const code$1 = String(token.content ?? "");
|
|
8752
8798
|
const tag = getTagName(code$1);
|
|
8799
|
+
const customTags = options?.customHtmlTags;
|
|
8800
|
+
const customTagSet = customTags && customTags.length ? new Set(customTags.map(normalizeCustomTag).filter(Boolean)) : null;
|
|
8753
8801
|
if (!tag) return [{
|
|
8754
8802
|
type: "inline_code",
|
|
8755
8803
|
code: code$1,
|
|
@@ -8792,7 +8840,7 @@ function parseHtmlInlineCodeToken(token, tokens, i, parseInlineTokens$1, raw, pP
|
|
|
8792
8840
|
}, fragment$1.nextIndex];
|
|
8793
8841
|
}
|
|
8794
8842
|
if (selfClosing) return [{
|
|
8795
|
-
type: "html_inline",
|
|
8843
|
+
type: customTagSet?.has(tag) ? tag : "html_inline",
|
|
8796
8844
|
tag,
|
|
8797
8845
|
content: code$1,
|
|
8798
8846
|
children: [],
|
|
@@ -8815,9 +8863,27 @@ function parseHtmlInlineCodeToken(token, tokens, i, parseInlineTokens$1, raw, pP
|
|
|
8815
8863
|
autoClosed = true;
|
|
8816
8864
|
loading = true;
|
|
8817
8865
|
}
|
|
8866
|
+
const attrs = [];
|
|
8867
|
+
const attrRegex = /\s([\w:-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
8868
|
+
let match;
|
|
8869
|
+
while ((match = attrRegex.exec(code$1)) !== null) {
|
|
8870
|
+
const attrName = match[1];
|
|
8871
|
+
const attrValue = match[2] || match[3] || match[4] || "";
|
|
8872
|
+
attrs.push([attrName, attrValue]);
|
|
8873
|
+
}
|
|
8874
|
+
if (customTagSet?.has(tag)) return [{
|
|
8875
|
+
type: tag,
|
|
8876
|
+
tag,
|
|
8877
|
+
attrs,
|
|
8878
|
+
content: fragment.innerTokens.length ? stringifyTokens(fragment.innerTokens) : "",
|
|
8879
|
+
raw: content,
|
|
8880
|
+
loading: token.loading || loading,
|
|
8881
|
+
autoClosed
|
|
8882
|
+
}, fragment.nextIndex];
|
|
8818
8883
|
return [{
|
|
8819
8884
|
type: "html_inline",
|
|
8820
8885
|
tag,
|
|
8886
|
+
attrs,
|
|
8821
8887
|
content,
|
|
8822
8888
|
children,
|
|
8823
8889
|
raw: content,
|
|
@@ -8883,7 +8949,10 @@ function parseInsertToken(tokens, startIndex, options) {
|
|
|
8883
8949
|
innerTokens.push(tokens[i]);
|
|
8884
8950
|
i++;
|
|
8885
8951
|
}
|
|
8886
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8952
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
8953
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
8954
|
+
customHtmlTags: options?.customHtmlTags
|
|
8955
|
+
}));
|
|
8887
8956
|
return {
|
|
8888
8957
|
node: {
|
|
8889
8958
|
type: "insert",
|
|
@@ -8909,7 +8978,10 @@ function parseLinkToken(tokens, startIndex, options) {
|
|
|
8909
8978
|
i++;
|
|
8910
8979
|
}
|
|
8911
8980
|
if (tokens[i]?.type === "link_close") loading = false;
|
|
8912
|
-
const children = parseInlineTokens(linkTokens, void 0, void 0, {
|
|
8981
|
+
const children = parseInlineTokens(linkTokens, void 0, void 0, {
|
|
8982
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
8983
|
+
customHtmlTags: options?.customHtmlTags
|
|
8984
|
+
});
|
|
8913
8985
|
const linkText = children.map((node) => {
|
|
8914
8986
|
const nodeAny = node;
|
|
8915
8987
|
if ("content" in node) return String(nodeAny.content ?? "");
|
|
@@ -8964,7 +9036,10 @@ function parseStrikethroughToken(tokens, startIndex, options) {
|
|
|
8964
9036
|
innerTokens.push(tokens[i]);
|
|
8965
9037
|
i++;
|
|
8966
9038
|
}
|
|
8967
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9039
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9040
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9041
|
+
customHtmlTags: options?.customHtmlTags
|
|
9042
|
+
}));
|
|
8968
9043
|
return {
|
|
8969
9044
|
node: {
|
|
8970
9045
|
type: "strikethrough",
|
|
@@ -8993,7 +9068,10 @@ function parseStrongToken(tokens, startIndex, raw, options) {
|
|
|
8993
9068
|
innerTokens.push(tokens[i]);
|
|
8994
9069
|
i++;
|
|
8995
9070
|
}
|
|
8996
|
-
children.push(...parseInlineTokens(innerTokens, raw, void 0, {
|
|
9071
|
+
children.push(...parseInlineTokens(innerTokens, raw, void 0, {
|
|
9072
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9073
|
+
customHtmlTags: options?.customHtmlTags
|
|
9074
|
+
}));
|
|
8997
9075
|
return {
|
|
8998
9076
|
node: {
|
|
8999
9077
|
type: "strong",
|
|
@@ -9016,7 +9094,10 @@ function parseSubscriptToken(tokens, startIndex, options) {
|
|
|
9016
9094
|
innerTokens.push(tokens[i]);
|
|
9017
9095
|
i++;
|
|
9018
9096
|
}
|
|
9019
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9097
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9098
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9099
|
+
customHtmlTags: options?.customHtmlTags
|
|
9100
|
+
}));
|
|
9020
9101
|
const startContent = String(tokens[startIndex].content ?? "");
|
|
9021
9102
|
const display = subText || startContent;
|
|
9022
9103
|
return {
|
|
@@ -9045,7 +9126,10 @@ function parseSuperscriptToken(tokens, startIndex, options) {
|
|
|
9045
9126
|
innerTokens.push(tokens[i]);
|
|
9046
9127
|
i++;
|
|
9047
9128
|
}
|
|
9048
|
-
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9129
|
+
children.push(...parseInlineTokens(innerTokens, void 0, void 0, {
|
|
9130
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
9131
|
+
customHtmlTags: options?.customHtmlTags
|
|
9132
|
+
}));
|
|
9049
9133
|
return {
|
|
9050
9134
|
node: {
|
|
9051
9135
|
type: "superscript",
|
|
@@ -9922,7 +10006,10 @@ function parseDefinitionList(tokens, index, options) {
|
|
|
9922
10006
|
let definitionNodes = [];
|
|
9923
10007
|
while (j < tokens.length && tokens[j].type !== "dl_close") if (tokens[j].type === "dt_open") {
|
|
9924
10008
|
const termToken = tokens[j + 1];
|
|
9925
|
-
termNodes = parseInlineTokens(termToken.children || [], void 0, void 0, {
|
|
10009
|
+
termNodes = parseInlineTokens(termToken.children || [], void 0, void 0, {
|
|
10010
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10011
|
+
customHtmlTags: options?.customHtmlTags
|
|
10012
|
+
});
|
|
9926
10013
|
j += 3;
|
|
9927
10014
|
} else if (tokens[j].type === "dd_open") {
|
|
9928
10015
|
let k = j + 1;
|
|
@@ -9931,7 +10018,10 @@ function parseDefinitionList(tokens, index, options) {
|
|
|
9931
10018
|
const contentToken = tokens[k + 1];
|
|
9932
10019
|
definitionNodes.push({
|
|
9933
10020
|
type: "paragraph",
|
|
9934
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10021
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10022
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10023
|
+
customHtmlTags: options?.customHtmlTags
|
|
10024
|
+
}),
|
|
9935
10025
|
raw: String(contentToken.content ?? "")
|
|
9936
10026
|
});
|
|
9937
10027
|
k += 3;
|
|
@@ -9967,7 +10057,10 @@ function parseFootnote(tokens, index, options) {
|
|
|
9967
10057
|
if (tokens[j + 2].type === "footnote_anchor") children.push(tokens[j + 2]);
|
|
9968
10058
|
footnoteChildren.push({
|
|
9969
10059
|
type: "paragraph",
|
|
9970
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10060
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10061
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10062
|
+
customHtmlTags: options?.customHtmlTags
|
|
10063
|
+
}),
|
|
9971
10064
|
raw: String(contentToken.content ?? "")
|
|
9972
10065
|
});
|
|
9973
10066
|
j += 3;
|
|
@@ -9992,7 +10085,10 @@ function parseHeading(tokens, index, options) {
|
|
|
9992
10085
|
type: "heading",
|
|
9993
10086
|
level: headingLevel,
|
|
9994
10087
|
text: headingContent,
|
|
9995
|
-
children: parseInlineTokens(headingContentToken.children || [], headingContent, void 0, {
|
|
10088
|
+
children: parseInlineTokens(headingContentToken.children || [], headingContent, void 0, {
|
|
10089
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10090
|
+
customHtmlTags: options?.customHtmlTags
|
|
10091
|
+
}),
|
|
9996
10092
|
raw: headingContent
|
|
9997
10093
|
};
|
|
9998
10094
|
}
|
|
@@ -10103,7 +10199,10 @@ function parseTable(tokens, index, options) {
|
|
|
10103
10199
|
cells.push({
|
|
10104
10200
|
type: "table_cell",
|
|
10105
10201
|
header: isHeaderCell || isHeader,
|
|
10106
|
-
children: parseInlineTokens(contentToken.children || [], content, void 0, {
|
|
10202
|
+
children: parseInlineTokens(contentToken.children || [], content, void 0, {
|
|
10203
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10204
|
+
customHtmlTags: options?.customHtmlTags
|
|
10205
|
+
}),
|
|
10107
10206
|
raw: content,
|
|
10108
10207
|
align
|
|
10109
10208
|
});
|
|
@@ -10150,7 +10249,19 @@ function parseBasicBlockToken(tokens, index, options) {
|
|
|
10150
10249
|
case "code_block": return [parseCodeBlock(token), index + 1];
|
|
10151
10250
|
case "fence": return [parseFenceToken(token), index + 1];
|
|
10152
10251
|
case "math_block": return [parseMathBlock(token), index + 1];
|
|
10153
|
-
case "html_block":
|
|
10252
|
+
case "html_block": {
|
|
10253
|
+
const htmlBlockNode = parseHtmlBlock(token);
|
|
10254
|
+
if (options?.customHtmlTags && htmlBlockNode.tag) {
|
|
10255
|
+
if (new Set(options.customHtmlTags.map((t) => {
|
|
10256
|
+
const m = String(t ?? "").trim().match(/^[<\s/]*([A-Z][\w-]*)/i);
|
|
10257
|
+
return m ? m[1].toLowerCase() : "";
|
|
10258
|
+
}).filter(Boolean)).has(htmlBlockNode.tag)) return [{
|
|
10259
|
+
...htmlBlockNode,
|
|
10260
|
+
type: htmlBlockNode.tag
|
|
10261
|
+
}, index + 1];
|
|
10262
|
+
}
|
|
10263
|
+
return [htmlBlockNode, index + 1];
|
|
10264
|
+
}
|
|
10154
10265
|
case "table_open": {
|
|
10155
10266
|
const [tableNode, newIndex] = parseTable(tokens, index, options);
|
|
10156
10267
|
return [tableNode, newIndex];
|
|
@@ -10211,7 +10322,10 @@ function parseList(tokens, index, options) {
|
|
|
10211
10322
|
}
|
|
10212
10323
|
itemChildren.push({
|
|
10213
10324
|
type: "paragraph",
|
|
10214
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), preToken, {
|
|
10325
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), preToken, {
|
|
10326
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10327
|
+
customHtmlTags: options?.customHtmlTags
|
|
10328
|
+
}),
|
|
10215
10329
|
raw: String(contentToken.content ?? "")
|
|
10216
10330
|
});
|
|
10217
10331
|
k += 3;
|
|
@@ -10265,7 +10379,10 @@ function parseAdmonition(tokens, index, match, options) {
|
|
|
10265
10379
|
const contentToken = tokens[j + 1];
|
|
10266
10380
|
if (contentToken) admonitionChildren.push({
|
|
10267
10381
|
type: "paragraph",
|
|
10268
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10382
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10383
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10384
|
+
customHtmlTags: options?.customHtmlTags
|
|
10385
|
+
}),
|
|
10269
10386
|
raw: String(contentToken.content ?? "")
|
|
10270
10387
|
});
|
|
10271
10388
|
j += 3;
|
|
@@ -10334,7 +10451,10 @@ function parseContainer(tokens, index, options) {
|
|
|
10334
10451
|
const _children = i !== -1 ? childrenArr.slice(0, i) : childrenArr;
|
|
10335
10452
|
children.push({
|
|
10336
10453
|
type: "paragraph",
|
|
10337
|
-
children: parseInlineTokens(_children || [], void 0, void 0, {
|
|
10454
|
+
children: parseInlineTokens(_children || [], void 0, void 0, {
|
|
10455
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10456
|
+
customHtmlTags: options?.customHtmlTags
|
|
10457
|
+
}),
|
|
10338
10458
|
raw: String(contentToken.content ?? "").replace(/\n:+$/, "").replace(/\n\s*:::\s*$/, "")
|
|
10339
10459
|
});
|
|
10340
10460
|
}
|
|
@@ -10388,7 +10508,10 @@ function parseBlockquote(tokens, index, options) {
|
|
|
10388
10508
|
const contentToken = tokens[j + 1];
|
|
10389
10509
|
blockquoteChildren.push({
|
|
10390
10510
|
type: "paragraph",
|
|
10391
|
-
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10511
|
+
children: parseInlineTokens(contentToken.children || [], String(contentToken.content ?? ""), void 0, {
|
|
10512
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10513
|
+
customHtmlTags: options?.customHtmlTags
|
|
10514
|
+
}),
|
|
10392
10515
|
raw: String(contentToken.content ?? "")
|
|
10393
10516
|
});
|
|
10394
10517
|
j += 3;
|
|
@@ -10439,7 +10562,10 @@ function parseParagraph(tokens, index, options) {
|
|
|
10439
10562
|
const paragraphContent = String(paragraphContentToken.content ?? "");
|
|
10440
10563
|
return {
|
|
10441
10564
|
type: "paragraph",
|
|
10442
|
-
children: parseInlineTokens(paragraphContentToken.children || [], paragraphContent, void 0, {
|
|
10565
|
+
children: parseInlineTokens(paragraphContentToken.children || [], paragraphContent, void 0, {
|
|
10566
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10567
|
+
customHtmlTags: options?.customHtmlTags
|
|
10568
|
+
}),
|
|
10443
10569
|
raw: paragraphContent
|
|
10444
10570
|
};
|
|
10445
10571
|
}
|
|
@@ -10516,7 +10642,10 @@ function processTokens(tokens, options) {
|
|
|
10516
10642
|
i++;
|
|
10517
10643
|
break;
|
|
10518
10644
|
case "inline":
|
|
10519
|
-
result.push(...parseInlineTokens(token.children || [], String(token.content ?? ""), void 0, {
|
|
10645
|
+
result.push(...parseInlineTokens(token.children || [], String(token.content ?? ""), void 0, {
|
|
10646
|
+
requireClosingStrong: options?.requireClosingStrong,
|
|
10647
|
+
customHtmlTags: options?.customHtmlTags
|
|
10648
|
+
}));
|
|
10520
10649
|
i += 1;
|
|
10521
10650
|
break;
|
|
10522
10651
|
default:
|