markdown-to-jsx 8.0.0 → 9.0.0

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 CHANGED
@@ -1,412 +1,342 @@
1
+ import * as React2 from "react";
2
+ import * as React from "react";
1
3
  /**
2
- * markdown-to-jsx is a fork of
3
- * [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown)
4
- * from Khan Academy. Thank you Khan devs for making such an awesome
5
- * and extensible parsing infra... without it, half of the
6
- * optimizations here wouldn't be feasible. 🙏🏼
7
- */
8
- import * as React from 'react';
9
- import { type RuleType as RuleTypeValue } from './match';
10
- export declare const RuleType: {
11
- readonly blockQuote: "0";
12
- readonly breakLine: "1";
13
- readonly breakThematic: "2";
14
- readonly codeBlock: "3";
15
- readonly codeFenced: "4";
16
- readonly codeInline: "5";
17
- readonly footnote: "6";
18
- readonly footnoteReference: "7";
19
- readonly gfmTask: "8";
20
- readonly heading: "9";
21
- readonly headingSetext: "10";
22
- readonly htmlBlock: "11";
23
- readonly htmlComment: "12";
24
- readonly htmlSelfClosing: "13";
25
- readonly image: "14";
26
- readonly link: "15";
27
- readonly linkAngleBraceStyleDetector: "16";
28
- readonly linkBareUrlDetector: "17";
29
- readonly linkMailtoDetector: "18";
30
- readonly newlineCoalescer: "19";
31
- readonly orderedList: "20";
32
- readonly paragraph: "21";
33
- readonly ref: "22";
34
- readonly refImage: "23";
35
- readonly refLink: "24";
36
- readonly table: "25";
37
- readonly tableSeparator: "26";
38
- readonly text: "27";
39
- readonly textEscaped: "28";
40
- readonly textFormatted: "34";
41
- readonly unorderedList: "30";
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;
42
31
  };
