markdown-to-jsx 9.4.1 → 9.4.2
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/markdown.cjs +55 -55
- package/dist/markdown.d.cts +363 -1
- package/dist/markdown.d.ts +363 -1
- package/dist/markdown.js +34 -34
- package/dist/markdown.js.map +3 -3
- package/package.json +1 -1
package/dist/markdown.d.cts
CHANGED
|
@@ -1,3 +1,365 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Analogous to `node.type`. Please note that the values here may change at any time,
|
|
4
|
+
* so do not hard code against the value directly.
|
|
5
|
+
*/
|
|
6
|
+
declare const RuleTypeConst: {
|
|
7
|
+
readonly blockQuote: 0;
|
|
8
|
+
readonly breakLine: 1;
|
|
9
|
+
readonly breakThematic: 2;
|
|
10
|
+
readonly codeBlock: 3;
|
|
11
|
+
readonly codeInline: 4;
|
|
12
|
+
readonly footnote: 5;
|
|
13
|
+
readonly footnoteReference: 6;
|
|
14
|
+
readonly frontmatter: 7;
|
|
15
|
+
readonly gfmTask: 8;
|
|
16
|
+
readonly heading: 9;
|
|
17
|
+
readonly htmlBlock: 10;
|
|
18
|
+
readonly htmlComment: 11;
|
|
19
|
+
readonly htmlSelfClosing: 12;
|
|
20
|
+
readonly image: 13;
|
|
21
|
+
readonly link: 14;
|
|
22
|
+
readonly orderedList: 15;
|
|
23
|
+
readonly paragraph: 16;
|
|
24
|
+
readonly ref: 17;
|
|
25
|
+
readonly refCollection: 18;
|
|
26
|
+
readonly table: 19;
|
|
27
|
+
readonly text: 20;
|
|
28
|
+
readonly textFormatted: 21;
|
|
29
|
+
readonly unorderedList: 22;
|
|
30
|
+
};
|
|
31
|
+
type RuleTypeValue = (typeof RuleTypeConst)[keyof typeof RuleTypeConst];
|
|
32
|
+
/**
|
|
33
|
+
* markdown-to-jsx types and interfaces
|
|
34
|
+
*/
|
|
35
|
+
declare namespace MarkdownToJSX {
|
|
36
|
+
/**
|
|
37
|
+
* RequireAtLeastOne<{ ... }> <- only requires at least one key
|
|
38
|
+
*/
|
|
39
|
+
type RequireAtLeastOne<
|
|
40
|
+
T,
|
|
41
|
+
Keys extends keyof T = keyof T
|
|
42
|
+
> = Pick<T, Exclude<keyof T, Keys>> & { [K in Keys]-? : Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>> }[Keys];
|
|
43
|
+
export type CreateElement = typeof React.createElement;
|
|
44
|
+
export type HTMLTags = keyof React.JSX.IntrinsicElements & (string & {});
|
|
45
|
+
export type State = {
|
|
46
|
+
/** true if the current content is inside anchor link grammar */
|
|
47
|
+
inAnchor?: boolean;
|
|
48
|
+
/** true if inside a blockquote */
|
|
49
|
+
inBlockQuote?: boolean;
|
|
50
|
+
/** true if parsing in an HTML context */
|
|
51
|
+
inHTML?: boolean;
|
|
52
|
+
/** true if in a list */
|
|
53
|
+
inList?: boolean;
|
|
54
|
+
/** true if parsing in an inline context (subset of rules around formatting and links) */
|
|
55
|
+
inline?: boolean;
|
|
56
|
+
/** use this for the `key` prop */
|
|
57
|
+
key?: string | number;
|
|
58
|
+
/** reference definitions (footnotes are stored with '^' prefix) */
|
|
59
|
+
refs?: {
|
|
60
|
+
[key: string]: {
|
|
61
|
+
target: string;
|
|
62
|
+
title: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/** current recursion depth during rendering */
|
|
66
|
+
renderDepth?: number;
|
|
67
|
+
};
|
|
68
|
+
export interface BlockQuoteNode {
|
|
69
|
+
alert?: string;
|
|
70
|
+
children: MarkdownToJSX.ASTNode[];
|
|
71
|
+
type: typeof RuleType.blockQuote;
|
|
72
|
+
}
|
|
73
|
+
export interface BreakLineNode {
|
|
74
|
+
type: typeof RuleType.breakLine;
|
|
75
|
+
}
|
|
76
|
+
export interface BreakThematicNode {
|
|
77
|
+
type: typeof RuleType.breakThematic;
|
|
78
|
+
}
|
|
79
|
+
export interface CodeBlockNode {
|
|
80
|
+
type: typeof RuleType.codeBlock;
|
|
81
|
+
attrs?: React.JSX.IntrinsicAttributes;
|
|
82
|
+
lang?: string;
|
|
83
|
+
text: string;
|
|
84
|
+
}
|
|
85
|
+
export interface CodeInlineNode {
|
|
86
|
+
type: typeof RuleType.codeInline;
|
|
87
|
+
text: string;
|
|
88
|
+
}
|
|
89
|
+
export interface FootnoteNode {
|
|
90
|
+
type: typeof RuleType.footnote;
|
|
91
|
+
}
|
|
92
|
+
export interface FootnoteReferenceNode {
|
|
93
|
+
type: typeof RuleType.footnoteReference;
|
|
94
|
+
target: string;
|
|
95
|
+
text: string;
|
|
96
|
+
}
|
|
97
|
+
export interface FrontmatterNode {
|
|
98
|
+
type: typeof RuleType.frontmatter;
|
|
99
|
+
text: string;
|
|
100
|
+
}
|
|
101
|
+
export interface GFMTaskNode {
|
|
102
|
+
type: typeof RuleType.gfmTask;
|
|
103
|
+
completed: boolean;
|
|
104
|
+
}
|
|
105
|
+
export interface HeadingNode {
|
|
106
|
+
type: typeof RuleType.heading;
|
|
107
|
+
children: MarkdownToJSX.ASTNode[];
|
|
108
|
+
id: string;
|
|
109
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
110
|
+
}
|
|
111
|
+
export interface HTMLCommentNode {
|
|
112
|
+
type: typeof RuleType.htmlComment;
|
|
113
|
+
text: string;
|
|
114
|
+
}
|
|
115
|
+
export interface ImageNode {
|
|
116
|
+
type: typeof RuleType.image;
|
|
117
|
+
alt?: string;
|
|
118
|
+
target: string;
|
|
119
|
+
title?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface LinkNode {
|
|
122
|
+
type: typeof RuleType.link;
|
|
123
|
+
children: MarkdownToJSX.ASTNode[];
|
|
124
|
+
target: string | null;
|
|
125
|
+
title?: string;
|
|
126
|
+
}
|
|
127
|
+
export interface OrderedListNode {
|
|
128
|
+
type: typeof RuleType.orderedList;
|
|
129
|
+
items: MarkdownToJSX.ASTNode[][];
|
|
130
|
+
start?: number;
|
|
131
|
+
}
|
|
132
|
+
export interface UnorderedListNode {
|
|
133
|
+
type: typeof RuleType.unorderedList;
|
|
134
|
+
items: MarkdownToJSX.ASTNode[][];
|
|
135
|
+
}
|
|
136
|
+
export interface ParagraphNode {
|
|
137
|
+
type: typeof RuleType.paragraph;
|
|
138
|
+
children: MarkdownToJSX.ASTNode[];
|
|
139
|
+
}
|
|
140
|
+
export interface ReferenceNode {
|
|
141
|
+
type: typeof RuleType.ref;
|
|
142
|
+
}
|
|
143
|
+
export interface ReferenceCollectionNode {
|
|
144
|
+
type: typeof RuleType.refCollection;
|
|
145
|
+
refs: {
|
|
146
|
+
[key: string]: {
|
|
147
|
+
target: string;
|
|
148
|
+
title: string | undefined;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export interface TableNode {
|
|
153
|
+
type: typeof RuleType.table;
|
|
154
|
+
/**
|
|
155
|
+
* alignment for each table column
|
|
156
|
+
*/
|
|
157
|
+
align: ("left" | "right" | "center")[];
|
|
158
|
+
cells: MarkdownToJSX.ASTNode[][][];
|
|
159
|
+
header: MarkdownToJSX.ASTNode[][];
|
|
160
|
+
}
|
|
161
|
+
export interface TextNode {
|
|
162
|
+
type: typeof RuleType.text;
|
|
163
|
+
text: string;
|
|
164
|
+
}
|
|
165
|
+
export interface FormattedTextNode {
|
|
166
|
+
type: typeof RuleType.textFormatted;
|
|
167
|
+
/**
|
|
168
|
+
* the corresponding html tag
|
|
169
|
+
*/
|
|
170
|
+
tag: string;
|
|
171
|
+
children: MarkdownToJSX.ASTNode[];
|
|
172
|
+
}
|
|
173
|
+
export interface HTMLNode {
|
|
174
|
+
type: typeof RuleType.htmlBlock;
|
|
175
|
+
attrs?: Record<string, any>;
|
|
176
|
+
children?: ASTNode[] | undefined;
|
|
177
|
+
verbatim?: boolean;
|
|
178
|
+
rawAttrs?: string;
|
|
179
|
+
rawText?: string | undefined;
|
|
180
|
+
/** @deprecated Use `rawText` instead. This property will be removed in a future major version. */
|
|
181
|
+
text?: string | undefined;
|
|
182
|
+
tag: string;
|
|
183
|
+
}
|
|
184
|
+
export interface HTMLSelfClosingNode {
|
|
185
|
+
type: typeof RuleType.htmlSelfClosing;
|
|
186
|
+
attrs?: Record<string, any>;
|
|
187
|
+
isClosingTag?: boolean;
|
|
188
|
+
tag: string;
|
|
189
|
+
rawText?: string;
|
|
190
|
+
}
|
|
191
|
+
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;
|
|
192
|
+
export type ASTRender = (ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], state: MarkdownToJSX.State) => React.ReactNode;
|
|
193
|
+
export type Override = RequireAtLeastOne<{
|
|
194
|
+
component: React.ElementType;
|
|
195
|
+
props: Object;
|
|
196
|
+
}> | React.ElementType;
|
|
197
|
+
export type Overrides = { [tag in HTMLTags]? : Override } & {
|
|
198
|
+
[customComponent: string]: Override;
|
|
199
|
+
};
|
|
200
|
+
export type Options = Partial<{
|
|
201
|
+
/**
|
|
202
|
+
* Ultimate control over the output of all rendered JSX.
|
|
203
|
+
*/
|
|
204
|
+
createElement: (tag: Parameters<CreateElement>[0], props: React.JSX.IntrinsicAttributes, ...children: React.ReactNode[]) => React.ReactNode;
|
|
205
|
+
/**
|
|
206
|
+
* The library automatically generates an anchor tag for bare URLs included in the markdown
|
|
207
|
+
* document, but this behavior can be disabled if desired.
|
|
208
|
+
*/
|
|
209
|
+
disableAutoLink: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Disable the compiler's best-effort transcription of provided raw HTML
|
|
212
|
+
* into JSX-equivalent. This is the functionality that prevents the need to
|
|
213
|
+
* use `dangerouslySetInnerHTML` in React.
|
|
214
|
+
*/
|
|
215
|
+
disableParsingRawHTML: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Enable GFM tagfilter extension to filter potentially dangerous HTML tags.
|
|
218
|
+
* When enabled, the following tags are escaped: title, textarea, style, xmp,
|
|
219
|
+
* iframe, noembed, noframes, script, plaintext.
|
|
220
|
+
* https://github.github.com/gfm/#disallowed-raw-html-extension-
|
|
221
|
+
* @default true
|
|
222
|
+
*/
|
|
223
|
+
tagfilter?: boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Forces the compiler to have space between hash sign and the header text which
|
|
226
|
+
* is explicitly stated in the most of the markdown specs.
|
|
227
|
+
* https://github.github.com/gfm/#atx-heading
|
|
228
|
+
* `The opening sequence of # characters must be followed by a space or by the end of line.`
|
|
229
|
+
*/
|
|
230
|
+
enforceAtxHeadings: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* **⚠️ SECURITY WARNING: STRONGLY DISCOURAGED FOR USER INPUTS**
|
|
233
|
+
*
|
|
234
|
+
* When enabled, attempts to eval expressions in JSX props that cannot be serialized
|
|
235
|
+
* as JSON (functions, variables, complex expressions). This uses `eval()` which can
|
|
236
|
+
* execute arbitrary code.
|
|
237
|
+
*
|
|
238
|
+
* **ONLY use this option when:**
|
|
239
|
+
* - The markdown source is completely trusted (e.g., your own documentation)
|
|
240
|
+
* - You control all JSX components and their props
|
|
241
|
+
* - The content is NOT user-generated or user-editable
|
|
242
|
+
*
|
|
243
|
+
* **DO NOT use this option when:**
|
|
244
|
+
* - Processing user-submitted markdown
|
|
245
|
+
* - Rendering untrusted content
|
|
246
|
+
* - Building public-facing applications with user content
|
|
247
|
+
*
|
|
248
|
+
* Example unsafe input: `<Component onClick={() => fetch('/admin/delete-all')} />`
|
|
249
|
+
*
|
|
250
|
+
* When disabled (default), unserializable expressions remain as strings that can be
|
|
251
|
+
* safely inspected or handled on a case-by-case basis via custom renderRule logic.
|
|
252
|
+
*
|
|
253
|
+
* @default false
|
|
254
|
+
*/
|
|
255
|
+
evalUnserializableExpressions?: boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Forces the compiler to always output content with a block-level wrapper
|
|
258
|
+
* (`<p>` or any block-level syntax your markdown already contains.)
|
|
259
|
+
*/
|
|
260
|
+
forceBlock: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Forces the compiler to always output content with an inline wrapper (`<span>`)
|
|
263
|
+
*/
|
|
264
|
+
forceInline: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Forces the compiler to wrap results, even if there is only a single
|
|
267
|
+
* child or no children.
|
|
268
|
+
*/
|
|
269
|
+
forceWrapper: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Selectively control the output of particular HTML tags as they would be
|
|
272
|
+
* emitted by the compiler.
|
|
273
|
+
*/
|
|
274
|
+
overrides: Overrides;
|
|
275
|
+
/**
|
|
276
|
+
* Allows for full control over rendering of particular rules.
|
|
277
|
+
* For example, to implement a LaTeX renderer such as `react-katex`:
|
|
278
|
+
*
|
|
279
|
+
* ```
|
|
280
|
+
* renderRule(next, node, renderChildren, state) {
|
|
281
|
+
* if (node.type === RuleType.codeBlock && node.lang === 'latex') {
|
|
282
|
+
* return (
|
|
283
|
+
* <TeX as="div" key={state.key}>
|
|
284
|
+
* {String.raw`${node.text}`}
|
|
285
|
+
* </TeX>
|
|
286
|
+
* )
|
|
287
|
+
* }
|
|
288
|
+
*
|
|
289
|
+
* return next();
|
|
290
|
+
* }
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* Thar be dragons obviously, but you can do a lot with this
|
|
294
|
+
* (have fun!) To see how things work internally, check the `render`
|
|
295
|
+
* method in source for a particular rule.
|
|
296
|
+
*/
|
|
297
|
+
renderRule: (next: () => React.ReactNode, node: ASTNode, renderChildren: ASTRender, state: State) => React.ReactNode;
|
|
298
|
+
/**
|
|
299
|
+
* Override the built-in sanitizer function for URLs, etc if desired. The built-in version is available as a library
|
|
300
|
+
export called `sanitizer`.
|
|
301
|
+
*/
|
|
302
|
+
sanitizer: (value: string, tag: string, attribute: string) => string | null;
|
|
303
|
+
/**
|
|
304
|
+
* Override normalization of non-URI-safe characters for use in generating
|
|
305
|
+
* HTML IDs for anchor linking purposes.
|
|
306
|
+
*/
|
|
307
|
+
slugify: (input: string, defaultFn: (input: string) => string) => string;
|
|
308
|
+
/**
|
|
309
|
+
* Declare the type of the wrapper to be used when there are multiple
|
|
310
|
+
* children to render. Set to `null` to get an array of children back
|
|
311
|
+
* without any wrapper, or use `React.Fragment` to get a React element
|
|
312
|
+
* that won't show up in the DOM.
|
|
313
|
+
*/
|
|
314
|
+
wrapper: React.ElementType | null;
|
|
315
|
+
/**
|
|
316
|
+
* Props to apply to the wrapper element.
|
|
317
|
+
*/
|
|
318
|
+
wrapperProps?: React.JSX.IntrinsicAttributes;
|
|
319
|
+
/**
|
|
320
|
+
* Preserve frontmatter in the output by rendering it as a <pre> element.
|
|
321
|
+
* By default, frontmatter is parsed but not rendered.
|
|
322
|
+
* @default false
|
|
323
|
+
*/
|
|
324
|
+
preserveFrontmatter?: boolean;
|
|
325
|
+
}>;
|
|
326
|
+
}
|
|
327
|
+
declare const RuleType: typeof RuleTypeConst;
|
|
328
|
+
type RuleType = RuleTypeValue;
|
|
329
|
+
declare global {
|
|
330
|
+
var parseMetrics: {
|
|
331
|
+
blockParsers: {
|
|
332
|
+
[key: string]: {
|
|
333
|
+
attempts: number;
|
|
334
|
+
hits: number;
|
|
335
|
+
hitTimings: number[];
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
inlineParsers: {
|
|
339
|
+
[key: string]: {
|
|
340
|
+
attempts: number;
|
|
341
|
+
hits: number;
|
|
342
|
+
hitTimings: number[];
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
totalOperations: number;
|
|
346
|
+
blockParseIterations: number;
|
|
347
|
+
inlineParseIterations: number;
|
|
348
|
+
} | null;
|
|
349
|
+
var parseMetricsStartTimes: Map<string, number> | null;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Given a markdown string, return an abstract syntax tree (AST) of the markdown.
|
|
353
|
+
*
|
|
354
|
+
* The first node in the AST is a reference collection node. This node contains all the
|
|
355
|
+
* reference definitions found in the markdown. These reference definitions are used to
|
|
356
|
+
* resolve reference links and images in the markdown.
|
|
357
|
+
*
|
|
358
|
+
* @param source - The markdown string to parse.
|
|
359
|
+
* @param options - The options for the parser.
|
|
360
|
+
* @returns The AST of the markdown.
|
|
361
|
+
*/
|
|
362
|
+
declare function parser(source: string, options?: MarkdownToJSX.Options): MarkdownToJSX.ASTNode[];
|
|
1
363
|
type MarkdownOverride = {
|
|
2
364
|
component?: string;
|
|
3
365
|
props?: Record<string, string | number | boolean>;
|
|
@@ -38,4 +400,4 @@ type MarkdownCompilerOptions = Omit<MarkdownToJSX.Options, "createElement" | "wr
|
|
|
38
400
|
declare function compiler(input: string, options?: MarkdownCompilerOptions): string;
|
|
39
401
|
declare function astToMarkdown(ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], options?: MarkdownCompilerOptions): string;
|
|
40
402
|
declare const markdown: typeof astToMarkdown;
|
|
41
|
-
export { markdown, compiler, astToMarkdown, MarkdownOverrides, MarkdownOverride, MarkdownCompilerOptions };
|
|
403
|
+
export { parser, markdown, compiler, astToMarkdown, RuleType, MarkdownToJSX, MarkdownOverrides, MarkdownOverride, MarkdownCompilerOptions };
|