markdown-to-jsx 9.0.0 → 9.1.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.cts CHANGED
@@ -41,9 +41,9 @@ type RequireAtLeastOne<
41
41
  T,
42
42
  Keys extends keyof T = keyof T
43
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 = {
44
+ export type CreateElement = typeof React.createElement;
45
+ export type HTMLTags = keyof React.JSX.IntrinsicElements & (string & {});
46
+ export type State = {
47
47
  /** true if the current content is inside anchor link grammar */
48
48
  inAnchor?: boolean;
49
49
  /** true if inside a blockquote */
@@ -66,82 +66,82 @@ type RequireAtLeastOne<
66
66
  /** current recursion depth during rendering */
67
67
  renderDepth?: number;
68
68
  };
69
- interface BlockQuoteNode {
69
+ export interface BlockQuoteNode {
70
70
  alert?: string;
71
71
  children: MarkdownToJSX.ASTNode[];
72
72
  type: typeof RuleType2.blockQuote;
73
73
  }
74
- interface BreakLineNode {
74
+ export interface BreakLineNode {
75
75
  type: typeof RuleType2.breakLine;
76
76
  }
77
- interface BreakThematicNode {
77
+ export interface BreakThematicNode {
78
78
  type: typeof RuleType2.breakThematic;
79
79
  }
80
- interface CodeBlockNode {
80
+ export interface CodeBlockNode {
81
81
  type: typeof RuleType2.codeBlock;
82
82
  attrs?: React.JSX.IntrinsicAttributes;
83
83
  lang?: string;
84
84
  text: string;
85
85
  }
86
- interface CodeInlineNode {
86
+ export interface CodeInlineNode {
87
87
  type: typeof RuleType2.codeInline;
88
88
  text: string;
89
89
  }
90
- interface FootnoteNode {
90
+ export interface FootnoteNode {
91
91
  type: typeof RuleType2.footnote;
92
92
  }
93
- interface FootnoteReferenceNode {
93
+ export interface FootnoteReferenceNode {
94
94
  type: typeof RuleType2.footnoteReference;
95
95
  target: string;
96
96
  text: string;
97
97
  }
98
- interface FrontmatterNode {
98
+ export interface FrontmatterNode {
99
99
  type: typeof RuleType2.frontmatter;
100
100
  text: string;
101
101
  }
102
- interface GFMTaskNode {
102
+ export interface GFMTaskNode {
103
103
  type: typeof RuleType2.gfmTask;
104
104
  completed: boolean;
105
105
  }
106
- interface HeadingNode {
106
+ export interface HeadingNode {
107
107
  type: typeof RuleType2.heading;
108
108
  children: MarkdownToJSX.ASTNode[];
109
109
  id: string;
110
110
  level: 1 | 2 | 3 | 4 | 5 | 6;
111
111
  }
112
- interface HTMLCommentNode {
112
+ export interface HTMLCommentNode {
113
113
  type: typeof RuleType2.htmlComment;
114
114
  text: string;
115
115
  }
116
- interface ImageNode {
116
+ export interface ImageNode {
117
117
  type: typeof RuleType2.image;
118
118
  alt?: string;
119
119
  target: string;
120
120
  title?: string;
121
121
  }
122
- interface LinkNode {
122
+ export interface LinkNode {
123
123
  type: typeof RuleType2.link;
124
124
  children: MarkdownToJSX.ASTNode[];
125
125
  target: string | null;
126
126
  title?: string;
127
127
  }
128
- interface OrderedListNode {
128
+ export interface OrderedListNode {
129
129
  type: typeof RuleType2.orderedList;
130
130
  items: MarkdownToJSX.ASTNode[][];
131
131
  start?: number;
132
132
  }
133
- interface UnorderedListNode {
133
+ export interface UnorderedListNode {
134
134
  type: typeof RuleType2.unorderedList;
135
135
  items: MarkdownToJSX.ASTNode[][];
136
136
  }
137
- interface ParagraphNode {
137
+ export interface ParagraphNode {
138
138
  type: typeof RuleType2.paragraph;
139
139
  children: MarkdownToJSX.ASTNode[];
140
140
  }
141
- interface ReferenceNode {
141
+ export interface ReferenceNode {
142
142
  type: typeof RuleType2.ref;
143
143
  }
144
- interface ReferenceCollectionNode {
144
+ export interface ReferenceCollectionNode {
145
145
  type: typeof RuleType2.refCollection;
146
146
  refs: {
147
147
  [key: string]: {
@@ -150,7 +150,7 @@ type RequireAtLeastOne<
150
150
  };
151
151
  };
152
152
  }
153
- interface TableNode {
153
+ export interface TableNode {
154
154
  type: typeof RuleType2.table;
155
155
  /**
156
156
  * alignment for each table column
@@ -159,11 +159,11 @@ type RequireAtLeastOne<
159
159
  cells: MarkdownToJSX.ASTNode[][][];
160
160
  header: MarkdownToJSX.ASTNode[][];
161
161
  }
162
- interface TextNode {
162
+ export interface TextNode {
163
163
  type: typeof RuleType2.text;
164
164
  text: string;
165
165
  }
166
- interface FormattedTextNode {
166
+ export interface FormattedTextNode {
167
167
  type: typeof RuleType2.textFormatted;
168
168
  /**
169
169
  * the corresponding html tag
@@ -171,7 +171,7 @@ type RequireAtLeastOne<
171
171
  tag: string;
172
172
  children: MarkdownToJSX.ASTNode[];
173
173
  }
174
- interface HTMLNode {
174
+ export interface HTMLNode {
175
175
  type: typeof RuleType2.htmlBlock;
176
176
  attrs?: Record<string, any>;
177
177
  children?: ASTNode[] | undefined;
@@ -179,22 +179,22 @@ type RequireAtLeastOne<
179
179
  tag: string;
180
180
  text?: string | undefined;
181
181
  }
182
- interface HTMLSelfClosingNode {
182
+ export interface HTMLSelfClosingNode {
183
183
  type: typeof RuleType2.htmlSelfClosing;
184
184
  attrs?: Record<string, any>;
185
185
  isClosingTag?: boolean;
186
186
  tag: string;
187
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<{
188
+ 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;
189
+ export type ASTRender = (ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], state: MarkdownToJSX.State) => React.ReactNode;
190
+ export type Override = RequireAtLeastOne<{
191
191
  component: React.ElementType;
192
192
  props: Object;
193
193
  }> | React.ElementType;
194
- type Overrides = { [tag in HTMLTags]? : Override } & {
194
+ export type Overrides = { [tag in HTMLTags]? : Override } & {
195
195
  [customComponent: string]: Override;
196
196
  };
197
- type Options = Partial<{
197
+ export type Options = Partial<{
198
198
  /**
199
199
  * Ultimate control over the output of all rendered JSX.
200
200
  */
@@ -269,7 +269,7 @@ type RequireAtLeastOne<
269
269
  renderRule: (next: () => React.ReactNode, node: ASTNode, renderChildren: ASTRender, state: State) => React.ReactNode;
270
270
  /**
271
271
  * Override the built-in sanitizer function for URLs, etc if desired. The built-in version is available as a library
272
- called `sanitizer`.
272
+ export called `sanitizer`.
273
273
  */
274
274
  sanitizer: (value: string, tag: HTMLTags, attribute: string) => string | null;
275
275
  /**
@@ -288,9 +288,13 @@ type RequireAtLeastOne<
288
288
  * Props to apply to the wrapper element.
289
289
  */
290
290
  wrapperProps?: React.JSX.IntrinsicAttributes;
291
+ /**
292
+ * Preserve frontmatter in the output by rendering it as a <pre> element.
293
+ * By default, frontmatter is parsed but not rendered.
294
+ * @default false
295
+ */
296
+ preserveFrontmatter?: boolean;
291
297
  }>;
292
- {}
293
- ;
294
298
  }
295
299
  declare const RuleType2: typeof RuleTypeConst;
296
300
  type RuleType2 = RuleTypeValue;
package/dist/index.d.ts CHANGED
@@ -41,9 +41,9 @@ type RequireAtLeastOne<
41
41
  T,
42
42
  Keys extends keyof T = keyof T
43
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 = {
44
+ export type CreateElement = typeof React.createElement;
45
+ export type HTMLTags = keyof React.JSX.IntrinsicElements & (string & {});
46
+ export type State = {
47
47
  /** true if the current content is inside anchor link grammar */
48
48
  inAnchor?: boolean;
49
49
  /** true if inside a blockquote */
@@ -66,82 +66,82 @@ type RequireAtLeastOne<
66
66
  /** current recursion depth during rendering */
67
67
  renderDepth?: number;
68
68
  };
69
- interface BlockQuoteNode {
69
+ export interface BlockQuoteNode {
70
70
  alert?: string;
71
71
  children: MarkdownToJSX.ASTNode[];
72
72
  type: typeof RuleType2.blockQuote;
73
73
  }
74
- interface BreakLineNode {
74
+ export interface BreakLineNode {
75
75
  type: typeof RuleType2.breakLine;
76
76
  }
77
- interface BreakThematicNode {
77
+ export interface BreakThematicNode {
78
78
  type: typeof RuleType2.breakThematic;
79
79
  }
80
- interface CodeBlockNode {
80
+ export interface CodeBlockNode {
81
81
  type: typeof RuleType2.codeBlock;
82
82
  attrs?: React.JSX.IntrinsicAttributes;
83
83
  lang?: string;
84
84
  text: string;
85
85
  }
86
- interface CodeInlineNode {
86
+ export interface CodeInlineNode {
87
87
  type: typeof RuleType2.codeInline;
88
88
  text: string;
89
89
  }
90
- interface FootnoteNode {
90
+ export interface FootnoteNode {
91
91
  type: typeof RuleType2.footnote;
92
92
  }
93
- interface FootnoteReferenceNode {
93
+ export interface FootnoteReferenceNode {
94
94
  type: typeof RuleType2.footnoteReference;
95
95
  target: string;
96
96
  text: string;
97
97
  }
98
- interface FrontmatterNode {
98
+ export interface FrontmatterNode {
99
99
  type: typeof RuleType2.frontmatter;
100
100
  text: string;
101
101
  }
102
- interface GFMTaskNode {
102
+ export interface GFMTaskNode {
103
103
  type: typeof RuleType2.gfmTask;
104
104
  completed: boolean;
105
105
  }
106
- interface HeadingNode {
106
+ export interface HeadingNode {
107
107
  type: typeof RuleType2.heading;
108
108
  children: MarkdownToJSX.ASTNode[];
109
109
  id: string;
110
110
  level: 1 | 2 | 3 | 4 | 5 | 6;
111
111
  }
112
- interface HTMLCommentNode {
112
+ export interface HTMLCommentNode {
113
113
  type: typeof RuleType2.htmlComment;
114
114
  text: string;
115
115
  }
116
- interface ImageNode {
116
+ export interface ImageNode {
117
117
  type: typeof RuleType2.image;
118
118
  alt?: string;
119
119
  target: string;
120
120
  title?: string;
121
121
  }
122
- interface LinkNode {
122
+ export interface LinkNode {
123
123
  type: typeof RuleType2.link;
124
124
  children: MarkdownToJSX.ASTNode[];
125
125
  target: string | null;
126
126
  title?: string;
127
127
  }
128
- interface OrderedListNode {
128
+ export interface OrderedListNode {
129
129
  type: typeof RuleType2.orderedList;
130
130
  items: MarkdownToJSX.ASTNode[][];
131
131
  start?: number;
132
132
  }
133
- interface UnorderedListNode {
133
+ export interface UnorderedListNode {
134
134
  type: typeof RuleType2.unorderedList;
135
135
  items: MarkdownToJSX.ASTNode[][];
136
136
  }
137
- interface ParagraphNode {
137
+ export interface ParagraphNode {
138
138
  type: typeof RuleType2.paragraph;
139
139
  children: MarkdownToJSX.ASTNode[];
140
140
  }
141
- interface ReferenceNode {
141
+ export interface ReferenceNode {
142
142
  type: typeof RuleType2.ref;
143
143
  }
144
- interface ReferenceCollectionNode {
144
+ export interface ReferenceCollectionNode {
145
145
  type: typeof RuleType2.refCollection;
146
146
  refs: {
147
147
  [key: string]: {
@@ -150,7 +150,7 @@ type RequireAtLeastOne<
150
150
  };
151
151
  };
152
152
  }
153
- interface TableNode {
153
+ export interface TableNode {
154
154
  type: typeof RuleType2.table;
155
155
  /**
156
156
  * alignment for each table column
@@ -159,11 +159,11 @@ type RequireAtLeastOne<
159
159
  cells: MarkdownToJSX.ASTNode[][][];
160
160
  header: MarkdownToJSX.ASTNode[][];
161
161
  }
162
- interface TextNode {
162
+ export interface TextNode {
163
163
  type: typeof RuleType2.text;
164
164
  text: string;
165
165
  }
166
- interface FormattedTextNode {
166
+ export interface FormattedTextNode {
167
167
  type: typeof RuleType2.textFormatted;
168
168
  /**
169
169
  * the corresponding html tag
@@ -171,7 +171,7 @@ type RequireAtLeastOne<
171
171
  tag: string;
172
172
  children: MarkdownToJSX.ASTNode[];
173
173
  }
174
- interface HTMLNode {
174
+ export interface HTMLNode {
175
175
  type: typeof RuleType2.htmlBlock;
176
176
  attrs?: Record<string, any>;
177
177
  children?: ASTNode[] | undefined;
@@ -179,22 +179,22 @@ type RequireAtLeastOne<
179
179
  tag: string;
180
180
  text?: string | undefined;
181
181
  }
182
- interface HTMLSelfClosingNode {
182
+ export interface HTMLSelfClosingNode {
183
183
  type: typeof RuleType2.htmlSelfClosing;
184
184
  attrs?: Record<string, any>;
185
185
  isClosingTag?: boolean;
186
186
  tag: string;
187
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<{
188
+ 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;
189
+ export type ASTRender = (ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], state: MarkdownToJSX.State) => React.ReactNode;
190
+ export type Override = RequireAtLeastOne<{
191
191
  component: React.ElementType;
192
192
  props: Object;
193
193
  }> | React.ElementType;
194
- type Overrides = { [tag in HTMLTags]? : Override } & {
194
+ export type Overrides = { [tag in HTMLTags]? : Override } & {
195
195
  [customComponent: string]: Override;
196
196
  };
197
- type Options = Partial<{
197
+ export type Options = Partial<{
198
198
  /**
199
199
  * Ultimate control over the output of all rendered JSX.
200
200
  */
@@ -269,7 +269,7 @@ type RequireAtLeastOne<
269
269
  renderRule: (next: () => React.ReactNode, node: ASTNode, renderChildren: ASTRender, state: State) => React.ReactNode;
270
270
  /**
271
271
  * Override the built-in sanitizer function for URLs, etc if desired. The built-in version is available as a library
272
- called `sanitizer`.
272
+ export called `sanitizer`.
273
273
  */
274
274
  sanitizer: (value: string, tag: HTMLTags, attribute: string) => string | null;
275
275
  /**
@@ -288,9 +288,13 @@ type RequireAtLeastOne<
288
288
  * Props to apply to the wrapper element.
289
289
  */
290
290
  wrapperProps?: React.JSX.IntrinsicAttributes;
291
+ /**
292
+ * Preserve frontmatter in the output by rendering it as a <pre> element.
293
+ * By default, frontmatter is parsed but not rendered.
294
+ * @default false
295
+ */
296
+ preserveFrontmatter?: boolean;
291
297
  }>;
292
- {}
293
- ;
294
298
  }
295
299
  declare const RuleType2: typeof RuleTypeConst;
296
300
  type RuleType2 = RuleTypeValue;