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