stream-markdown-parser 1.0.2 → 1.0.5
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.cjs +19847 -0
- package/dist/index.d.cts +623 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +403 -18
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
//#region src/factory.d.ts
|
|
2
|
+
interface FactoryOptions extends Record<string, unknown> {
|
|
3
|
+
markdownItOptions?: Record<string, unknown>;
|
|
4
|
+
enableMath?: boolean;
|
|
5
|
+
enableContainers?: boolean;
|
|
6
|
+
mathOptions?: {
|
|
7
|
+
commands?: string[];
|
|
8
|
+
escapeExclamation?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Custom HTML-like tag names that should participate in streaming mid-state
|
|
12
|
+
* suppression and be emitted as custom nodes (e.g. ['thinking']).
|
|
13
|
+
*/
|
|
14
|
+
customHtmlTags?: readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Whether to enable the fix for indented code blocks that should be paragraphs.
|
|
17
|
+
* Default: true
|
|
18
|
+
*/
|
|
19
|
+
enableFixIndentedCodeBlock?: boolean;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/markdown-it-types.d.ts
|
|
23
|
+
interface MarkdownItOptions extends Record<string, unknown> {
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
html?: boolean;
|
|
26
|
+
xhtmlOut?: boolean;
|
|
27
|
+
breaks?: boolean;
|
|
28
|
+
langPrefix?: string;
|
|
29
|
+
linkify?: boolean;
|
|
30
|
+
typographer?: boolean;
|
|
31
|
+
quotes?: string | string[];
|
|
32
|
+
highlight?: ((str: string, lang: string, attrs: string) => string | Promise<string>) | null;
|
|
33
|
+
validateLink?: (url: string) => boolean;
|
|
34
|
+
}
|
|
35
|
+
interface Token {
|
|
36
|
+
type: string;
|
|
37
|
+
tag: string;
|
|
38
|
+
attrs: [string, string][] | null;
|
|
39
|
+
map: [number, number] | null;
|
|
40
|
+
nesting: number;
|
|
41
|
+
level: number;
|
|
42
|
+
children: Token[] | null;
|
|
43
|
+
content: string;
|
|
44
|
+
markup: string;
|
|
45
|
+
info: string;
|
|
46
|
+
meta: Record<string, unknown> | null;
|
|
47
|
+
block: boolean;
|
|
48
|
+
hidden: boolean;
|
|
49
|
+
attrIndex: (name: string) => number;
|
|
50
|
+
attrPush: (attrData: [string, string]) => void;
|
|
51
|
+
attrSet: (name: string, value: string) => void;
|
|
52
|
+
attrGet: (name: string) => string | null;
|
|
53
|
+
attrJoin: (name: string, value: string) => void;
|
|
54
|
+
}
|
|
55
|
+
interface RuleOptions {
|
|
56
|
+
alt?: string[];
|
|
57
|
+
}
|
|
58
|
+
type RuleHandler = (...args: any[]) => unknown;
|
|
59
|
+
interface RuleManager {
|
|
60
|
+
before: (name: string, ruleName: string, fn: RuleHandler, options?: RuleOptions) => void;
|
|
61
|
+
after: (name: string, ruleName: string, fn: RuleHandler, options?: RuleOptions) => void;
|
|
62
|
+
at: (ruleName: string, fn: RuleHandler, options?: RuleOptions) => void;
|
|
63
|
+
push: (ruleName: string, fn: RuleHandler, options?: RuleOptions) => void;
|
|
64
|
+
enable: (list: string | string[], ignoreInvalid?: boolean) => void;
|
|
65
|
+
disable: (list: string | string[], ignoreInvalid?: boolean) => void;
|
|
66
|
+
getRules: (chainName?: string) => RuleHandler[];
|
|
67
|
+
}
|
|
68
|
+
interface ParserBlock {
|
|
69
|
+
ruler: RuleManager;
|
|
70
|
+
parse: (src: string, md: MarkdownIt, env: Record<string, unknown>, outTokens: Token[]) => void;
|
|
71
|
+
}
|
|
72
|
+
interface ParserInline {
|
|
73
|
+
ruler: RuleManager;
|
|
74
|
+
ruler2: RuleManager;
|
|
75
|
+
}
|
|
76
|
+
interface RendererRuleRecord {
|
|
77
|
+
[type: string]: ((tokens: Token[], idx: number, options?: unknown, env?: unknown, self?: unknown) => unknown) | undefined;
|
|
78
|
+
}
|
|
79
|
+
interface Renderer {
|
|
80
|
+
rules: RendererRuleRecord;
|
|
81
|
+
render: (tokens: Token[], options?: unknown, env?: unknown) => string;
|
|
82
|
+
renderToken: (tokens: Token[], idx: number, options?: unknown) => string;
|
|
83
|
+
}
|
|
84
|
+
interface MarkdownIt {
|
|
85
|
+
core: {
|
|
86
|
+
ruler: RuleManager;
|
|
87
|
+
};
|
|
88
|
+
block: ParserBlock;
|
|
89
|
+
inline: ParserInline;
|
|
90
|
+
renderer: Renderer;
|
|
91
|
+
options: MarkdownItOptions;
|
|
92
|
+
utils: {
|
|
93
|
+
escapeHtml: (value: string) => string;
|
|
94
|
+
[key: string]: unknown;
|
|
95
|
+
};
|
|
96
|
+
linkify?: unknown;
|
|
97
|
+
helpers?: Record<string, unknown>;
|
|
98
|
+
set: (options: MarkdownItOptions) => this;
|
|
99
|
+
configure: (preset: string | {
|
|
100
|
+
options?: MarkdownItOptions;
|
|
101
|
+
components?: unknown;
|
|
102
|
+
}) => this;
|
|
103
|
+
enable: (list: string | string[], ignoreInvalid?: boolean) => this;
|
|
104
|
+
disable: (list: string | string[], ignoreInvalid?: boolean) => this;
|
|
105
|
+
use: <TParams extends unknown[] = any[]>(plugin: CompatibleMarkdownItPlugin<TParams>, ...params: TParams) => this;
|
|
106
|
+
parse: (src: string, env?: Record<string, unknown>) => Token[];
|
|
107
|
+
stream?: {
|
|
108
|
+
enabled?: boolean;
|
|
109
|
+
parse?: (src: string, env?: Record<string, unknown>) => Token[];
|
|
110
|
+
reset?: () => void;
|
|
111
|
+
peek?: () => Token[];
|
|
112
|
+
stats?: () => unknown;
|
|
113
|
+
resetStats?: () => void;
|
|
114
|
+
};
|
|
115
|
+
parseInline: (src: string, env?: Record<string, unknown>) => Token[];
|
|
116
|
+
render: (src: string, env?: Record<string, unknown>) => string;
|
|
117
|
+
renderInline: (src: string, env?: Record<string, unknown>) => string;
|
|
118
|
+
}
|
|
119
|
+
type MarkdownItPlugin<TParams extends unknown[] = any[]> = (md: MarkdownIt, ...params: TParams) => unknown;
|
|
120
|
+
type CompatibleMarkdownItPlugin<TParams extends unknown[] = any[]> = MarkdownItPlugin<TParams> | ((md: any, ...params: TParams) => unknown);
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/types.d.ts
|
|
123
|
+
interface BaseNode {
|
|
124
|
+
type: string;
|
|
125
|
+
raw: string;
|
|
126
|
+
loading?: boolean;
|
|
127
|
+
code?: string;
|
|
128
|
+
diff?: boolean;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A catch‑all node type for user extensions.
|
|
132
|
+
* Must still satisfy the renderer contract (`type` + `raw`), but may carry
|
|
133
|
+
* arbitrary extra fields.
|
|
134
|
+
*/
|
|
135
|
+
type UnknownNode = BaseNode & Record<string, unknown>;
|
|
136
|
+
interface TextNode extends BaseNode {
|
|
137
|
+
type: 'text';
|
|
138
|
+
content: string;
|
|
139
|
+
center?: boolean;
|
|
140
|
+
}
|
|
141
|
+
interface HeadingNode extends BaseNode {
|
|
142
|
+
type: 'heading';
|
|
143
|
+
level: number;
|
|
144
|
+
text: string;
|
|
145
|
+
attrs?: Record<string, string | boolean>;
|
|
146
|
+
children: ParsedNode[];
|
|
147
|
+
}
|
|
148
|
+
interface ParagraphNode extends BaseNode {
|
|
149
|
+
type: 'paragraph';
|
|
150
|
+
children: ParsedNode[];
|
|
151
|
+
maybeCheckbox?: boolean;
|
|
152
|
+
}
|
|
153
|
+
interface InlineNode extends BaseNode {
|
|
154
|
+
type: 'inline';
|
|
155
|
+
children: ParsedNode[];
|
|
156
|
+
content?: string;
|
|
157
|
+
}
|
|
158
|
+
interface ListNode extends BaseNode {
|
|
159
|
+
type: 'list';
|
|
160
|
+
ordered: boolean;
|
|
161
|
+
start?: number;
|
|
162
|
+
items: ListItemNode[];
|
|
163
|
+
}
|
|
164
|
+
interface ListItemNode extends BaseNode {
|
|
165
|
+
type: 'list_item';
|
|
166
|
+
children: ParsedNode[];
|
|
167
|
+
}
|
|
168
|
+
interface CodeBlockNode extends BaseNode {
|
|
169
|
+
type: 'code_block';
|
|
170
|
+
language: string;
|
|
171
|
+
code: string;
|
|
172
|
+
startLine?: number;
|
|
173
|
+
endLine?: number;
|
|
174
|
+
loading?: boolean;
|
|
175
|
+
diff?: boolean;
|
|
176
|
+
originalCode?: string;
|
|
177
|
+
updatedCode?: string;
|
|
178
|
+
raw: string;
|
|
179
|
+
}
|
|
180
|
+
interface HtmlBlockNode extends BaseNode {
|
|
181
|
+
type: 'html_block';
|
|
182
|
+
attrs?: [string, string][] | null;
|
|
183
|
+
tag: string;
|
|
184
|
+
content: string;
|
|
185
|
+
children?: ParsedNode[];
|
|
186
|
+
}
|
|
187
|
+
interface HtmlInlineNode extends BaseNode {
|
|
188
|
+
type: 'html_inline';
|
|
189
|
+
tag?: string;
|
|
190
|
+
content: string;
|
|
191
|
+
children: ParsedNode[];
|
|
192
|
+
/**
|
|
193
|
+
* True when the parser auto-appended a closing tag for streaming stability.
|
|
194
|
+
* The original source is still incomplete (no explicit close typed yet).
|
|
195
|
+
*/
|
|
196
|
+
autoClosed?: boolean;
|
|
197
|
+
}
|
|
198
|
+
type CustomComponentAttrs = [string, string][] | Record<string, string | boolean> | Array<{
|
|
199
|
+
name: string;
|
|
200
|
+
value: string | boolean;
|
|
201
|
+
}> | null;
|
|
202
|
+
/**
|
|
203
|
+
* A generic node shape for custom HTML-like components.
|
|
204
|
+
* When a tag name is included in `customHtmlTags`, the parser emits a node
|
|
205
|
+
* whose `type` equals that tag name and carries the raw HTML `content`
|
|
206
|
+
* plus extracted `attrs` from user transforms.
|
|
207
|
+
*/
|
|
208
|
+
interface CustomComponentNode extends BaseNode {
|
|
209
|
+
/** The custom tag name (same as `tag`) */
|
|
210
|
+
type: string;
|
|
211
|
+
tag: string;
|
|
212
|
+
content: string;
|
|
213
|
+
attrs?: CustomComponentAttrs;
|
|
214
|
+
children?: ParsedNode[];
|
|
215
|
+
autoClosed?: boolean;
|
|
216
|
+
}
|
|
217
|
+
interface InlineCodeNode extends BaseNode {
|
|
218
|
+
type: 'inline_code';
|
|
219
|
+
code: string;
|
|
220
|
+
}
|
|
221
|
+
interface LinkNode extends BaseNode {
|
|
222
|
+
type: 'link';
|
|
223
|
+
href: string;
|
|
224
|
+
title: string | null;
|
|
225
|
+
text: string;
|
|
226
|
+
attrs?: [string, string][];
|
|
227
|
+
children: ParsedNode[];
|
|
228
|
+
}
|
|
229
|
+
interface ImageNode extends BaseNode {
|
|
230
|
+
type: 'image';
|
|
231
|
+
src: string;
|
|
232
|
+
alt: string;
|
|
233
|
+
title: string | null;
|
|
234
|
+
}
|
|
235
|
+
interface ThematicBreakNode extends BaseNode {
|
|
236
|
+
type: 'thematic_break';
|
|
237
|
+
}
|
|
238
|
+
interface MermaidBlockNode {
|
|
239
|
+
node: {
|
|
240
|
+
type: 'code_block';
|
|
241
|
+
language: string;
|
|
242
|
+
code: string;
|
|
243
|
+
loading?: boolean;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
type MarkdownRender = {
|
|
247
|
+
content: string;
|
|
248
|
+
nodes?: undefined;
|
|
249
|
+
} | {
|
|
250
|
+
content?: undefined;
|
|
251
|
+
nodes: BaseNode[];
|
|
252
|
+
};
|
|
253
|
+
interface BlockquoteNode extends BaseNode {
|
|
254
|
+
type: 'blockquote';
|
|
255
|
+
children: ParsedNode[];
|
|
256
|
+
}
|
|
257
|
+
interface TableNode extends BaseNode {
|
|
258
|
+
type: 'table';
|
|
259
|
+
header: TableRowNode;
|
|
260
|
+
rows: TableRowNode[];
|
|
261
|
+
}
|
|
262
|
+
interface TableRowNode extends BaseNode {
|
|
263
|
+
type: 'table_row';
|
|
264
|
+
cells: TableCellNode[];
|
|
265
|
+
}
|
|
266
|
+
interface TableCellNode extends BaseNode {
|
|
267
|
+
type: 'table_cell';
|
|
268
|
+
header: boolean;
|
|
269
|
+
children: ParsedNode[];
|
|
270
|
+
align?: 'left' | 'right' | 'center';
|
|
271
|
+
}
|
|
272
|
+
interface DefinitionListNode extends BaseNode {
|
|
273
|
+
type: 'definition_list';
|
|
274
|
+
items: DefinitionItemNode[];
|
|
275
|
+
}
|
|
276
|
+
interface DefinitionItemNode extends BaseNode {
|
|
277
|
+
type: 'definition_item';
|
|
278
|
+
term: ParsedNode[];
|
|
279
|
+
definition: ParsedNode[];
|
|
280
|
+
}
|
|
281
|
+
interface FootnoteNode extends BaseNode {
|
|
282
|
+
type: 'footnote';
|
|
283
|
+
id: string;
|
|
284
|
+
children: ParsedNode[];
|
|
285
|
+
}
|
|
286
|
+
interface FootnoteReferenceNode extends BaseNode {
|
|
287
|
+
type: 'footnote_reference';
|
|
288
|
+
id: string;
|
|
289
|
+
}
|
|
290
|
+
interface FootnoteAnchorNode extends BaseNode {
|
|
291
|
+
type: 'footnote_anchor';
|
|
292
|
+
id: string;
|
|
293
|
+
}
|
|
294
|
+
interface AdmonitionNode extends BaseNode {
|
|
295
|
+
type: 'admonition';
|
|
296
|
+
kind: string;
|
|
297
|
+
title: string;
|
|
298
|
+
children: ParsedNode[];
|
|
299
|
+
}
|
|
300
|
+
interface VmrContainerNode extends BaseNode {
|
|
301
|
+
type: 'vmr_container';
|
|
302
|
+
name: string;
|
|
303
|
+
/** True while the opening `:::` has been seen but the closing `:::` hasn't (streaming mid-state). */
|
|
304
|
+
loading?: boolean;
|
|
305
|
+
attrs?: Record<string, string>;
|
|
306
|
+
children: ParsedNode[];
|
|
307
|
+
}
|
|
308
|
+
interface StrongNode extends BaseNode {
|
|
309
|
+
type: 'strong';
|
|
310
|
+
children: ParsedNode[];
|
|
311
|
+
}
|
|
312
|
+
interface EmphasisNode extends BaseNode {
|
|
313
|
+
type: 'emphasis';
|
|
314
|
+
children: ParsedNode[];
|
|
315
|
+
}
|
|
316
|
+
interface StrikethroughNode extends BaseNode {
|
|
317
|
+
type: 'strikethrough';
|
|
318
|
+
children: ParsedNode[];
|
|
319
|
+
}
|
|
320
|
+
interface HighlightNode extends BaseNode {
|
|
321
|
+
type: 'highlight';
|
|
322
|
+
children: ParsedNode[];
|
|
323
|
+
}
|
|
324
|
+
interface InsertNode extends BaseNode {
|
|
325
|
+
type: 'insert';
|
|
326
|
+
children: ParsedNode[];
|
|
327
|
+
}
|
|
328
|
+
interface SubscriptNode extends BaseNode {
|
|
329
|
+
type: 'subscript';
|
|
330
|
+
children: ParsedNode[];
|
|
331
|
+
}
|
|
332
|
+
interface SuperscriptNode extends BaseNode {
|
|
333
|
+
type: 'superscript';
|
|
334
|
+
children: ParsedNode[];
|
|
335
|
+
}
|
|
336
|
+
interface CheckboxNode extends BaseNode {
|
|
337
|
+
type: 'checkbox';
|
|
338
|
+
checked: boolean;
|
|
339
|
+
}
|
|
340
|
+
interface CheckboxInputNode extends BaseNode {
|
|
341
|
+
type: 'checkbox_input';
|
|
342
|
+
checked: boolean;
|
|
343
|
+
}
|
|
344
|
+
interface EmojiNode extends BaseNode {
|
|
345
|
+
type: 'emoji';
|
|
346
|
+
name: string;
|
|
347
|
+
markup: string;
|
|
348
|
+
}
|
|
349
|
+
interface HardBreakNode extends BaseNode {
|
|
350
|
+
type: 'hardbreak';
|
|
351
|
+
}
|
|
352
|
+
interface MathInlineNode extends BaseNode {
|
|
353
|
+
type: 'math_inline';
|
|
354
|
+
content: string;
|
|
355
|
+
markup?: string;
|
|
356
|
+
}
|
|
357
|
+
interface MathBlockNode extends BaseNode {
|
|
358
|
+
type: 'math_block';
|
|
359
|
+
content: string;
|
|
360
|
+
markup?: string;
|
|
361
|
+
}
|
|
362
|
+
interface ReferenceNode extends BaseNode {
|
|
363
|
+
type: 'reference';
|
|
364
|
+
id: string;
|
|
365
|
+
}
|
|
366
|
+
type MarkdownTokenMeta = Record<string, unknown>;
|
|
367
|
+
type MarkdownTokenBase = Omit<Token, 'children' | 'meta'> & {
|
|
368
|
+
children?: MarkdownToken[] | null;
|
|
369
|
+
loading?: boolean;
|
|
370
|
+
mark?: string;
|
|
371
|
+
meta?: MarkdownTokenMeta | null;
|
|
372
|
+
raw?: string;
|
|
373
|
+
};
|
|
374
|
+
interface MarkdownTokenLite {
|
|
375
|
+
type: string;
|
|
376
|
+
tag?: string;
|
|
377
|
+
content?: string;
|
|
378
|
+
info?: string;
|
|
379
|
+
mark?: string;
|
|
380
|
+
markup?: string;
|
|
381
|
+
meta?: MarkdownTokenMeta | null;
|
|
382
|
+
map?: [number, number] | number[] | null;
|
|
383
|
+
block?: boolean;
|
|
384
|
+
hidden?: boolean;
|
|
385
|
+
attrs?: [string, string][] | null;
|
|
386
|
+
nesting?: number;
|
|
387
|
+
level?: number;
|
|
388
|
+
children?: MarkdownToken[] | null;
|
|
389
|
+
loading?: boolean;
|
|
390
|
+
raw?: string;
|
|
391
|
+
}
|
|
392
|
+
type MarkdownToken = MarkdownTokenBase | MarkdownTokenLite;
|
|
393
|
+
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 | VmrContainerNode | HardBreakNode | MathInlineNode | MathBlockNode | ReferenceNode | HtmlBlockNode | HtmlInlineNode | CustomComponentNode | UnknownNode;
|
|
394
|
+
interface CustomComponents {
|
|
395
|
+
text: unknown;
|
|
396
|
+
paragraph: unknown;
|
|
397
|
+
heading: unknown;
|
|
398
|
+
code_block: unknown;
|
|
399
|
+
list: unknown;
|
|
400
|
+
blockquote: unknown;
|
|
401
|
+
table: unknown;
|
|
402
|
+
definition_list: unknown;
|
|
403
|
+
footnote: unknown;
|
|
404
|
+
footnote_reference: unknown;
|
|
405
|
+
admonition: unknown;
|
|
406
|
+
hardbreak: unknown;
|
|
407
|
+
link: unknown;
|
|
408
|
+
image: unknown;
|
|
409
|
+
thematic_break: unknown;
|
|
410
|
+
math_inline: unknown;
|
|
411
|
+
math_block: unknown;
|
|
412
|
+
strong: unknown;
|
|
413
|
+
emphasis: unknown;
|
|
414
|
+
strikethrough: unknown;
|
|
415
|
+
highlight: unknown;
|
|
416
|
+
insert: unknown;
|
|
417
|
+
subscript: unknown;
|
|
418
|
+
superscript: unknown;
|
|
419
|
+
emoji: unknown;
|
|
420
|
+
checkbox: unknown;
|
|
421
|
+
inline_code: unknown;
|
|
422
|
+
html_inline: unknown;
|
|
423
|
+
reference: unknown;
|
|
424
|
+
mermaid: unknown;
|
|
425
|
+
[key: string]: unknown;
|
|
426
|
+
}
|
|
427
|
+
type TransformTokensHook = (tokens: MarkdownToken[]) => MarkdownToken[];
|
|
428
|
+
interface ParseOptions {
|
|
429
|
+
preTransformTokens?: TransformTokensHook;
|
|
430
|
+
postTransformTokens?: TransformTokensHook;
|
|
431
|
+
/**
|
|
432
|
+
* Defaults to 'auto': use markdown-it-ts' stream parser for non-final
|
|
433
|
+
* top-level document parses when available. Final parses and fragment parses
|
|
434
|
+
* use the regular parser unless streamParse is explicitly true.
|
|
435
|
+
*/
|
|
436
|
+
streamParse?: boolean | 'auto';
|
|
437
|
+
requireClosingStrong?: boolean;
|
|
438
|
+
/**
|
|
439
|
+
* When true, indicates the input buffer is complete (end-of-stream).
|
|
440
|
+
* This disables "mid-state" streaming behavior (e.g. unclosed math/link/code
|
|
441
|
+
* tokens staying in a loading state) and keeps trailing markers as literal text.
|
|
442
|
+
*/
|
|
443
|
+
final?: boolean;
|
|
444
|
+
/**
|
|
445
|
+
* Custom HTML-like tag names that should be emitted as custom nodes
|
|
446
|
+
* instead of `html_inline` when encountered (e.g. ['thinking']).
|
|
447
|
+
* Used by inline parsing and passed to markdown-it core rules for
|
|
448
|
+
* mid-state suppression during streaming.
|
|
449
|
+
*/
|
|
450
|
+
customHtmlTags?: readonly string[];
|
|
451
|
+
/**
|
|
452
|
+
* If provided, link nodes are only emitted when this returns true for the href.
|
|
453
|
+
* When it returns false, the link is rendered as plain text (the link text only).
|
|
454
|
+
* Typically set from the MarkdownIt instance (e.g. md.options.validateLink or
|
|
455
|
+
* md.set({ validateLink })) so that unsafe URLs (e.g. javascript:) are not
|
|
456
|
+
* output as links.
|
|
457
|
+
*/
|
|
458
|
+
validateLink?: (url: string) => boolean;
|
|
459
|
+
debug?: boolean;
|
|
460
|
+
}
|
|
461
|
+
interface InternalParseOptions extends ParseOptions {
|
|
462
|
+
__customHtmlBlockCursor?: number;
|
|
463
|
+
__disableStreamParse?: boolean;
|
|
464
|
+
__insideStrong?: boolean;
|
|
465
|
+
__markdownIt?: MarkdownIt;
|
|
466
|
+
__sourceMarkdown?: string;
|
|
467
|
+
}
|
|
468
|
+
type PostTransformNodesHook = (nodes: ParsedNode[]) => ParsedNode[];
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/parser/inline-parsers/index.d.ts
|
|
471
|
+
declare function parseInlineTokens(tokens: MarkdownToken[], raw?: string, pPreToken?: MarkdownToken, options?: ParseOptions): ParsedNode[];
|
|
472
|
+
//#endregion
|
|
473
|
+
//#region src/parser/index.d.ts
|
|
474
|
+
declare function parseMarkdownToStructure(markdown: string, md: MarkdownIt, options?: ParseOptions): ParsedNode[];
|
|
475
|
+
declare function processTokens(tokens: MarkdownToken[], options?: ParseOptions): ParsedNode[];
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/config.d.ts
|
|
478
|
+
/**
|
|
479
|
+
* MathOptions control how the math plugin normalizes content before
|
|
480
|
+
* handing it to KaTeX (or other math renderers).
|
|
481
|
+
*
|
|
482
|
+
* - commands: list of command words that should be auto-prefixed with a
|
|
483
|
+
* backslash if not already escaped (e.g. 'infty' -> '\\infty'). Use a
|
|
484
|
+
* conservative list to avoid false positives in prose.
|
|
485
|
+
* - escapeExclamation: whether to escape standalone '!' to '\\!' (default true).
|
|
486
|
+
*/
|
|
487
|
+
interface MathOptions {
|
|
488
|
+
/** List of command words to auto-escape. */
|
|
489
|
+
commands?: readonly string[];
|
|
490
|
+
/** Whether to escape standalone '!' (default: true). */
|
|
491
|
+
escapeExclamation?: boolean;
|
|
492
|
+
/**
|
|
493
|
+
* Strict delimiter mode.
|
|
494
|
+
* - When true, only explicit TeX delimiters are recognized as math:
|
|
495
|
+
* inline: `$...$` and `\\(...\\)`; block: `$$...$$` and `\\[...\\]`.
|
|
496
|
+
*
|
|
497
|
+
* Important: authors should write explicit TeX delimiters with escaped
|
|
498
|
+
* backslashes in source (for example, write `\\(...\\)` rather than
|
|
499
|
+
* an unescaped `\(...\)`). Unescaped `\(...\)` cannot be reliably
|
|
500
|
+
* distinguished from ordinary parentheses and may not be parsed as math.
|
|
501
|
+
* - Heuristics and mid-state (unclosed) math detection are disabled.
|
|
502
|
+
*/
|
|
503
|
+
strictDelimiters?: boolean;
|
|
504
|
+
}
|
|
505
|
+
declare function setDefaultMathOptions(opts: MathOptions | undefined): void;
|
|
506
|
+
//#endregion
|
|
507
|
+
//#region src/customHtmlTags.d.ts
|
|
508
|
+
declare function isHtmlLikeTagName(tag: string): boolean;
|
|
509
|
+
declare function normalizeCustomHtmlTagName(value: unknown): string;
|
|
510
|
+
declare function normalizeCustomHtmlTags(tags?: readonly string[]): string[];
|
|
511
|
+
declare function mergeCustomHtmlTags(...lists: Array<readonly string[] | undefined>): string[];
|
|
512
|
+
declare function resolveCustomHtmlTags(tags?: readonly string[]): {
|
|
513
|
+
key: string;
|
|
514
|
+
tags: string[];
|
|
515
|
+
};
|
|
516
|
+
declare function getHtmlTagFromContent(html: unknown): string;
|
|
517
|
+
declare function hasCompleteHtmlTagContent(html: unknown, tag: string): boolean;
|
|
518
|
+
declare function shouldRenderUnknownHtmlTagAsText(html: unknown, tag: string): boolean;
|
|
519
|
+
declare function stripCustomHtmlWrapper(html: unknown, tag: string): string;
|
|
520
|
+
//#endregion
|
|
521
|
+
//#region src/findMatchingClose.d.ts
|
|
522
|
+
declare function findMatchingClose(src: string, startIdx: number, open: string, close: string): number;
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/htmlRenderUtils.d.ts
|
|
525
|
+
type HtmlPolicy = 'escape' | 'safe' | 'trusted';
|
|
526
|
+
type HtmlPropValue = string | number | boolean;
|
|
527
|
+
interface HtmlToken {
|
|
528
|
+
type: 'text' | 'tag_open' | 'tag_close' | 'self_closing';
|
|
529
|
+
tagName?: string;
|
|
530
|
+
attrs?: Record<string, string>;
|
|
531
|
+
content?: string;
|
|
532
|
+
}
|
|
533
|
+
declare const SAFE_ALLOWED_HTML_TAGS: Set<string>;
|
|
534
|
+
declare function isHtmlTagBlocked(tagName: string | undefined, policy?: HtmlPolicy): boolean;
|
|
535
|
+
declare function isHtmlTagHardBlocked(tagName: string | undefined, policy?: HtmlPolicy): boolean;
|
|
536
|
+
declare function isCustomHtmlComponentTag(tagName: string, customComponents: Record<string, unknown>): any;
|
|
537
|
+
declare function sanitizeHtmlAttrs(attrs: Record<string, string>, policy?: HtmlPolicy, tagName?: string): Record<string, string>;
|
|
538
|
+
declare function tokenAttrsToRecord(attrs?: Array<[string, string | null]> | null): Record<string, string>;
|
|
539
|
+
declare function sanitizeHtmlTokenAttrs(attrs?: Array<[string, string | null]> | null, policy?: HtmlPolicy, tagName?: string): [string, string][];
|
|
540
|
+
declare function convertHtmlPropValue(value: string, key: string): HtmlPropValue;
|
|
541
|
+
declare function convertHtmlAttrsToProps(attrs: Record<string, string>): Record<string, HtmlPropValue>;
|
|
542
|
+
declare function tokenizeHtml(html: string): HtmlToken[];
|
|
543
|
+
declare function hasCustomHtmlComponents(content: string, customComponents: Record<string, unknown>): boolean;
|
|
544
|
+
declare function sanitizeHtmlContent(content: string, policy?: HtmlPolicy): string;
|
|
545
|
+
//#endregion
|
|
546
|
+
//#region src/htmlTags.d.ts
|
|
547
|
+
declare const VOID_HTML_TAG_NAMES: readonly ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"];
|
|
548
|
+
declare const INLINE_HTML_TAG_NAMES: readonly ["a", "abbr", "b", "bdi", "bdo", "button", "cite", "code", "data", "del", "dfn", "em", "font", "i", "ins", "kbd", "label", "mark", "q", "s", "samp", "small", "span", "strong", "sub", "sup", "time", "u", "var"];
|
|
549
|
+
declare const BLOCK_HTML_TAG_NAMES: readonly ["article", "aside", "blockquote", "details", "div", "figcaption", "figure", "footer", "header", "h1", "h2", "h3", "h4", "h5", "h6", "li", "main", "nav", "ol", "p", "pre", "section", "summary", "table", "tbody", "td", "th", "thead", "tr", "ul"];
|
|
550
|
+
declare const SVG_HTML_TAG_NAMES: readonly ["svg", "g", "path"];
|
|
551
|
+
declare const EXTENDED_STANDARD_HTML_TAG_NAMES: readonly ["address", "audio", "body", "canvas", "caption", "colgroup", "datalist", "dd", "dialog", "dl", "dt", "fieldset", "form", "head", "hgroup", "html", "iframe", "legend", "map", "menu", "meter", "noscript", "object", "optgroup", "option", "output", "picture", "progress", "rp", "rt", "ruby", "script", "select", "style", "template", "textarea", "tfoot", "title", "video"];
|
|
552
|
+
declare const DANGEROUS_HTML_ATTR_NAMES: readonly ["onclick", "onerror", "onload", "onmouseover", "onmouseout", "onmousedown", "onmouseup", "onkeydown", "onkeyup", "onfocus", "onblur", "onsubmit", "onreset", "onchange", "onselect", "ondblclick", "ontouchstart", "ontouchend", "ontouchmove", "ontouchcancel", "onwheel", "onscroll", "oncopy", "oncut", "onpaste", "oninput", "oninvalid", "onsearch", "srcdoc", "ping"];
|
|
553
|
+
declare const URL_HTML_ATTR_NAMES: readonly ["action", "data", "href", "src", "srcset", "poster", "xlink:href", "formaction"];
|
|
554
|
+
declare const BLOCKED_HTML_TAG_NAMES: readonly ["script"];
|
|
555
|
+
declare const NON_STRUCTURING_HTML_TAG_NAMES: readonly ["pre", "script", "style", "table", "tbody", "td", "tfoot", "th", "thead", "textarea", "tr", "title"];
|
|
556
|
+
declare const VOID_HTML_TAGS: Set<string>;
|
|
557
|
+
declare const STANDARD_BLOCK_HTML_TAGS: Set<string>;
|
|
558
|
+
declare const STANDARD_HTML_TAGS: Set<string>;
|
|
559
|
+
declare const EXTENDED_STANDARD_HTML_TAGS: Set<string>;
|
|
560
|
+
declare const DANGEROUS_HTML_ATTRS: Set<string>;
|
|
561
|
+
declare const URL_HTML_ATTRS: Set<string>;
|
|
562
|
+
declare const BLOCKED_HTML_TAGS: Set<string>;
|
|
563
|
+
declare const NON_STRUCTURING_HTML_TAGS: Set<string>;
|
|
564
|
+
declare function stripHtmlControlAndWhitespace(value: string): string;
|
|
565
|
+
interface HtmlUrlContext {
|
|
566
|
+
tagName?: string;
|
|
567
|
+
attrName?: string;
|
|
568
|
+
}
|
|
569
|
+
declare function isUnsafeHtmlUrl(value: string, context?: HtmlUrlContext): boolean;
|
|
570
|
+
declare function shouldOpenLinkInNewTab(href: string | null | undefined): boolean;
|
|
571
|
+
declare function sanitizeImageSrc(value: unknown): string;
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/mermaidSvgSanitizer.d.ts
|
|
574
|
+
/**
|
|
575
|
+
* Sanitizes Mermaid SVG with DOMParser and returns a detached SVG element.
|
|
576
|
+
* Returns null in non-DOM runtimes such as plain Node.js.
|
|
577
|
+
*/
|
|
578
|
+
declare function toSafeSvgElement<TElement = unknown>(svg: string | null | undefined): TElement | null;
|
|
579
|
+
/**
|
|
580
|
+
* Sanitizes Mermaid SVG with DOMParser.
|
|
581
|
+
* Returns null in non-DOM runtimes such as plain Node.js.
|
|
582
|
+
*/
|
|
583
|
+
declare function sanitizeMermaidSvg(svg: string | null | undefined): string | null;
|
|
584
|
+
/**
|
|
585
|
+
* Sanitizes Mermaid SVG with DOMParser.
|
|
586
|
+
* Returns an empty string in non-DOM runtimes such as plain Node.js.
|
|
587
|
+
*/
|
|
588
|
+
declare function toSafeMermaidSvgMarkup(svg: string | null | undefined): string;
|
|
589
|
+
declare function isBrokenMermaidSvg(svg: string | null | undefined): boolean;
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/parser/inline-parsers/fence-parser.d.ts
|
|
592
|
+
declare function parseFenceToken(token: MarkdownToken): CodeBlockNode;
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/plugins/containers.d.ts
|
|
595
|
+
declare function applyContainers(md: MarkdownIt): void;
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region src/plugins/isMathLike.d.ts
|
|
598
|
+
declare const TEX_BRACE_COMMANDS: string[];
|
|
599
|
+
declare const ESCAPED_TEX_BRACE_COMMANDS: string;
|
|
600
|
+
declare function isMathLike(s: string): boolean;
|
|
601
|
+
//#endregion
|
|
602
|
+
//#region src/plugins/math.d.ts
|
|
603
|
+
declare const KATEX_COMMANDS: string[];
|
|
604
|
+
declare function normalizeStandaloneBackslashT(s: string, opts?: MathOptions): string;
|
|
605
|
+
declare function applyMath(md: MarkdownIt, mathOpts?: MathOptions): void;
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/index.d.ts
|
|
608
|
+
type MarkdownPluginRegistration<TParams extends unknown[] = any[]> = CompatibleMarkdownItPlugin<TParams> | readonly [CompatibleMarkdownItPlugin<TParams>, ...TParams];
|
|
609
|
+
declare function registerMarkdownPlugin(plugin: MarkdownPluginRegistration): void;
|
|
610
|
+
declare function clearRegisteredMarkdownPlugins(): void;
|
|
611
|
+
interface GetMarkdownOptions extends FactoryOptions {
|
|
612
|
+
plugin?: MarkdownPluginRegistration[];
|
|
613
|
+
apply?: Array<(md: MarkdownIt) => void>;
|
|
614
|
+
/**
|
|
615
|
+
* Custom translation function or translation map for UI texts
|
|
616
|
+
* @default { 'common.copy': 'Copy' }
|
|
617
|
+
*/
|
|
618
|
+
i18n?: ((key: string) => string) | Record<string, string>;
|
|
619
|
+
}
|
|
620
|
+
declare function getMarkdown(msgId?: string, options?: GetMarkdownOptions): MarkdownIt;
|
|
621
|
+
//#endregion
|
|
622
|
+
export { AdmonitionNode, BLOCKED_HTML_TAGS, BLOCKED_HTML_TAG_NAMES, BLOCK_HTML_TAG_NAMES, BaseNode, BlockquoteNode, CheckboxInputNode, CheckboxNode, CodeBlockNode, CustomComponentAttrs, CustomComponentNode, CustomComponents, DANGEROUS_HTML_ATTRS, DANGEROUS_HTML_ATTR_NAMES, DefinitionItemNode, DefinitionListNode, ESCAPED_TEX_BRACE_COMMANDS, EXTENDED_STANDARD_HTML_TAGS, EXTENDED_STANDARD_HTML_TAG_NAMES, EmojiNode, EmphasisNode, FootnoteAnchorNode, FootnoteNode, FootnoteReferenceNode, GetMarkdownOptions, HardBreakNode, HeadingNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, HtmlPolicy, HtmlPropValue, HtmlToken, INLINE_HTML_TAG_NAMES, ImageNode, InlineCodeNode, InlineNode, InsertNode, InternalParseOptions, KATEX_COMMANDS, LinkNode, ListItemNode, ListNode, type MarkdownIt, MarkdownPluginRegistration, MarkdownRender, MarkdownToken, MarkdownTokenLite, MarkdownTokenMeta, MathBlockNode, MathInlineNode, type MathOptions, MermaidBlockNode, NON_STRUCTURING_HTML_TAGS, NON_STRUCTURING_HTML_TAG_NAMES, ParagraphNode, ParseOptions, ParsedNode, PostTransformNodesHook, ReferenceNode, SAFE_ALLOWED_HTML_TAGS, STANDARD_BLOCK_HTML_TAGS, STANDARD_HTML_TAGS, SVG_HTML_TAG_NAMES, StrikethroughNode, StrongNode, SubscriptNode, SuperscriptNode, TEX_BRACE_COMMANDS, TableCellNode, TableNode, TableRowNode, TextNode, ThematicBreakNode, TransformTokensHook, URL_HTML_ATTRS, URL_HTML_ATTR_NAMES, UnknownNode, VOID_HTML_TAGS, VOID_HTML_TAG_NAMES, VmrContainerNode, applyContainers, applyMath, clearRegisteredMarkdownPlugins, convertHtmlAttrsToProps, convertHtmlPropValue, findMatchingClose, getHtmlTagFromContent, getMarkdown, hasCompleteHtmlTagContent, hasCustomHtmlComponents, isBrokenMermaidSvg, isCustomHtmlComponentTag, isHtmlLikeTagName, isHtmlTagBlocked, isHtmlTagHardBlocked, isMathLike, isUnsafeHtmlUrl, mergeCustomHtmlTags, normalizeCustomHtmlTagName, normalizeCustomHtmlTags, normalizeStandaloneBackslashT, parseFenceToken, parseInlineTokens, parseMarkdownToStructure, processTokens, registerMarkdownPlugin, resolveCustomHtmlTags, sanitizeHtmlAttrs, sanitizeHtmlContent, sanitizeHtmlTokenAttrs, sanitizeImageSrc, sanitizeMermaidSvg, setDefaultMathOptions, shouldOpenLinkInNewTab, shouldRenderUnknownHtmlTagAsText, stripCustomHtmlWrapper, stripHtmlControlAndWhitespace, toSafeMermaidSvgMarkup, toSafeSvgElement, tokenAttrsToRecord, tokenizeHtml };
|
|
623
|
+
//# sourceMappingURL=index.d.cts.map
|