43
- export type RuleType = RuleTypeValue;
44
- declare const Priority: {
45
- /**
46
- * anything that must scan the tree before everything else
47
- */
48
- MAX: number;
49
- /**
50
- * scans for block-level constructs
51
- */
52
- HIGH: number;
53
- /**
54
- * inline w/ more priority than other inline
55
- */
56
- MED: number;
57
- /**
58
- * inline elements
59
- */
60
- LOW: number;
61
- /**
62
- * bare text and stuff that is considered leftovers
63
- */
64
- MIN: number;
65
- };
66
- export declare function slugify(str: string): string;
67
- export declare function sanitizer(input: string): string;
68
- export declare function compiler(markdown: string, options: MarkdownToJSX.Options & {
69
- wrapper: null;
70
- }): React.ReactNode[];
71
- export declare function compiler(markdown: string, options?: MarkdownToJSX.Options): React.JSX.Element;
32
+ type RuleTypeValue = (typeof RuleTypeConst)[keyof typeof RuleTypeConst];
72
33
  /**
73
- * A simple HOC for easy React use. Feed the markdown content as a direct child
74
- * and the rest is taken care of automatically.
75
- */
76
- declare const Markdown: React.FC<Omit<React.HTMLAttributes<Element>, 'children'> & {
77
- children?: string | null;
78
- options?: MarkdownToJSX.Options;
79
- }>;
80
- export declare namespace MarkdownToJSX {
81
- /**
82
- * RequireAtLeastOne<{ ... }> <- only requires at least one key
83
- */
84
- type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
85
- [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
86
- }[Keys];
87
- export type CreateElement = typeof React.createElement;
88
- export type HTMLTags = keyof React.JSX.IntrinsicElements;
89
- export type State = {
90
- /** true if the current content is inside anchor link grammar */
91
- inAnchor?: boolean;
92
- /** true if parsing in an HTML context */
93
- inHTML?: boolean;
94
- /** true if parsing in an inline context (subset of rules around formatting and links) */
95
- inline?: boolean;
96
- /** true if in a table */
97
- inTable?: boolean;
98
- /** use this for the `key` prop */
99
- key?: React.Key;
100
- /** true if in a list */
101
- list?: boolean;
102
- /** used for lookbacks */
103
- prevCapture?: string;
104
- /** true if parsing in inline context w/o links */
105
- simple?: boolean;
106
- /** current recursion depth during rendering */
107
- renderDepth?: number;
108
- };
109
- export interface BlockQuoteNode {
110
- alert?: string;
111
- children: MarkdownToJSX.ASTNode[];
112
- type: typeof RuleType.blockQuote;
113
- }
114
- export interface BreakLineNode {
115
- type: typeof RuleType.breakLine;
116
- }
117
- export interface BreakThematicNode {
118
- type: typeof RuleType.breakThematic;
119
- }
120
- export interface CodeBlockNode {
121
- type: typeof RuleType.codeBlock;
122
- attrs?: React.JSX.IntrinsicAttributes;
123
- lang?: string;
124
- text: string;
125
- }
126
- export interface CodeFencedNode {
127
- type: typeof RuleType.codeFenced;
128
- }
129
- export interface CodeInlineNode {
130
- type: typeof RuleType.codeInline;
131
- text: string;
132
- }
133
- export interface FootnoteNode {
134
- type: typeof RuleType.footnote;
135
- }
136
- export interface FootnoteReferenceNode {
137
- type: typeof RuleType.footnoteReference;
138
- target: string;
139
- text: string;
140
- }
141
- export interface GFMTaskNode {
142
- type: typeof RuleType.gfmTask;
143
- completed: boolean;
144
- }
145
- export interface HeadingNode {
146
- type: typeof RuleType.heading;
147
- children: MarkdownToJSX.ASTNode[];
148
- id: string;
149
- level: 1 | 2 | 3 | 4 | 5 | 6;
150
- }
151
- export interface HeadingSetextNode {
152
- type: typeof RuleType.headingSetext;
153
- }
154
- export interface HTMLCommentNode {
155
- type: typeof RuleType.htmlComment;
156
- }
157
- export interface ImageNode {
158
- type: typeof RuleType.image;
159
- alt?: string;
160
- target: string;
161
- title?: string;
162
- }
163
- export interface LinkNode {
164
- type: typeof RuleType.link;
165
- children: MarkdownToJSX.ASTNode[];
166
- target: string;
167
- title?: string;
168
- }
169
- export interface LinkAngleBraceNode {
170
- type: typeof RuleType.linkAngleBraceStyleDetector;
171
- }
172
- export interface LinkBareURLNode {
173
- type: typeof RuleType.linkBareUrlDetector;
174
- }
175
- export interface LinkMailtoNode {
176
- type: typeof RuleType.linkMailtoDetector;
177
- }
178
- export interface OrderedListNode {
179
- type: typeof RuleType.orderedList;
180
- items: MarkdownToJSX.ASTNode[][];
181
- ordered: true;
182
- start?: number;
183
- }
184
- export interface UnorderedListNode {
185
- type: typeof RuleType.unorderedList;
186
- items: MarkdownToJSX.ASTNode[][];
187
- ordered: false;
188
- }
189
- export interface NewlineNode {
190
- type: typeof RuleType.newlineCoalescer;
191
- }
192
- export interface ParagraphNode {
193
- type: typeof RuleType.paragraph;
194
- children: MarkdownToJSX.ASTNode[];
195
- }
196
- export interface ReferenceNode {
197
- type: typeof RuleType.ref;
198
- }
199
- export interface ReferenceImageNode {
200
- type: typeof RuleType.refImage;
201
- alt?: string;
202
- ref: string;
203
- }
204
- export interface ReferenceLinkNode {
205
- type: typeof RuleType.refLink;
206
- children: MarkdownToJSX.ASTNode[];
207
- fallbackChildren: string;
208
- ref: string;
209
- }
210
- export interface TableNode {
211
- type: typeof RuleType.table;
212
- /**
213
- * alignment for each table column
214
- */
215
- align: ('left' | 'right' | 'center')[];
216
- cells: MarkdownToJSX.ASTNode[][][];
217
- header: MarkdownToJSX.ASTNode[][];
218
- }
219
- export interface TableSeparatorNode {
220
- type: typeof RuleType.tableSeparator;
221
- }
222
- export interface TextNode {
223
- type: typeof RuleType.text;
224
- text: string;
225
- }
226
- export interface FormattedTextNode {
227
- type: typeof RuleType.textFormatted;
228
- /**
229
- * the corresponding html tag
230
- */
231
- tag: string;
232
- children: MarkdownToJSX.ASTNode[];
233
- }
234
- export interface EscapedTextNode {
235
- type: typeof RuleType.textEscaped;
236
- }
237
- export interface HTMLNode {
238
- type: typeof RuleType.htmlBlock;
239
- attrs: React.JSX.IntrinsicAttributes;
240
- children?: ReturnType<MarkdownToJSX.NestedParser> | undefined;
241
- noInnerParse: Boolean;
242
- tag: MarkdownToJSX.HTMLTags;
243
- text?: string | undefined;
244
- }
245
- export interface HTMLSelfClosingNode {
246
- type: typeof RuleType.htmlSelfClosing;
247
- attrs: React.JSX.IntrinsicAttributes;
248
- tag: string;
249
- }
250
- export type ASTNode = BlockQuoteNode | BreakLineNode | BreakThematicNode | CodeBlockNode | CodeFencedNode | CodeInlineNode | FootnoteNode | FootnoteReferenceNode | GFMTaskNode | HeadingNode | HeadingSetextNode | HTMLCommentNode | ImageNode | LinkNode | LinkAngleBraceNode | LinkBareURLNode | LinkMailtoNode | OrderedListNode | UnorderedListNode | NewlineNode | ParagraphNode | ReferenceNode | ReferenceImageNode | ReferenceLinkNode | TableNode | TableSeparatorNode | TextNode | FormattedTextNode | EscapedTextNode | HTMLNode | HTMLSelfClosingNode;
251
- export type NestedParser = (input: string, state?: MarkdownToJSX.State) => MarkdownToJSX.ASTNode[];
252
- export type Parser<ParserOutput> = (capture: RegExpMatchArray, nestedParse: NestedParser, state?: MarkdownToJSX.State) => ParserOutput;
253
- export type RuleOutput = (ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], state: MarkdownToJSX.State) => React.ReactNode;
254
- export type Rule<ParserOutput = MarkdownToJSX.ASTNode> = {
255
- _match: (source: string, state: MarkdownToJSX.State, prevCapturedString?: string) => RegExpMatchArray;
256
- _order: (typeof Priority)[keyof typeof Priority];
257
- _parse: MarkdownToJSX.Parser<Omit<ParserOutput, 'type'>>;
258
- /**
259
- * Optional fast check that can quickly determine if this rule
260
- * should even be attempted. Should check the start of the source string
261
- * for quick patterns without expensive regex operations.
262
- *
263
- * @param source The input source string (already trimmed of leading whitespace)
264
- * @param state Current parser state
265
- * @returns true if the rule should be attempted, false to skip
266
- */
267
- _qualify?: string[] | ((source: string, state: MarkdownToJSX.State) => boolean);
268
- _render?: (node: ParserOutput,
269
- /**
270
- * Continue rendering AST nodes if applicable.
271
- */
272
- render: RuleOutput, state?: MarkdownToJSX.State) => React.ReactNode;
273
- };
274
- export type Rules = {
275
- [K in ASTNode['type']]: K extends typeof RuleType.table ? Rule<Extract<ASTNode, {
276
- type: K | typeof RuleType.paragraph;
277
- }>> : Rule<Extract<ASTNode, {
278
- type: K;
279
- }>>;
280
- };
281
- export type Override = RequireAtLeastOne<{
282
- component: React.ElementType;
283
- props: Object;
284
- }> | React.ElementType;
285
- export type Overrides = {
286
- [tag in HTMLTags]?: Override;
287
- } & {
288
- [customComponent: string]: Override;
289
- };
290
- export type Options = Partial<{
291
- /**
292
- * When true, returns the parsed AST instead of rendered JSX.
293
- * Footnotes are not automatically appended; the consumer handles them.
294
- */
295
- ast: boolean;
296
- /**
297
- * Ultimate control over the output of all rendered JSX.
298
- */
299
- createElement: (tag: Parameters<CreateElement>[0], props: React.JSX.IntrinsicAttributes, ...children: React.ReactNode[]) => React.ReactNode;
300
- /**
301
- * The library automatically generates an anchor tag for bare URLs included in the markdown
302
- * document, but this behavior can be disabled if desired.
303
- */
304
- disableAutoLink: boolean;
305
- /**
306
- * Disable the compiler's best-effort transcription of provided raw HTML
307
- * into JSX-equivalent. This is the functionality that prevents the need to
308
- * use `dangerouslySetInnerHTML` in React.
309
- */
310
- disableParsingRawHTML: boolean;
311
- /**
312
- * Forces the compiler to have space between hash sign and the header text which
313
- * is explicitly stated in the most of the markdown specs.
314
- * https://github.github.com/gfm/#atx-heading
315
- * `The opening sequence of # characters must be followed by a space or by the end of line.`
316
- */
317
- enforceAtxHeadings: boolean;
318
- /**
319
- * Forces the compiler to always output content with a block-level wrapper
320
- * (`<p>` or any block-level syntax your markdown already contains.)
321
- */
322
- forceBlock: boolean;
323
- /**
324
- * Forces the compiler to always output content with an inline wrapper (`<span>`)
325
- */
326
- forceInline: boolean;
327
- /**
328
- * Forces the compiler to wrap results, even if there is only a single
329
- * child or no children.
330
- */
331
- forceWrapper: boolean;
332
- /**
333
- * Supply additional HTML entity: unicode replacement mappings.
334
- *
335
- * Pass only the inner part of the entity as the key,
336
- * e.g. `&le;` -> `{ "le": "\u2264" }`
337
- *
338
- * By default
339
- * the following entities are replaced with their unicode equivalents:
340
- *
341
- * ```
342
- * &amp;
343
- * &apos;
344
- * &gt;
345
- * &lt;
346
- * &nbsp;
347
- * &quot;
348
- * ```
349
- */
350
- namedCodesToUnicode: {
351
- [key: string]: string;
352
- };
353
- /**
354
- * Selectively control the output of particular HTML tags as they would be
355
- * emitted by the compiler.
356
- */
357
- overrides: Overrides;
358
- /**
359
- * Allows for full control over rendering of particular rules.
360
- * For example, to implement a LaTeX renderer such as `react-katex`:
361
- *
362
- * ```
363
- * renderRule(next, node, renderChildren, state) {
364
- * if (node.type === RuleType.codeBlock && node.lang === 'latex') {
365
- * return (
366
- * <TeX as="div" key={state.key}>
367
- * {String.raw`${node.text}`}
368
- * </TeX>
369
- * )
370
- * }
371
- *
372
- * return next();
373
- * }
374
- * ```
375
- *
376
- * Thar be dragons obviously, but you can do a lot with this
377
- * (have fun!) To see how things work internally, check the `render`
378
- * method in source for a particular rule.
379
- */
380
- renderRule: (
381
- /** Resume normal processing, call this function as a fallback if you are not returning custom JSX. */
382
- next: () => React.ReactNode,
383
- /** the current AST node, use `RuleType` against `node.type` for identification */
384
- node: ASTNode,
385
- /** use as `renderChildren(node.children)` for block nodes */
386
- renderChildren: RuleOutput,
387
- /** contains `key` which should be supplied to the topmost JSX element */
388
- state: State) => React.ReactNode;
389
- /**
390
- * Override the built-in sanitizer function for URLs, etc if desired. The built-in version is available as a library export called `sanitizer`.
391
- */
392
- sanitizer: (value: string, tag: HTMLTags, attribute: string) => string | null;
393
- /**
394
- * Override normalization of non-URI-safe characters for use in generating
395
- * HTML IDs for anchor linking purposes.
396
- */
397
- slugify: (input: string, defaultFn: (input: string) => string) => string;
398
- /**
399
- * Declare the type of the wrapper to be used when there are multiple
400
- * children to render. Set to `null` to get an array of children back
401
- * without any wrapper, or use `React.Fragment` to get a React element
402
- * that won't show up in the DOM.
403
- */
404
- wrapper: React.ElementType | null;
405
- /**
406
- * Props to apply to the wrapper element.
407
- */
408
- wrapperProps?: React.JSX.IntrinsicAttributes;
409
- }>;
410
- export {};
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
+ type CreateElement = typeof React.createElement;
45
+ type HTMLTags = keyof React.JSX.IntrinsicElements & (string & {});
46
+ type State = {
47
+ /** true if the current content is inside anchor link grammar */
48
+ inAnchor?: boolean;
49
+ /** true if inside a blockquote */
50
+ inBlockQuote?: boolean;
51
+ /** true if parsing in an HTML context */
52
+ inHTML?: boolean;
53
+ /** true if in a list */
54
+ inList?: boolean;
55
+ /** true if parsing in an inline context (subset of rules around formatting and links) */
56
+ inline?: boolean;
57
+ /** use this for the `key` prop */
58
+ key?: React.Key;
59
+ /** reference definitions (footnotes are stored with '^' prefix) */
60
+ refs?: {
61
+ [key: string]: {
62
+ target: string;
63
+ title: string | undefined;
64
+ };
65
+ };
66
+ /** current recursion depth during rendering */
67
+ renderDepth?: number;
68
+ };
69
+ interface BlockQuoteNode {
70
+ alert?: string;
71
+ children: MarkdownToJSX.ASTNode[];
72
+ type: typeof RuleType2.blockQuote;
73
+ }
74
+ interface BreakLineNode {
75
+ type: typeof RuleType2.breakLine;
76
+ }
77
+ interface BreakThematicNode {
78
+ type: typeof RuleType2.breakThematic;
79
+ }
80
+ interface CodeBlockNode {
81
+ type: typeof RuleType2.codeBlock;
82
+ attrs?: React.JSX.IntrinsicAttributes;
83
+ lang?: string;
84
+ text: string;
85
+ }
86
+ interface CodeInlineNode {
87
+ type: typeof RuleType2.codeInline;
88
+ text: string;
89
+ }
90
+ interface FootnoteNode {
91
+ type: typeof RuleType2.footnote;
92
+ }
93
+ interface FootnoteReferenceNode {
94
+ type: typeof RuleType2.footnoteReference;
95
+ target: string;
96
+ text: string;
97
+ }
98
+ interface FrontmatterNode {
99
+ type: typeof RuleType2.frontmatter;
100
+ text: string;
101
+ }
102
+ interface GFMTaskNode {
103
+ type: typeof RuleType2.gfmTask;
104
+ completed: boolean;
105
+ }
106
+ interface HeadingNode {
107
+ type: typeof RuleType2.heading;
108
+ children: MarkdownToJSX.ASTNode[];
109
+ id: string;
110
+ level: 1 | 2 | 3 | 4 | 5 | 6;
111
+ }
112
+ interface HTMLCommentNode {
113
+ type: typeof RuleType2.htmlComment;
114
+ text: string;
115
+ }
116
+ interface ImageNode {
117
+ type: typeof RuleType2.image;
118
+ alt?: string;
119
+ target: string;
120
+ title?: string;
121
+ }
122
+ interface LinkNode {
123
+ type: typeof RuleType2.link;
124
+ children: MarkdownToJSX.ASTNode[];
125
+ target: string | null;
126
+ title?: string;
127
+ }
128
+ interface OrderedListNode {
129
+ type: typeof RuleType2.orderedList;
130
+ items: MarkdownToJSX.ASTNode[][];
131
+ start?: number;
132
+ }
133
+ interface UnorderedListNode {
134
+ type: typeof RuleType2.unorderedList;
135
+ items: MarkdownToJSX.ASTNode[][];
136
+ }
137
+ interface ParagraphNode {
138
+ type: typeof RuleType2.paragraph;
139
+ children: MarkdownToJSX.ASTNode[];
140
+ }
141
+ interface ReferenceNode {
142
+ type: typeof RuleType2.ref;
143
+ }
144
+ interface ReferenceCollectionNode {
145
+ type: typeof RuleType2.refCollection;
146
+ refs: {
147
+ [key: string]: {
148
+ target: string;
149
+ title: string | undefined;
150
+ };
151
+ };
152
+ }
153
+ interface TableNode {
154
+ type: typeof RuleType2.table;
155
+ /**
156
+ * alignment for each table column
157
+ */
158
+ align: ("left" | "right" | "center")[];
159
+ cells: MarkdownToJSX.ASTNode[][][];
160
+ header: MarkdownToJSX.ASTNode[][];
161
+ }
162
+ interface TextNode {
163
+ type: typeof RuleType2.text;
164
+ text: string;
165
+ }
166
+ interface FormattedTextNode {
167
+ type: typeof RuleType2.textFormatted;
168
+ /**
169
+ * the corresponding html tag
170
+ */
171
+ tag: string;
172
+ children: MarkdownToJSX.ASTNode[];
173
+ }
174
+ interface HTMLNode {
175
+ type: typeof RuleType2.htmlBlock;
176
+ attrs?: Record<string, any>;
177
+ children?: ASTNode[] | undefined;
178
+ noInnerParse?: Boolean;
179
+ tag: string;
180
+ text?: string | undefined;
181
+ }
182
+ interface HTMLSelfClosingNode {
183
+ type: typeof RuleType2.htmlSelfClosing;
184
+ attrs?: Record<string, any>;
185
+ isClosingTag?: boolean;
186
+ tag: string;
187
+ }
188
+ 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;
189
+ type ASTRender = (ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], state: MarkdownToJSX.State) => React.ReactNode;
190
+ type Override = RequireAtLeastOne<{
191
+ component: React.ElementType;
192
+ props: Object;
193
+ }> | React.ElementType;
194
+ type Overrides = { [tag in HTMLTags]? : Override } & {
195
+ [customComponent: string]: Override;
196
+ };
197
+ type Options = Partial<{
198
+ /**
199
+ * Ultimate control over the output of all rendered JSX.
200
+ */
201
+ createElement: (tag: Parameters<CreateElement>[0], props: React.JSX.IntrinsicAttributes, ...children: React.ReactNode[]) => React.ReactNode;
202
+ /**
203
+ * The library automatically generates an anchor tag for bare URLs included in the markdown
204
+ * document, but this behavior can be disabled if desired.
205
+ */
206
+ disableAutoLink: boolean;
207
+ /**
208
+ * Disable the compiler's best-effort transcription of provided raw HTML
209
+ * into JSX-equivalent. This is the functionality that prevents the need to
210
+ * use `dangerouslySetInnerHTML` in React.
211
+ */
212
+ disableParsingRawHTML: boolean;
213
+ /**
214
+ * Enable GFM tagfilter extension to filter potentially dangerous HTML tags.
215
+ * When enabled, the following tags are escaped: title, textarea, style, xmp,
216
+ * iframe, noembed, noframes, script, plaintext.
217
+ * https://github.github.com/gfm/#disallowed-raw-html-extension-
218
+ * @default true
219
+ */
220
+ tagfilter?: boolean;
221
+ /**
222
+ * Forces the compiler to have space between hash sign and the header text which
223
+ * is explicitly stated in the most of the markdown specs.
224
+ * https://github.github.com/gfm/#atx-heading
225
+ * `The opening sequence of # characters must be followed by a space or by the end of line.`
226
+ */
227
+ enforceAtxHeadings: boolean;
228
+ /**
229
+ * Forces the compiler to always output content with a block-level wrapper
230
+ * (`<p>` or any block-level syntax your markdown already contains.)
231
+ */
232
+ forceBlock: boolean;
233
+ /**
234
+ * Forces the compiler to always output content with an inline wrapper (`<span>`)
235
+ */
236
+ forceInline: boolean;
237
+ /**
238
+ * Forces the compiler to wrap results, even if there is only a single
239
+ * child or no children.
240
+ */
241
+ forceWrapper: boolean;
242
+ /**
243
+ * Selectively control the output of particular HTML tags as they would be
244
+ * emitted by the compiler.
245
+ */
246
+ overrides: Overrides;
247
+ /**
248
+ * Allows for full control over rendering of particular rules.
249
+ * For example, to implement a LaTeX renderer such as `react-katex`:
250
+ *
251
+ * ```
252
+ * renderRule(next, node, renderChildren, state) {
253
+ * if (node.type === RuleType.codeBlock && node.lang === 'latex') {
254
+ * return (
255
+ * <TeX as="div" key={state.key}>
256
+ * {String.raw`${node.text}`}
257
+ * </TeX>
258
+ * )
259
+ * }
260
+ *
261
+ * return next();
262
+ * }
263
+ * ```
264
+ *
265
+ * Thar be dragons obviously, but you can do a lot with this
266
+ * (have fun!) To see how things work internally, check the `render`
267
+ * method in source for a particular rule.
268
+ */
269
+ renderRule: (next: () => React.ReactNode, node: ASTNode, renderChildren: ASTRender, state: State) => React.ReactNode;
270
+ /**
271
+ * Override the built-in sanitizer function for URLs, etc if desired. The built-in version is available as a library
272
+ called `sanitizer`.
273
+ */
274
+ sanitizer: (value: string, tag: HTMLTags, attribute: string) => string | null;
275
+ /**
276
+ * Override normalization of non-URI-safe characters for use in generating
277
+ * HTML IDs for anchor linking purposes.
278
+ */
279
+ slugify: (input: string, defaultFn: (input: string) => string) => string;
280
+ /**
281
+ * Declare the type of the wrapper to be used when there are multiple
282
+ * children to render. Set to `null` to get an array of children back
283
+ * without any wrapper, or use `React.Fragment` to get a React element
284
+ * that won't show up in the DOM.
285
+ */
286
+ wrapper: React.ElementType | null;
287
+ /**
288
+ * Props to apply to the wrapper element.
289
+ */
290
+ wrapperProps?: React.JSX.IntrinsicAttributes;
291
+ }>;
292
+ {}
293
+ ;
294
+ }
295
+ declare const RuleType2: typeof RuleTypeConst;
296
+ type RuleType2 = RuleTypeValue;
297
+ declare global {
298
+ var parseMetrics: {
299
+ blockParsers: {
300
+ [key: string]: {
301
+ attempts: number;
302
+ hits: number;
303
+ hitTimings: number[];
304
+ };
305
+ };
306
+ inlineParsers: {
307
+ [key: string]: {
308
+ attempts: number;
309
+ hits: number;
310
+ hitTimings: number[];
311
+ };
312
+ };
313
+ totalOperations: number;
314
+ blockParseIterations: number;
315
+ inlineParseIterations: number;
316
+ } | null;
317
+ var parseMetricsStartTimes: Map<string, number> | null;
411
318
  }
