markdown-to-jsx 9.2.0 → 9.3.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/README.md +93 -20
- package/dist/html.cjs +97 -96
- package/dist/html.d.cts +4 -2
- package/dist/html.d.ts +4 -2
- package/dist/html.js +97 -96
- package/dist/html.js.map +7 -7
- package/dist/index.cjs +85 -85
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +83 -83
- package/dist/index.js.map +7 -7
- package/dist/markdown.cjs +93 -93
- package/dist/markdown.js +93 -93
- package/dist/markdown.js.map +6 -6
- package/dist/native.cjs +100 -100
- package/dist/native.d.cts +3 -2
- package/dist/native.d.ts +3 -2
- package/dist/native.js +102 -102
- package/dist/native.js.map +7 -7
- package/dist/react.cjs +83 -83
- package/dist/react.d.cts +4 -8
- package/dist/react.d.ts +4 -8
- package/dist/react.js +85 -85
- package/dist/react.js.map +7 -7
- package/dist/solid.cjs +108 -0
- package/dist/solid.d.cts +373 -0
- package/dist/solid.d.ts +373 -0
- package/dist/solid.js +108 -0
- package/dist/solid.js.map +15 -0
- package/dist/vue.cjs +108 -0
- package/dist/vue.d.cts +373 -0
- package/dist/vue.d.ts +373 -0
- package/dist/vue.js +108 -0
- package/dist/vue.js.map +15 -0
- package/package.json +43 -4
package/dist/vue.d.cts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { h, VNode, Component } 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
|
+
export type CreateElement = typeof React.createElement;
|
|
45
|
+
export type HTMLTags = keyof React.JSX.IntrinsicElements & (string & {});
|
|
46
|
+
export 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?: string | number;
|
|
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
|
+
export interface BlockQuoteNode {
|
|
70
|
+
alert?: string;
|
|
71
|
+
children: MarkdownToJSX.ASTNode[];
|
|
72
|
+
type: typeof RuleType2.blockQuote;
|
|
73
|
+
}
|
|
74
|
+
export interface BreakLineNode {
|
|
75
|
+
type: typeof RuleType2.breakLine;
|
|
76
|
+
}
|
|
77
|
+
export interface BreakThematicNode {
|
|
78
|
+
type: typeof RuleType2.breakThematic;
|
|
79
|
+
}
|
|
80
|
+
export interface CodeBlockNode {
|
|
81
|
+
type: typeof RuleType2.codeBlock;
|
|
82
|
+
attrs?: React.JSX.IntrinsicAttributes;
|
|
83
|
+
lang?: string;
|
|
84
|
+
text: string;
|
|
85
|
+
}
|
|
86
|
+
export interface CodeInlineNode {
|
|
87
|
+
type: typeof RuleType2.codeInline;
|
|
88
|
+
text: string;
|
|
89
|
+
}
|
|
90
|
+
export interface FootnoteNode {
|
|
91
|
+
type: typeof RuleType2.footnote;
|
|
92
|
+
}
|
|
93
|
+
export interface FootnoteReferenceNode {
|
|
94
|
+
type: typeof RuleType2.footnoteReference;
|
|
95
|
+
target: string;
|
|
96
|
+
text: string;
|
|
97
|
+
}
|
|
98
|
+
export interface FrontmatterNode {
|
|
99
|
+
type: typeof RuleType2.frontmatter;
|
|
100
|
+
text: string;
|
|
101
|
+
}
|
|
102
|
+
export interface GFMTaskNode {
|
|
103
|
+
type: typeof RuleType2.gfmTask;
|
|
104
|
+
completed: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface HeadingNode {
|
|
107
|
+
type: typeof RuleType2.heading;
|
|
108
|
+
children: MarkdownToJSX.ASTNode[];
|
|
109
|
+
id: string;
|
|
110
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
111
|
+
}
|
|
112
|
+
export interface HTMLCommentNode {
|
|
113
|
+
type: typeof RuleType2.htmlComment;
|
|
114
|
+
text: string;
|
|
115
|
+
}
|
|
116
|
+
export interface ImageNode {
|
|
117
|
+
type: typeof RuleType2.image;
|
|
118
|
+
alt?: string;
|
|
119
|
+
target: string;
|
|
120
|
+
title?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface LinkNode {
|
|
123
|
+
type: typeof RuleType2.link;
|
|
124
|
+
children: MarkdownToJSX.ASTNode[];
|
|
125
|
+
target: string | null;
|
|
126
|
+
title?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface OrderedListNode {
|
|
129
|
+
type: typeof RuleType2.orderedList;
|
|
130
|
+
items: MarkdownToJSX.ASTNode[][];
|
|
131
|
+
start?: number;
|
|
132
|
+
}
|
|
133
|
+
export interface UnorderedListNode {
|
|
134
|
+
type: typeof RuleType2.unorderedList;
|
|
135
|
+
items: MarkdownToJSX.ASTNode[][];
|
|
136
|
+
}
|
|
137
|
+
export interface ParagraphNode {
|
|
138
|
+
type: typeof RuleType2.paragraph;
|
|
139
|
+
children: MarkdownToJSX.ASTNode[];
|
|
140
|
+
}
|
|
141
|
+
export interface ReferenceNode {
|
|
142
|
+
type: typeof RuleType2.ref;
|
|
143
|
+
}
|
|
144
|
+
export interface ReferenceCollectionNode {
|
|
145
|
+
type: typeof RuleType2.refCollection;
|
|
146
|
+
refs: {
|
|
147
|
+
[key: string]: {
|
|
148
|
+
target: string;
|
|
149
|
+
title: string | undefined;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
export 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
|
+
export interface TextNode {
|
|
163
|
+
type: typeof RuleType2.text;
|
|
164
|
+
text: string;
|
|
165
|
+
}
|
|
166
|
+
export interface FormattedTextNode {
|
|
167
|
+
type: typeof RuleType2.textFormatted;
|
|
168
|
+
/**
|
|
169
|
+
* the corresponding html tag
|
|
170
|
+
*/
|
|
171
|
+
tag: string;
|
|
172
|
+
children: MarkdownToJSX.ASTNode[];
|
|
173
|
+
}
|
|
174
|
+
export 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
|
+
export interface HTMLSelfClosingNode {
|
|
183
|
+
type: typeof RuleType2.htmlSelfClosing;
|
|
184
|
+
attrs?: Record<string, any>;
|
|
185
|
+
isClosingTag?: boolean;
|
|
186
|
+
tag: string;
|
|
187
|
+
rawText?: string;
|
|
188
|
+
}
|
|
189
|
+
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;
|
|
190
|
+
export type ASTRender = (ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], state: MarkdownToJSX.State) => React.ReactNode;
|
|
191
|
+
export type Override = RequireAtLeastOne<{
|
|
192
|
+
component: React.ElementType;
|
|
193
|
+
props: Object;
|
|
194
|
+
}> | React.ElementType;
|
|
195
|
+
export type Overrides = { [tag in HTMLTags]? : Override } & {
|
|
196
|
+
[customComponent: string]: Override;
|
|
197
|
+
};
|
|
198
|
+
export type Options = Partial<{
|
|
199
|
+
/**
|
|
200
|
+
* Ultimate control over the output of all rendered JSX.
|
|
201
|
+
*/
|
|
202
|
+
createElement: (tag: Parameters<CreateElement>[0], props: React.JSX.IntrinsicAttributes, ...children: React.ReactNode[]) => React.ReactNode;
|
|
203
|
+
/**
|
|
204
|
+
* The library automatically generates an anchor tag for bare URLs included in the markdown
|
|
205
|
+
* document, but this behavior can be disabled if desired.
|
|
206
|
+
*/
|
|
207
|
+
disableAutoLink: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Disable the compiler's best-effort transcription of provided raw HTML
|
|
210
|
+
* into JSX-equivalent. This is the functionality that prevents the need to
|
|
211
|
+
* use `dangerouslySetInnerHTML` in React.
|
|
212
|
+
*/
|
|
213
|
+
disableParsingRawHTML: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Enable GFM tagfilter extension to filter potentially dangerous HTML tags.
|
|
216
|
+
* When enabled, the following tags are escaped: title, textarea, style, xmp,
|
|
217
|
+
* iframe, noembed, noframes, script, plaintext.
|
|
218
|
+
* https://github.github.com/gfm/#disallowed-raw-html-extension-
|
|
219
|
+
* @default true
|
|
220
|
+
*/
|
|
221
|
+
tagfilter?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Forces the compiler to have space between hash sign and the header text which
|
|
224
|
+
* is explicitly stated in the most of the markdown specs.
|
|
225
|
+
* https://github.github.com/gfm/#atx-heading
|
|
226
|
+
* `The opening sequence of # characters must be followed by a space or by the end of line.`
|
|
227
|
+
*/
|
|
228
|
+
enforceAtxHeadings: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Forces the compiler to always output content with a block-level wrapper
|
|
231
|
+
* (`<p>` or any block-level syntax your markdown already contains.)
|
|
232
|
+
*/
|
|
233
|
+
forceBlock: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Forces the compiler to always output content with an inline wrapper (`<span>`)
|
|
236
|
+
*/
|
|
237
|
+
forceInline: boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Forces the compiler to wrap results, even if there is only a single
|
|
240
|
+
* child or no children.
|
|
241
|
+
*/
|
|
242
|
+
forceWrapper: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Selectively control the output of particular HTML tags as they would be
|
|
245
|
+
* emitted by the compiler.
|
|
246
|
+
*/
|
|
247
|
+
overrides: Overrides;
|
|
248
|
+
/**
|
|
249
|
+
* Allows for full control over rendering of particular rules.
|
|
250
|
+
* For example, to implement a LaTeX renderer such as `react-katex`:
|
|
251
|
+
*
|
|
252
|
+
* ```
|
|
253
|
+
* renderRule(next, node, renderChildren, state) {
|
|
254
|
+
* if (node.type === RuleType.codeBlock && node.lang === 'latex') {
|
|
255
|
+
* return (
|
|
256
|
+
* <TeX as="div" key={state.key}>
|
|
257
|
+
* {String.raw`${node.text}`}
|
|
258
|
+
* </TeX>
|
|
259
|
+
* )
|
|
260
|
+
* }
|
|
261
|
+
*
|
|
262
|
+
* return next();
|
|
263
|
+
* }
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* Thar be dragons obviously, but you can do a lot with this
|
|
267
|
+
* (have fun!) To see how things work internally, check the `render`
|
|
268
|
+
* method in source for a particular rule.
|
|
269
|
+
*/
|
|
270
|
+
renderRule: (next: () => React.ReactNode, node: ASTNode, renderChildren: ASTRender, state: State) => React.ReactNode;
|
|
271
|
+
/**
|
|
272
|
+
* Override the built-in sanitizer function for URLs, etc if desired. The built-in version is available as a library
|
|
273
|
+
export called `sanitizer`.
|
|
274
|
+
*/
|
|
275
|
+
sanitizer: (value: string, tag: string, attribute: string) => string | null;
|
|
276
|
+
/**
|
|
277
|
+
* Override normalization of non-URI-safe characters for use in generating
|
|
278
|
+
* HTML IDs for anchor linking purposes.
|
|
279
|
+
*/
|
|
280
|
+
slugify: (input: string, defaultFn: (input: string) => string) => string;
|
|
281
|
+
/**
|
|
282
|
+
* Declare the type of the wrapper to be used when there are multiple
|
|
283
|
+
* children to render. Set to `null` to get an array of children back
|
|
284
|
+
* without any wrapper, or use `React.Fragment` to get a React element
|
|
285
|
+
* that won't show up in the DOM.
|
|
286
|
+
*/
|
|
287
|
+
wrapper: React.ElementType | null;
|
|
288
|
+
/**
|
|
289
|
+
* Props to apply to the wrapper element.
|
|
290
|
+
*/
|
|
291
|
+
wrapperProps?: React.JSX.IntrinsicAttributes;
|
|
292
|
+
/**
|
|
293
|
+
* Preserve frontmatter in the output by rendering it as a <pre> element.
|
|
294
|
+
* By default, frontmatter is parsed but not rendered.
|
|
295
|
+
* @default false
|
|
296
|
+
*/
|
|
297
|
+
preserveFrontmatter?: boolean;
|
|
298
|
+
}>;
|
|
299
|
+
}
|
|
300
|
+
declare const RuleType2: typeof RuleTypeConst;
|
|
301
|
+
type RuleType2 = RuleTypeValue;
|
|
302
|
+
type RequireAtLeastOne<
|
|
303
|
+
T,
|
|
304
|
+
Keys extends keyof T = keyof T
|
|
305
|
+
> = MarkdownToJSX.RequireAtLeastOne<T, Keys>;
|
|
306
|
+
declare global {
|
|
307
|
+
var parseMetrics: {
|
|
308
|
+
blockParsers: {
|
|
309
|
+
[key: string]: {
|
|
310
|
+
attempts: number;
|
|
311
|
+
hits: number;
|
|
312
|
+
hitTimings: number[];
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
inlineParsers: {
|
|
316
|
+
[key: string]: {
|
|
317
|
+
attempts: number;
|
|
318
|
+
hits: number;
|
|
319
|
+
hitTimings: number[];
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
totalOperations: number;
|
|
323
|
+
blockParseIterations: number;
|
|
324
|
+
inlineParseIterations: number;
|
|
325
|
+
} | null;
|
|
326
|
+
var parseMetricsStartTimes: Map<string, number> | null;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Given a markdown string, return an abstract syntax tree (AST) of the markdown.
|
|
330
|
+
*
|
|
331
|
+
* The first node in the AST is a reference collection node. This node contains all the
|
|
332
|
+
* reference definitions found in the markdown. These reference definitions are used to
|
|
333
|
+
* resolve reference links and images in the markdown.
|
|
334
|
+
*
|
|
335
|
+
* @param source - The markdown string to parse.
|
|
336
|
+
* @param options - The options for the parser.
|
|
337
|
+
* @returns The AST of the markdown.
|
|
338
|
+
*/
|
|
339
|
+
declare function parser(source: string, options?: MarkdownToJSX.Options): MarkdownToJSX.ASTNode[];
|
|
340
|
+
declare function sanitizer(input: string): string | null;
|
|
341
|
+
declare function slugify(str: string): string;
|
|
342
|
+
type VueChild = VNode | string;
|
|
343
|
+
/**
|
|
344
|
+
* Convert HTML attributes to Vue props
|
|
345
|
+
* Vue uses HTML standard attributes (class, not className), so minimal mapping needed
|
|
346
|
+
* Only 'for' -> 'htmlFor' needs mapping
|
|
347
|
+
*/
|
|
348
|
+
declare function htmlAttrsToVueProps(attrs: Record<string, any>): Record<string, any>;
|
|
349
|
+
type VueOverride = RequireAtLeastOne<{
|
|
350
|
+
component: string | Component;
|
|
351
|
+
props: Record<string, unknown>;
|
|
352
|
+
}> | string | Component;
|
|
353
|
+
type VueOverrides = {
|
|
354
|
+
[tag: string]: VueOverride;
|
|
355
|
+
};
|
|
356
|
+
type VueOptions = Omit<MarkdownToJSX.Options, "createElement" | "wrapperProps" | "renderRule" | "overrides"> & {
|
|
357
|
+
createElement?: typeof h;
|
|
358
|
+
wrapperProps?: Record<string, unknown>;
|
|
359
|
+
renderRule?: (next: () => VueChild | null, node: MarkdownToJSX.ASTNode, renderChildren: (children: MarkdownToJSX.ASTNode[]) => VueChild[] | VNode, state: MarkdownToJSX.State) => VueChild | null;
|
|
360
|
+
overrides?: VueOverrides;
|
|
361
|
+
};
|
|
362
|
+
declare function astToJSX(ast: MarkdownToJSX.ASTNode[], options?: VueOptions): VNode | VNode[] | null;
|
|
363
|
+
declare function compiler(markdown?: string, options?: VueOptions): VNode | VNode[] | null;
|
|
364
|
+
/**
|
|
365
|
+
* A Vue component for easy markdown rendering. Feed the markdown content as a direct child
|
|
366
|
+
* and the rest is taken care of automatically.
|
|
367
|
+
*/
|
|
368
|
+
declare const Markdown: Component<{
|
|
369
|
+
children?: string | null;
|
|
370
|
+
options?: VueOptions;
|
|
371
|
+
[key: string]: unknown;
|
|
372
|
+
}>;
|
|
373
|
+
export { slugify, sanitizer, parser, htmlAttrsToVueProps, Markdown as default, compiler, astToJSX, VueOverrides, VueOverride, VueOptions, RuleType2 as RuleType, MarkdownToJSX, Markdown };
|