markdown-to-jsx 9.7.11 → 9.7.13

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/vue.d.cts ADDED
@@ -0,0 +1,597 @@
1
+ import { h, VNode, Component, InjectionKey } from "vue";
2
+ import * as React from "react";
3
+ /**
4
+ * Analogous to `node.type`. Please note that the values here may change at any time,
5
+ * so do not hard code against the value directly.
6
+ */
7
+ declare const RuleTypeConst: {
8
+ readonly blockQuote: 0;
9
+ readonly breakLine: 1;
10
+ readonly breakThematic: 2;
11
+ readonly codeBlock: 3;
12
+ readonly codeInline: 4;
13
+ readonly footnote: 5;
14
+ readonly footnoteReference: 6;
15
+ readonly frontmatter: 7;
16
+ readonly gfmTask: 8;
17
+ readonly heading: 9;
18
+ readonly htmlBlock: 10;
19
+ readonly htmlComment: 11;
20
+ readonly htmlSelfClosing: 12;
21
+ readonly image: 13;
22
+ readonly link: 14;
23
+ readonly orderedList: 15;
24
+ readonly paragraph: 16;
25
+ readonly ref: 17;
26
+ readonly refCollection: 18;
27
+ readonly table: 19;
28
+ readonly text: 20;
29
+ readonly textFormatted: 21;
30
+ readonly unorderedList: 22;
31
+ };
32
+ type RuleTypeValue = (typeof RuleTypeConst)[keyof typeof RuleTypeConst];
33
+ /**
34
+ * markdown-to-jsx types and interfaces
35
+ */
36
+ declare namespace MarkdownToJSX {
37
+ /**
38
+ * RequireAtLeastOne<{ ... }> <- only requires at least one key
39
+ */
40
+ type RequireAtLeastOne<
41
+ T,
42
+ Keys extends keyof T = keyof T
43
+ > = Pick<T, Exclude<keyof T, Keys>> & { [K in Keys]-? : Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>> }[Keys];
44
+ /**
45
+ * React.createElement function type
46
+ */
47
+ export type CreateElement = typeof React.createElement;
48
+ /**
49
+ * HTML tag names that can be used in JSX
50
+ */
51
+ export type HTMLTags = keyof React.JSX.IntrinsicElements & (string & {});
52
+ /**
53
+ * Parser and renderer state
54
+ */
55
+ export type State = {
56
+ /** true if the current content is inside anchor link grammar */
57
+ inAnchor?: boolean;
58
+ /** true if inside a blockquote */
59
+ inBlockQuote?: boolean;
60
+ /** true if parsing in an HTML context */
61
+ inHTML?: boolean;
62
+ /** true if in a list */
63
+ inList?: boolean;
64
+ /** true if parsing in an inline context (subset of rules around formatting and links) */
65
+ inline?: boolean;
66
+ /** use this for the `key` prop */
67
+ key?: string | number;
68
+ /** reference definitions (footnotes are stored with '^' prefix) */
69
+ refs?: {
70
+ [key: string]: {
71
+ target: string;
72
+ title: string;
73
+ };
74
+ };
75
+ /** current recursion depth during rendering */
76
+ renderDepth?: number;
77
+ /** internal: block parse recursion depth */
78
+ _depth?: number;
79
+ /** internal: disable setext heading detection (lazy blockquote continuation) */
80
+ _noSetext?: boolean;
81
+ /** internal: HTML nesting depth for stack overflow protection */
82
+ _htmlDepth?: number;
83
+ /** internal: set by collectReferenceDefinitions when input ends inside an unclosed fence */
84
+ _endsInsideFence?: boolean;
85
+ };
86
+ /**
87
+ * Blockquote node in the AST
88
+ */
89
+ export interface BlockQuoteNode {
90
+ /** Optional alert type (Note, Tip, Warning, etc.) */
91
+ alert?: string;
92
+ /** Child nodes within the blockquote */
93
+ children: MarkdownToJSX.ASTNode[];
94
+ type: typeof RuleType2.blockQuote;
95
+ }
96
+ /**
97
+ * Hard line break node
98
+ */
99
+ export interface BreakLineNode {
100
+ type: typeof RuleType2.breakLine;
101
+ }
102
+ /**
103
+ * Thematic break (horizontal rule) node
104
+ */
105
+ export interface BreakThematicNode {
106
+ type: typeof RuleType2.breakThematic;
107
+ }
108
+ /**
109
+ * Code block node (fenced code blocks)
110
+ */
111
+ export interface CodeBlockNode {
112
+ type: typeof RuleType2.codeBlock;
113
+ /** HTML attributes for the code block */
114
+ attrs?: React.JSX.IntrinsicAttributes;
115
+ /** Programming language identifier */
116
+ lang?: string;
117
+ /** Code content */
118
+ text: string;
119
+ }
120
+ /**
121
+ * Inline code node
122
+ */
123
+ export interface CodeInlineNode {
124
+ type: typeof RuleType2.codeInline;
125
+ /** Code text */
126
+ text: string;
127
+ }
128
+ /**
129
+ * Footnote definition node (not rendered, stored in refCollection)
130
+ */
131
+ export interface FootnoteNode {
132
+ type: typeof RuleType2.footnote;
133
+ }
134
+ /**
135
+ * Footnote reference node
136
+ */
137
+ export interface FootnoteReferenceNode {
138
+ type: typeof RuleType2.footnoteReference;
139
+ /** Link target (anchor) */
140
+ target: string;
141
+ /** Display text */
142
+ text: string;
143
+ }
144
+ /**
145
+ * YAML frontmatter node
146
+ */
147
+ export interface FrontmatterNode {
148
+ type: typeof RuleType2.frontmatter;
149
+ /** Frontmatter content */
150
+ text: string;
151
+ }
152
+ /**
153
+ * GFM task list item node
154
+ */
155
+ export interface GFMTaskNode {
156
+ type: typeof RuleType2.gfmTask;
157
+ /** Whether the task is completed */
158
+ completed: boolean;
159
+ }
160
+ /**
161
+ * Heading node
162
+ */
163
+ export interface HeadingNode {
164
+ type: typeof RuleType2.heading;
165
+ /** Child nodes (text content) */
166
+ children: MarkdownToJSX.ASTNode[];
167
+ /** Generated HTML ID for anchor linking */
168
+ id: string;
169
+ /** Heading level (1-6) */
170
+ level: 1 | 2 | 3 | 4 | 5 | 6;
171
+ }
172
+ /**
173
+ * HTML comment node
174
+ */
175
+ export interface HTMLCommentNode {
176
+ type: typeof RuleType2.htmlComment;
177
+ /** Comment text */
178
+ text: string;
179
+ }
180
+ /**
181
+ * Image node
182
+ */
183
+ export interface ImageNode {
184
+ type: typeof RuleType2.image;
185
+ /** Alt text */
186
+ alt?: string;
187
+ /** Image URL */
188
+ target: string;
189
+ /** Title attribute */
190
+ title?: string;
191
+ }
192
+ /**
193
+ * Link node
194
+ */
195
+ export interface LinkNode {
196
+ type: typeof RuleType2.link;
197
+ /** Child nodes (link text) */
198
+ children: MarkdownToJSX.ASTNode[];
199
+ /** Link URL (null for reference links without definition) */
200
+ target: string | null;
201
+ /** Title attribute */
202
+ title?: string;
203
+ }
204
+ /**
205
+ * Ordered list node
206
+ */
207
+ export interface OrderedListNode {
208
+ type: typeof RuleType2.orderedList;
209
+ /** Array of list items, each item is an array of nodes */
210
+ items: MarkdownToJSX.ASTNode[][];
211
+ /** Starting number for the list */
212
+ start?: number;
213
+ }
214
+ /**
215
+ * Unordered list node
216
+ */
217
+ export interface UnorderedListNode {
218
+ type: typeof RuleType2.unorderedList;
219
+ /** Array of list items, each item is an array of nodes */
220
+ items: MarkdownToJSX.ASTNode[][];
221
+ }
222
+ /**
223
+ * Paragraph node
224
+ */
225
+ export interface ParagraphNode {
226
+ type: typeof RuleType2.paragraph;
227
+ /** Child nodes */
228
+ children: MarkdownToJSX.ASTNode[];
229
+ }
230
+ /**
231
+ * Reference definition node (not rendered, stored in refCollection)
232
+ */
233
+ export interface ReferenceNode {
234
+ type: typeof RuleType2.ref;
235
+ }
236
+ /**
237
+ * Reference collection node (appears at AST root, includes footnotes with '^' prefix)
238
+ */
239
+ export interface ReferenceCollectionNode {
240
+ type: typeof RuleType2.refCollection;
241
+ /** Map of reference labels to their definitions */
242
+ refs: {
243
+ [key: string]: {
244
+ target: string;
245
+ title: string;
246
+ };
247
+ };
248
+ }
249
+ /**
250
+ * Table node
251
+ */
252
+ export interface TableNode {
253
+ type: typeof RuleType2.table;
254
+ /**
255
+ * alignment for each table column
256
+ */
257
+ align: ("left" | "right" | "center")[];
258
+ /** Table cells (3D array: rows -> cells -> nodes) */
259
+ cells: MarkdownToJSX.ASTNode[][][];
260
+ /** Table header row */
261
+ header: MarkdownToJSX.ASTNode[][];
262
+ }
263
+ /**
264
+ * Plain text node
265
+ */
266
+ export interface TextNode {
267
+ type: typeof RuleType2.text;
268
+ /** Text content */
269
+ text: string;
270
+ }
271
+ /**
272
+ * Formatted text node (bold, italic, etc.)
273
+ */
274
+ export interface FormattedTextNode {
275
+ type: typeof RuleType2.textFormatted;
276
+ /**
277
+ * the corresponding html tag
278
+ */
279
+ tag: string;
280
+ /** Child nodes */
281
+ children: MarkdownToJSX.ASTNode[];
282
+ }
283
+ /** @deprecated Use `FormattedTextNode` instead. */
284
+ export type TextFormattedNode = FormattedTextNode;
285
+ /**
286
+ * HTML block node (includes JSX components)
287
+ */
288
+ export interface HTMLNode {
289
+ type: typeof RuleType2.htmlBlock;
290
+ /** Parsed HTML attributes */
291
+ attrs?: Record<string, any>;
292
+ /** Parsed child nodes (always parsed, even for verbatim blocks) */
293
+ children?: ASTNode[] | undefined;
294
+ /** @internal Whether this is a closing tag */
295
+ _isClosingTag?: boolean;
296
+ /** @internal Whether this is a verbatim block (script, style, pre, etc.) */
297
+ _verbatim?: boolean;
298
+ /** @internal Original raw attribute string */
299
+ _rawAttrs?: string;
300
+ /** @internal Original raw HTML content (for verbatim blocks) */
301
+ _rawText?: string | undefined;
302
+ /** @deprecated Use `_rawText` instead. This property will be removed in a future major version. */
303
+ text?: string | undefined;
304
+ /** HTML tag name */
305
+ tag: string;
306
+ }
307
+ /**
308
+ * Self-closing HTML tag node
309
+ */
310
+ export interface HTMLSelfClosingNode {
311
+ type: typeof RuleType2.htmlSelfClosing;
312
+ /** Parsed HTML attributes */
313
+ attrs?: Record<string, any>;
314
+ /** @internal Whether this is a closing tag */
315
+ _isClosingTag?: boolean;
316
+ /** HTML tag name */
317
+ tag: string;
318
+ /** @internal Original raw HTML content */
319
+ _rawText?: string;
320
+ }
321
+ /**
322
+ * Union type of all possible AST node types
323
+ */
324
+ export type ASTNode = BlockQuoteNode | BreakLineNode | BreakThematicNode | CodeBlockNode | CodeInlineNode | FootnoteNode | FootnoteReferenceNode | FrontmatterNode | GFMTaskNode | HeadingNode | HTMLCommentNode | ImageNode | LinkNode | OrderedListNode | UnorderedListNode | ParagraphNode | ReferenceNode | ReferenceCollectionNode | TableNode | TextNode | FormattedTextNode | HTMLNode | HTMLSelfClosingNode;
325
+ /**
326
+ * Function type for rendering AST nodes
327
+ */
328
+ export type ASTRender = (ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], state: MarkdownToJSX.State) => React.ReactNode;
329
+ /**
330
+ * Override configuration for HTML tags or custom components
331
+ */
332
+ export type Override = RequireAtLeastOne<{
333
+ component: React.ElementType;
334
+ props: Object;
335
+ }> | React.ElementType;
336
+ /**
337
+ * Map of HTML tags and custom components to their override configurations
338
+ */
339
+ export type Overrides = { [tag in HTMLTags]? : Override } & {
340
+ [customComponent: string]: Override;
341
+ };
342
+ /**
343
+ * Compiler options
344
+ */
345
+ export type Options = Partial<{
346
+ /**
347
+ * Ultimate control over the output of all rendered JSX.
348
+ */
349
+ createElement: (tag: Parameters<CreateElement>[0], props: React.JSX.IntrinsicAttributes, ...children: React.ReactNode[]) => React.ReactNode;
350
+ /**
351
+ * The library automatically generates an anchor tag for bare URLs included in the markdown
352
+ * document, but this behavior can be disabled if desired.
353
+ */
354
+ disableAutoLink: boolean;
355
+ /**
356
+ * Disable the compiler's best-effort transcription of provided raw HTML
357
+ * into JSX-equivalent. This is the functionality that prevents the need to
358
+ * use `dangerouslySetInnerHTML` in React.
359
+ */
360
+ disableParsingRawHTML: boolean;
361
+ /**
362
+ * Disable the compiler's parsing of HTML blocks.
363
+ */
364
+ ignoreHTMLBlocks?: boolean;
365
+ /**
366
+ * Enable GFM tagfilter extension to filter potentially dangerous HTML tags.
367
+ * When enabled, the following tags are escaped: title, textarea, style, xmp,
368
+ * iframe, noembed, noframes, script, plaintext.
369
+ * https://github.github.com/gfm/#disallowed-raw-html-extension-
370
+ * @default true
371
+ */
372
+ tagfilter?: boolean;
373
+ /**
374
+ * Forces the compiler to have space between hash sign and the header text which
375
+ * is explicitly stated in the most of the markdown specs.
376
+ * https://github.github.com/gfm/#atx-heading
377
+ * `The opening sequence of # characters must be followed by a space or by the end of line.`
378
+ */
379
+ enforceAtxHeadings: boolean;
380
+ /**
381
+ * **⚠️ SECURITY WARNING: STRONGLY DISCOURAGED FOR USER INPUTS**
382
+ *
383
+ * When enabled, attempts to eval expressions in JSX props that cannot be serialized
384
+ * as JSON (functions, variables, complex expressions). This uses `eval()` which can
385
+ * execute arbitrary code.
386
+ *
387
+ * **ONLY use this option when:**
388
+ * - The markdown source is completely trusted (e.g., your own documentation)
389
+ * - You control all JSX components and their props
390
+ * - The content is NOT user-generated or user-editable
391
+ *
392
+ * **DO NOT use this option when:**
393
+ * - Processing user-submitted markdown
394
+ * - Rendering untrusted content
395
+ * - Building public-facing applications with user content
396
+ *
397
+ * Example unsafe input: `<Component onClick={() => fetch('/admin/delete-all')} />`
398
+ *
399
+ * When disabled (default), unserializable expressions remain as strings that can be
400
+ * safely inspected or handled on a case-by-case basis via custom renderRule logic.
401
+ *
402
+ * @default false
403
+ */
404
+ evalUnserializableExpressions?: boolean;
405
+ /**
406
+ * Forces the compiler to always output content with a block-level wrapper
407
+ * (`<p>` or any block-level syntax your markdown already contains.)
408
+ */
409
+ forceBlock: boolean;
410
+ /**
411
+ * Forces the compiler to always output content with an inline wrapper (`<span>`)
412
+ */
413
+ forceInline: boolean;
414
+ /**
415
+ * Forces the compiler to wrap results, even if there is only a single
416
+ * child or no children.
417
+ */
418
+ forceWrapper: boolean;
419
+ /**
420
+ * Selectively control the output of particular HTML tags as they would be
421
+ * emitted by the compiler.
422
+ */
423
+ overrides: Overrides;
424
+ /**
425
+ * Allows for full control over rendering of particular rules.
426
+ * For example, to implement a LaTeX renderer such as `react-katex`:
427
+ *
428
+ * ```
429
+ * renderRule(next, node, renderChildren, state) {
430
+ * if (node.type === RuleType.codeBlock && node.lang === 'latex') {
431
+ * return (
432
+ * <TeX as="div" key={state.key}>
433
+ * {String.raw`${node.text}`}
434
+ * </TeX>
435
+ * )
436
+ * }
437
+ *
438
+ * return next();
439
+ * }
440
+ * ```
441
+ *
442
+ * Thar be dragons obviously, but you can do a lot with this
443
+ * (have fun!) To see how things work internally, check the `render`
444
+ * method in source for a particular rule.
445
+ */
446
+ renderRule: (next: () => React.ReactNode, node: ASTNode, renderChildren: ASTRender, state: State) => React.ReactNode;
447
+ /**
448
+ * Override the built-in sanitizer function for URLs, etc if desired. The built-in version is available as a library
449
+ export called `sanitizer`.
450
+ */
451
+ sanitizer: (value: string, tag: string, attribute: string) => string | null;
452
+ /**
453
+ * Override normalization of non-URI-safe characters for use in generating
454
+ * HTML IDs for anchor linking purposes.
455
+ */
456
+ slugify: (input: string, defaultFn: (input: string) => string) => string;
457
+ /**
458
+ * Declare the type of the wrapper to be used when there are multiple
459
+ * children to render. Set to `null` to get an array of children back
460
+ * without any wrapper, or use `React.Fragment` to get a React element
461
+ * that won't show up in the DOM.
462
+ */
463
+ wrapper: React.ElementType | null;
464
+ /**
465
+ * Props to apply to the wrapper element.
466
+ */
467
+ wrapperProps?: React.JSX.IntrinsicAttributes;
468
+ /**
469
+ * Preserve frontmatter in the output by rendering it as a <pre> element.
470
+ * By default, frontmatter is parsed but not rendered.
471
+ * @default false
472
+ */
473
+ preserveFrontmatter?: boolean;
474
+ /**
475
+ * Optimize rendering for streaming scenarios where markdown content arrives
476
+ * incrementally (e.g., from LLM APIs). When enabled, incomplete inline syntax
477
+ * is suppressed to avoid displaying raw markdown characters while waiting
478
+ * for the closing delimiter to arrive.
479
+ *
480
+ * Fenced code blocks render normally with content visible as it streams.
481
+ *
482
+ * @default false
483
+ *
484
+ * @example
485
+ * ```tsx
486
+ * // Streaming markdown example
487
+ * function StreamingMarkdown({ content }) {
488
+ * return (
489
+ * <Markdown options={{ optimizeForStreaming: true }}>
490
+ * {content}
491
+ * </Markdown>
492
+ * )
493
+ * }
494
+ * ```
495
+ */
496
+ optimizeForStreaming?: boolean;
497
+ }>;
498
+ }
499
+ declare const RuleType2: typeof RuleTypeConst;
500
+ type RuleType2 = RuleTypeValue;
501
+ type RequireAtLeastOne<
502
+ T,
503
+ Keys extends keyof T = keyof T
504
+ > = MarkdownToJSX.RequireAtLeastOne<T, Keys>;
505
+ /**
506
+ * Main parser entry point - matches original parser interface
507
+ */
508
+ declare function parser(source: string, options?: MarkdownToJSX.Options): MarkdownToJSX.ASTNode[];
509
+ /**
510
+ * Sanitize URLs and other input values to prevent XSS attacks.
511
+ * Filters out javascript:, vbscript:, and data: URLs (except data:image).
512
+ *
513
+ *
514
+ * @param input - The URL or value to sanitize
515
+ * @returns Sanitized value, or null if unsafe
516
+ */
517
+ declare function sanitizer(input: string): string | null;
518
+ /**
519
+ * Convert a string to a URL-safe slug by normalizing characters and replacing spaces with hyphens.
520
+ * Based on https://stackoverflow.com/a/18123682/1141611
521
+ * Not complete, but probably good enough.
522
+ *
523
+ *
524
+ * @param str - String to slugify
525
+ * @returns URL-safe slug
526
+ */
527
+ declare function slugify(str: string): string;
528
+ /**
529
+ * Vue injection key for sharing compiler options across Markdown components
530
+ */
531
+ declare const MarkdownOptionsKey: InjectionKey<VueOptions | undefined>;
532
+ type VueChild = VNode | string;
533
+ /**
534
+ * Override configuration for HTML tags or custom components in Vue output
535
+ */
536
+ type VueOverride = RequireAtLeastOne<{
537
+ component: string | Component;
538
+ props: Record<string, unknown>;
539
+ }> | string | Component;
540
+ /**
541
+ * Map of HTML tags and custom components to their override configurations
542
+ */
543
+ type VueOverrides = {
544
+ [tag: string]: VueOverride;
545
+ };
546
+ /**
547
+ * Vue compiler options
548
+ */
549
+ type VueOptions = Omit<MarkdownToJSX.Options, "createElement" | "wrapperProps" | "renderRule" | "overrides"> & {
550
+ /** Custom createElement function (Vue's h function) */
551
+ createElement?: typeof h;
552
+ /** Props for wrapper element */
553
+ wrapperProps?: Record<string, unknown>;
554
+ /** Custom rendering function for AST rules */
555
+ renderRule?: (next: () => VueChild | null, node: MarkdownToJSX.ASTNode, renderChildren: (children: MarkdownToJSX.ASTNode[]) => VueChild[] | VNode, state: MarkdownToJSX.State) => VueChild | null;
556
+ /** Override configurations for HTML tags */
557
+ overrides?: VueOverrides;
558
+ };
559
+ /**
560
+ * Convert AST nodes to Vue VNode elements
561
+ *
562
+ * @param ast - Array of AST nodes to render
563
+ * @param options - Vue compiler options
564
+ * @returns Vue VNode element(s)
565
+ */
566
+ declare function astToJSX(ast: MarkdownToJSX.ASTNode[], options?: VueOptions): VNode | VNode[] | null;
567
+ /**
568
+ * Compile markdown string to Vue VNode elements
569
+ *
570
+ * @param markdown - Markdown string to compile
571
+ * @param options - Vue compiler options
572
+ * @returns Vue VNode element(s)
573
+ */
574
+ declare function compiler(markdown?: string, options?: VueOptions): VNode | VNode[] | null;
575
+ /**
576
+ * Vue context provider for sharing compiler options across Markdown components
577
+ *
578
+ * @param options - Default compiler options to share
579
+ * @param children - Vue children
580
+ */
581
+ declare const MarkdownProvider: Component<{
582
+ options?: VueOptions;
583
+ children?: unknown;
584
+ }>;
585
+ /**
586
+ * A Vue component for easy markdown rendering. Feed the markdown content as a direct child
587
+ * and the rest is taken care of automatically. Supports computed memoization for optimal performance.
588
+ *
589
+ * @param children - Markdown string content
590
+ * @param options - Compiler options
591
+ */
592
+ declare const Markdown: Component<{
593
+ children?: string | null;
594
+ options?: VueOptions;
595
+ [key: string]: unknown;
596
+ }>;
597
+ export { slugify, sanitizer, parser, Markdown as default, compiler, astToJSX, VueOverrides, VueOverride, VueOptions, RuleType2 as RuleType, MarkdownToJSX, MarkdownProvider, MarkdownOptionsKey, Markdown };