412
- export default Markdown;
319
+ /**
320
+ * Given a markdown string, return an abstract syntax tree (AST) of the markdown.
321
+ *
322
+ * The first node in the AST is a reference collection node. This node contains all the
323
+ * reference definitions found in the markdown. These reference definitions are used to
324
+ * resolve reference links and images in the markdown.
325
+ *
326
+ * @param source - The markdown string to parse.
327
+ * @param options - The options for the parser.
328
+ * @returns The AST of the markdown.
329
+ */
330
+ declare function parser(source: string, options?: MarkdownToJSX.Options): MarkdownToJSX.ASTNode[];
331
+ declare function sanitizer(input: string): string | null;
332
+ declare function slugify(str: string): string;
333
+ declare function compiler(markdown?: string, options?: MarkdownToJSX.Options): React2.ReactNode;
334
+ /**
335
+ * A simple HOC for easy React use. Feed the markdown content as a direct child
336
+ * and the rest is taken care of automatically.
337
+ */
338
+ declare const Markdown: React2.FC<Omit<React2.HTMLAttributes<Element>, "children"> & {
339
+ children?: string | null;
340
+ options?: MarkdownToJSX.Options;
341
+ }>;
342
+ export { slugify, sanitizer, parser, Markdown as default, compiler, RuleType2 as RuleType, MarkdownToJSX, Markdown };