markdown-to-jsx 7.7.16 → 8.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/README.md +56 -1
- package/dist/debug.module.js +1754 -1
- package/dist/debug.module.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +40 -50
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/match.d.ts +42 -0
- package/package.json +12 -11
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,7 @@
|
|
|
6
6
|
* optimizations here wouldn't be feasible. 🙏🏼
|
|
7
7
|
*/
|
|
8
8
|
import * as React from 'react';
|
|
9
|
-
|
|
10
|
-
* Analogous to `node.type`. Please note that the values here may change at any time,
|
|
11
|
-
* so do not hard code against the value directly.
|
|
12
|
-
*/
|
|
9
|
+
import { type RuleType as RuleTypeValue } from './match';
|
|
13
10
|
export declare const RuleType: {
|
|
14
11
|
readonly blockQuote: "0";
|
|
15
12
|
readonly breakLine: "1";
|
|
@@ -22,20 +19,13 @@ export declare const RuleType: {
|
|
|
22
19
|
readonly gfmTask: "8";
|
|
23
20
|
readonly heading: "9";
|
|
24
21
|
readonly headingSetext: "10";
|
|
25
|
-
/** only available if not `disableHTMLParsing` */
|
|
26
22
|
readonly htmlBlock: "11";
|
|
27
23
|
readonly htmlComment: "12";
|
|
28
|
-
/** only available if not `disableHTMLParsing` */
|
|
29
24
|
readonly htmlSelfClosing: "13";
|
|
30
25
|
readonly image: "14";
|
|
31
26
|
readonly link: "15";
|
|
32
|
-
/** emits a `link` 'node', does not render directly */
|
|
33
27
|
readonly linkAngleBraceStyleDetector: "16";
|
|
34
|
-
/** emits a `link` 'node', does not render directly */
|
|
35
28
|
readonly linkBareUrlDetector: "17";
|
|
36
|
-
/** @deprecated merged into linkAngleBraceStyleDetector
|
|
37
|
-
*
|
|
38
|
-
* emits a `link` 'node', does not render directly */
|
|
39
29
|
readonly linkMailtoDetector: "18";
|
|
40
30
|
readonly newlineCoalescer: "19";
|
|
41
31
|
readonly orderedList: "20";
|
|
@@ -46,14 +36,11 @@ export declare const RuleType: {
|
|
|
46
36
|
readonly table: "25";
|
|
47
37
|
readonly tableSeparator: "26";
|
|
48
38
|
readonly text: "27";
|
|
49
|
-
readonly
|
|
50
|
-
readonly
|
|
51
|
-
readonly
|
|
52
|
-
readonly textMarked: "31";
|
|
53
|
-
readonly textStrikethroughed: "32";
|
|
54
|
-
readonly unorderedList: "33";
|
|
39
|
+
readonly textEscaped: "28";
|
|
40
|
+
readonly textFormatted: "34";
|
|
41
|
+
readonly unorderedList: "30";
|
|
55
42
|
};
|
|
56
|
-
export type RuleType =
|
|
43
|
+
export type RuleType = RuleTypeValue;
|
|
57
44
|
declare const Priority: {
|
|
58
45
|
/**
|
|
59
46
|
* anything that must scan the tree before everything else
|
|
@@ -87,7 +74,7 @@ export declare function compiler(markdown: string, options?: MarkdownToJSX.Optio
|
|
|
87
74
|
* and the rest is taken care of automatically.
|
|
88
75
|
*/
|
|
89
76
|
declare const Markdown: React.FC<Omit<React.HTMLAttributes<Element>, 'children'> & {
|
|
90
|
-
children
|
|
77
|
+
children?: string | null;
|
|
91
78
|
options?: MarkdownToJSX.Options;
|
|
92
79
|
}>;
|
|
93
80
|
export declare namespace MarkdownToJSX {
|
|
@@ -116,10 +103,12 @@ export declare namespace MarkdownToJSX {
|
|
|
116
103
|
prevCapture?: string;
|
|
117
104
|
/** true if parsing in inline context w/o links */
|
|
118
105
|
simple?: boolean;
|
|
106
|
+
/** current recursion depth during rendering */
|
|
107
|
+
renderDepth?: number;
|
|
119
108
|
};
|
|
120
109
|
export interface BlockQuoteNode {
|
|
121
110
|
alert?: string;
|
|
122
|
-
children: MarkdownToJSX.
|
|
111
|
+
children: MarkdownToJSX.ASTNode[];
|
|
123
112
|
type: typeof RuleType.blockQuote;
|
|
124
113
|
}
|
|
125
114
|
export interface BreakLineNode {
|
|
@@ -155,7 +144,7 @@ export declare namespace MarkdownToJSX {
|
|
|
155
144
|
}
|
|
156
145
|
export interface HeadingNode {
|
|
157
146
|
type: typeof RuleType.heading;
|
|
158
|
-
children: MarkdownToJSX.
|
|
147
|
+
children: MarkdownToJSX.ASTNode[];
|
|
159
148
|
id: string;
|
|
160
149
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
161
150
|
}
|
|
@@ -173,7 +162,7 @@ export declare namespace MarkdownToJSX {
|
|
|
173
162
|
}
|
|
174
163
|
export interface LinkNode {
|
|
175
164
|
type: typeof RuleType.link;
|
|
176
|
-
children: MarkdownToJSX.
|
|
165
|
+
children: MarkdownToJSX.ASTNode[];
|
|
177
166
|
target: string;
|
|
178
167
|
title?: string;
|
|
179
168
|
}
|
|
@@ -188,13 +177,13 @@ export declare namespace MarkdownToJSX {
|
|
|
188
177
|
}
|
|
189
178
|
export interface OrderedListNode {
|
|
190
179
|
type: typeof RuleType.orderedList;
|
|
191
|
-
items: MarkdownToJSX.
|
|
180
|
+
items: MarkdownToJSX.ASTNode[][];
|
|
192
181
|
ordered: true;
|
|
193
182
|
start?: number;
|
|
194
183
|
}
|
|
195
184
|
export interface UnorderedListNode {
|
|
196
185
|
type: typeof RuleType.unorderedList;
|
|
197
|
-
items: MarkdownToJSX.
|
|
186
|
+
items: MarkdownToJSX.ASTNode[][];
|
|
198
187
|
ordered: false;
|
|
199
188
|
}
|
|
200
189
|
export interface NewlineNode {
|
|
@@ -202,7 +191,7 @@ export declare namespace MarkdownToJSX {
|
|
|
202
191
|
}
|
|
203
192
|
export interface ParagraphNode {
|
|
204
193
|
type: typeof RuleType.paragraph;
|
|
205
|
-
children: MarkdownToJSX.
|
|
194
|
+
children: MarkdownToJSX.ASTNode[];
|
|
206
195
|
}
|
|
207
196
|
export interface ReferenceNode {
|
|
208
197
|
type: typeof RuleType.ref;
|
|
@@ -214,7 +203,7 @@ export declare namespace MarkdownToJSX {
|
|
|
214
203
|
}
|
|
215
204
|
export interface ReferenceLinkNode {
|
|
216
205
|
type: typeof RuleType.refLink;
|
|
217
|
-
children: MarkdownToJSX.
|
|
206
|
+
children: MarkdownToJSX.ASTNode[];
|
|
218
207
|
fallbackChildren: string;
|
|
219
208
|
ref: string;
|
|
220
209
|
}
|
|
@@ -224,8 +213,8 @@ export declare namespace MarkdownToJSX {
|
|
|
224
213
|
* alignment for each table column
|
|
225
214
|
*/
|
|
226
215
|
align: ('left' | 'right' | 'center')[];
|
|
227
|
-
cells: MarkdownToJSX.
|
|
228
|
-
header: MarkdownToJSX.
|
|
216
|
+
cells: MarkdownToJSX.ASTNode[][][];
|
|
217
|
+
header: MarkdownToJSX.ASTNode[][];
|
|
229
218
|
}
|
|
230
219
|
export interface TableSeparatorNode {
|
|
231
220
|
type: typeof RuleType.tableSeparator;
|
|
@@ -234,25 +223,17 @@ export declare namespace MarkdownToJSX {
|
|
|
234
223
|
type: typeof RuleType.text;
|
|
235
224
|
text: string;
|
|
236
225
|
}
|
|
237
|
-
export interface
|
|
238
|
-
type: typeof RuleType.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
children: MarkdownToJSX.
|
|
226
|
+
export interface FormattedTextNode {
|
|
227
|
+
type: typeof RuleType.textFormatted;
|
|
228
|
+
/**
|
|
229
|
+
* the corresponding html tag
|
|
230
|
+
*/
|
|
231
|
+
tag: string;
|
|
232
|
+
children: MarkdownToJSX.ASTNode[];
|
|
244
233
|
}
|
|
245
234
|
export interface EscapedTextNode {
|
|
246
235
|
type: typeof RuleType.textEscaped;
|
|
247
236
|
}
|
|
248
|
-
export interface MarkedTextNode {
|
|
249
|
-
type: typeof RuleType.textMarked;
|
|
250
|
-
children: MarkdownToJSX.ParserResult[];
|
|
251
|
-
}
|
|
252
|
-
export interface StrikethroughTextNode {
|
|
253
|
-
type: typeof RuleType.textStrikethroughed;
|
|
254
|
-
children: MarkdownToJSX.ParserResult[];
|
|
255
|
-
}
|
|
256
237
|
export interface HTMLNode {
|
|
257
238
|
type: typeof RuleType.htmlBlock;
|
|
258
239
|
attrs: React.JSX.IntrinsicAttributes;
|
|
@@ -266,11 +247,11 @@ export declare namespace MarkdownToJSX {
|
|
|
266
247
|
attrs: React.JSX.IntrinsicAttributes;
|
|
267
248
|
tag: string;
|
|
268
249
|
}
|
|
269
|
-
export type
|
|
270
|
-
export type NestedParser = (input: string, state?: MarkdownToJSX.State) => MarkdownToJSX.
|
|
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[];
|
|
271
252
|
export type Parser<ParserOutput> = (capture: RegExpMatchArray, nestedParse: NestedParser, state?: MarkdownToJSX.State) => ParserOutput;
|
|
272
|
-
export type RuleOutput = (ast: MarkdownToJSX.
|
|
273
|
-
export type Rule<ParserOutput = MarkdownToJSX.
|
|
253
|
+
export type RuleOutput = (ast: MarkdownToJSX.ASTNode | MarkdownToJSX.ASTNode[], state: MarkdownToJSX.State) => React.ReactNode;
|
|
254
|
+
export type Rule<ParserOutput = MarkdownToJSX.ASTNode> = {
|
|
274
255
|
_match: (source: string, state: MarkdownToJSX.State, prevCapturedString?: string) => RegExpMatchArray;
|
|
275
256
|
_order: (typeof Priority)[keyof typeof Priority];
|
|
276
257
|
_parse: MarkdownToJSX.Parser<Omit<ParserOutput, 'type'>>;
|
|
@@ -291,9 +272,9 @@ export declare namespace MarkdownToJSX {
|
|
|
291
272
|
render: RuleOutput, state?: MarkdownToJSX.State) => React.ReactNode;
|
|
292
273
|
};
|
|
293
274
|
export type Rules = {
|
|
294
|
-
[K in
|
|
275
|
+
[K in ASTNode['type']]: K extends typeof RuleType.table ? Rule<Extract<ASTNode, {
|
|
295
276
|
type: K | typeof RuleType.paragraph;
|
|
296
|
-
}>> : Rule<Extract<
|
|
277
|
+
}>> : Rule<Extract<ASTNode, {
|
|
297
278
|
type: K;
|
|
298
279
|
}>>;
|
|
299
280
|
};
|
|
@@ -307,6 +288,11 @@ export declare namespace MarkdownToJSX {
|
|
|
307
288
|
[customComponent: string]: Override;
|
|
308
289
|
};
|
|
309
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;
|
|
310
296
|
/**
|
|
311
297
|
* Ultimate control over the output of all rendered JSX.
|
|
312
298
|
*/
|
|
@@ -395,7 +381,7 @@ export declare namespace MarkdownToJSX {
|
|
|
395
381
|
/** Resume normal processing, call this function as a fallback if you are not returning custom JSX. */
|
|
396
382
|
next: () => React.ReactNode,
|
|
397
383
|
/** the current AST node, use `RuleType` against `node.type` for identification */
|
|
398
|
-
node:
|
|
384
|
+
node: ASTNode,
|
|
399
385
|
/** use as `renderChildren(node.children)` for block nodes */
|
|
400
386
|
renderChildren: RuleOutput,
|
|
401
387
|
/** contains `key` which should be supplied to the topmost JSX element */
|
|
@@ -416,6 +402,10 @@ export declare namespace MarkdownToJSX {
|
|
|
416
402
|
* that won't show up in the DOM.
|
|
417
403
|
*/
|
|
418
404
|
wrapper: React.ElementType | null;
|
|
405
|
+
/**
|
|
406
|
+
* Props to apply to the wrapper element.
|
|
407
|
+
*/
|
|
408
|
+
wrapperProps?: React.JSX.IntrinsicAttributes;
|
|
419
409
|
}>;
|
|
420
410
|
export {};
|
|
421
411
|
}
|
package/dist/index.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as e from"react";function n(){return n=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},n.apply(this,arguments)}const r=["children","options"],t={blockQuote:"0",breakLine:"1",breakThematic:"2",codeBlock:"3",codeFenced:"4",codeInline:"5",footnote:"6",footnoteReference:"7",gfmTask:"8",heading:"9",headingSetext:"10",htmlBlock:"11",htmlComment:"12",htmlSelfClosing:"13",image:"14",link:"15",linkAngleBraceStyleDetector:"16",linkBareUrlDetector:"17",linkMailtoDetector:"18",newlineCoalescer:"19",orderedList:"20",paragraph:"21",ref:"22",refImage:"23",refLink:"24",table:"25",tableSeparator:"26",text:"27",textBolded:"28",textEmphasized:"29",textEscaped:"30",textMarked:"31",textStrikethroughed:"32",unorderedList:"33"},o=["allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","cellPadding","cellSpacing","charSet","classId","colSpan","contentEditable","contextMenu","crossOrigin","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hrefLang","inputMode","keyParams","keyType","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","radioGroup","readOnly","rowSpan","spellCheck","srcDoc","srcLang","srcSet","tabIndex","useMap"].reduce((e,n)=>(e[n.toLowerCase()]=n,e),{class:"className",for:"htmlFor"}),a={amp:"&",apos:"'",gt:">",lt:"<",nbsp:" ",quot:"“"},c=["style","script","pre"],i=["src","href","data","formAction","srcDoc","action"],u=/([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi,l=/\n{2,}$/,s=/^(\s*>[\s\S]*?)(?=\n\n|$)/,f=/^ *> ?/gm,_=/^(?:\[!([^\]]*)\]\n)?([\s\S]*)/,d=/^ {2,}\n/,p=/^(?:([-*_])( *\1){2,}) *(?:\n *)+\n/,y=/^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/,h=/^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/,g=/^(`+)((?:\\`|(?!\1)`|[^`])+)\1/,m=/^(?:\n *)*\n/,k=/\r\n?/g,x=/^\[\^([^\]]+)](:(.*)((\n+ {4,}.*)|(\n(?!\[\^).+))*)/,q=/^\[\^([^\]]+)]/,v=/\f/g,b=/^---[ \t]*\n(.|\n)*\n---[ \t]*\n/,$=/^\s*?\[(x|\s)\]/,S=/^ *(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,z=/^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,E=/^([^\n]+)\n *(=|-)\2{2,} *\n/,A=/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/i,R=/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi,B=/^<!--[\s\S]*?(?:-->)/,L=/^(data|aria|x)-[a-z_][a-z\d_.-]*$/,O=/^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i,j=/^\{.*\}$/,C=/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,I=/^<([^ >]+[:@\/][^ >]+)>/,T=/-([a-z])?/gi,M=/^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/,w=/^[^\n]+(?: \n|\n{2,})/,D=/^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/,F=/^!\[([^\]]*)\] ?\[([^\]]*)\]/,P=/^\[([^\]]*)\] ?\[([^\]]*)\]/,Z=/(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/,N=/\t/g,G=/(^ *\||\| *$)/g,U=/^ *:-+: *$/,V=/^ *:-+ *$/,H=/^ *-+: *$/,Q=e=>`(?=[\\s\\S]+?\\1${e?"\\1":""})`,W="((?:\\[.*?\\][([].*?[)\\]]|<.*?>(?:.*?<.*?>)?|`.*?`|\\\\\\1|[\\s\\S])+?)",J=RegExp(`^([*_])\\1${Q(1)}${W}\\1\\1(?!\\1)`),K=RegExp(`^([*_])${Q(0)}${W}\\1(?!\\1)`),X=RegExp(`^(==)${Q(0)}${W}\\1`),Y=RegExp(`^(~~)${Q(0)}${W}\\1`),ee=/^(:[a-zA-Z0-9-_]+:)/,ne=/^\\([^0-9A-Za-z\s])/,re=/\\([^0-9A-Za-z\s])/g,te=/^[\s\S](?:(?! \n|[0-9]\.|http)[^=*_~\-\n:<`\\\[!])*/,oe=/^\n+/,ae=/^([ \t]*)/,ce=/(?:^|\n)( *)$/,ie="(?:\\d+\\.)",ue="(?:[*+-])";function le(e){return"( *)("+(1===e?ie:ue)+") +"}const se=le(1),fe=le(2);function _e(e){return RegExp("^"+(1===e?se:fe))}const de=_e(1),pe=_e(2);function ye(e){return RegExp("^"+(1===e?se:fe)+"[^\\n]*(?:\\n(?!\\1"+(1===e?ie:ue)+" )[^\\n]*)*(\\n|$)","gm")}const he=ye(1),ge=ye(2);function me(e){const n=1===e?ie:ue;return RegExp("^( *)("+n+") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1"+n+" (?!"+n+" ))\\n*|\\s*\\n*$)")}const ke=me(1),xe=me(2);function qe(e,n){const r=1===n,t=r?ke:xe,o=r?he:ge,a=r?de:pe;return{t:e=>a.test(e),o:je(function(e,n){const r=ce.exec(n.prevCapture);return r&&(n.list||!n.inline&&!n.simple)?t.exec(e=r[1]+e):null}),i:1,u(e,n,t){const c=r?+e[2]:void 0,i=e[0].replace(l,"\n").match(o);let u=!1;return{items:i.map(function(e,r){const o=a.exec(e)[0].length,c=RegExp("^ {1,"+o+"}","gm"),l=e.replace(c,"").replace(a,""),s=r===i.length-1,f=-1!==l.indexOf("\n\n")||s&&u;u=f;const _=t.inline,d=t.list;let p;t.list=!0,f?(t.inline=!1,p=Se(l)+"\n\n"):(t.inline=!0,p=Se(l));const y=n(p,t);return t.inline=_,t.list=d,y}),ordered:r,start:c}},l:(n,r,t)=>e(n.ordered?"ol":"ul",{key:t.key,start:"20"===n.type?n.start:void 0},n.items.map(function(n,o){return e("li",{key:o},r(n,t))}))}}const ve=RegExp("^\\[((?:\\[[^\\[\\]]*(?:\\[[^\\[\\]]*\\][^\\[\\]]*)*\\]|[^\\[\\]])*)\\]\\(\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*\\)"),be=/^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/;function $e(e){return"string"==typeof e}function Se(e){let n=e.length;for(;n>0&&e[n-1]<=" ";)n--;return e.slice(0,n)}function ze(e,n){return e.startsWith(n)}function Ee(e,n,r){if(Array.isArray(r)){for(let n=0;n<r.length;n++)if(ze(e,r[n]))return!0;return!1}return r(e,n)}function Ae(e){return e.replace(/[ÀÁÂÃÄÅàáâãä忯]/g,"a").replace(/[çÇ]/g,"c").replace(/[ðÐ]/g,"d").replace(/[ÈÉÊËéèêë]/g,"e").replace(/[ÏïÎîÍíÌì]/g,"i").replace(/[Ññ]/g,"n").replace(/[øØœŒÕõÔôÓóÒò]/g,"o").replace(/[ÜüÛûÚúÙù]/g,"u").replace(/[ŸÿÝý]/g,"y").replace(/[^a-z0-9- ]/gi,"").replace(/ /gi,"-").toLowerCase()}function Re(e){return H.test(e)?"right":U.test(e)?"center":V.test(e)?"left":null}function Be(e,n,r,t){const o=r.inTable;r.inTable=!0;let a=[[]],c="";function i(){if(!c)return;const e=a[a.length-1];e.push.apply(e,n(c,r)),c=""}return e.trim().split(/(`[^`]*`|\\\||\|)/).filter(Boolean).forEach((e,n,r)=>{"|"===e.trim()&&(i(),t)?0!==n&&n!==r.length-1&&a.push([]):c+=e}),i(),r.inTable=o,a}function Le(e,n,r){r.inline=!0;const t=e[2]?e[2].replace(G,"").split("|").map(Re):[],o=e[3]?function(e,n,r){return e.trim().split("\n").map(function(e){return Be(e,n,r,!0)})}(e[3],n,r):[],a=Be(e[1],n,r,!!o.length);return r.inline=!1,o.length?{align:t,cells:o,header:a,type:"25"}:{children:a,type:"21"}}function Oe(e,n){return null==e.align[n]?{}:{textAlign:e.align[n]}}function je(e){return e.inline=1,e}function Ce(e){return je(function(n,r){return r.inline?e.exec(n):null})}function Ie(e){return je(function(n,r){return r.inline||r.simple?e.exec(n):null})}function Te(e){return function(n,r){return r.inline||r.simple?null:e.exec(n)}}function Me(e){return je(function(n){return e.exec(n)})}const we=/(javascript|vbscript|data(?!:image)):/i;function De(e){try{const n=decodeURIComponent(e).replace(/[^A-Za-z0-9/:]/g,"");if(we.test(n))return null}catch(e){return null}return e}function Fe(e){return e?e.replace(re,"$1"):e}function Pe(e,n,r){const t=r.inline||!1,o=r.simple||!1;r.inline=!0,r.simple=!0;const a=e(n,r);return r.inline=t,r.simple=o,a}function Ze(e,n,r){const t=r.inline||!1,o=r.simple||!1;r.inline=!1,r.simple=!0;const a=e(n,r);return r.inline=t,r.simple=o,a}function Ne(e,n,r){const t=r.inline||!1;r.inline=!1;const o=e(n,r);return r.inline=t,o}const Ge=(e,n,r)=>({children:Pe(n,e[2],r)});function Ue(){return{}}function Ve(){return null}function He(...e){return e.filter(Boolean).join(" ")}function Qe(e,n,r){let t=e;const o=n.split(".");for(;o.length&&(t=t[o[0]],void 0!==t);)o.shift();return t||r}function We(r="",t={}){t.overrides=t.overrides||{},t.namedCodesToUnicode=t.namedCodesToUnicode?n({},a,t.namedCodesToUnicode):a;const l=t.slugify||Ae,G=t.sanitizer||De,U=t.createElement||e.createElement,V=[s,y,h,t.enforceAtxHeadings?z:S,E,M,ke,xe],H=[...V,w,A,B,O];function Q(e,n){for(let r=0;r<e.length;r++)if(e[r].test(n))return!0;return!1}function W(e,r,...o){const a=Qe(t.overrides,e+".props",{});return U(function(e,n){const r=Qe(n,e);return r?"function"==typeof r||"object"==typeof r&&"render"in r?r:Qe(n,e+".component",e):e}(e,t.overrides),n({},r,a,{className:He(null==r?void 0:r.className,a.className)||void 0}),...o)}function re(e){e=e.replace(b,"");let n=!1;t.forceInline?n=!0:t.forceBlock||(n=!1===Z.test(e));const r=fe(se(n?e:Se(e).replace(oe,"")+"\n\n",{inline:n}));for(;$e(r[r.length-1])&&!r[r.length-1].trim();)r.pop();if(null===t.wrapper)return r;const o=t.wrapper||(n?"span":"div");let a;if(r.length>1||t.forceWrapper)a=r;else{if(1===r.length)return a=r[0],"string"==typeof a?W("span",{key:"outer"},a):a;a=null}return U(o,{key:"outer"},a)}function ce(e,n){if(!n||!n.trim())return null;const r=n.match(u);return r?r.reduce(function(n,r){const t=r.indexOf("=");if(-1!==t){const a=function(e){return-1!==e.indexOf("-")&&null===e.match(L)&&(e=e.replace(T,function(e,n){return n.toUpperCase()})),e}(r.slice(0,t)).trim(),c=function(e){const n=e[0];return('"'===n||"'"===n)&&e.length>=2&&e[e.length-1]===n?e.slice(1,-1):e}(r.slice(t+1).trim()),u=o[a]||a;if("ref"===u)return n;const l=n[u]=function(e,n,r,t){return"style"===n?function(e){const n=[];let r="",t=!1,o=!1,a="";if(!e)return n;for(let c=0;c<e.length;c++){const i=e[c];if('"'!==i&&"'"!==i||t||(o?i===a&&(o=!1,a=""):(o=!0,a=i)),"("===i&&r.endsWith("url")?t=!0:")"===i&&t&&(t=!1),";"!==i||o||t)r+=i;else{const e=r.trim();if(e){const r=e.indexOf(":");if(r>0){const t=e.slice(0,r).trim(),o=e.slice(r+1).trim();n.push([t,o])}}r=""}}const c=r.trim();if(c){const e=c.indexOf(":");if(e>0){const r=c.slice(0,e).trim(),t=c.slice(e+1).trim();n.push([r,t])}}return n}(r).reduce(function(n,[r,o]){return n[r.replace(/(-[a-z])/g,e=>e[1].toUpperCase())]=t(o,e,r),n},{}):-1!==i.indexOf(n)?t(Fe(r),e,n):(r.match(j)&&(r=Fe(r.slice(1,r.length-1))),"true"===r||"false"!==r&&r)}(e,a,c,G);"string"==typeof l&&(A.test(l)||O.test(l))&&(n[u]=re(l.trim()))}else"style"!==r&&(n[o[r]||r]=!0);return n},{}):null}const ie=[],ue={},le={0:{t:[">"],o:Te(s),i:1,u(e,n,r){const[,t,o]=e[0].replace(f,"").match(_);return{alert:t,children:n(o,r)}},l(e,n,r){const t={key:r.key};return e.alert&&(t.className="markdown-alert-"+l(e.alert.toLowerCase(),Ae),e.children.unshift({attrs:{},children:[{type:"27",text:e.alert}],noInnerParse:!0,type:"11",tag:"header"})),W("blockquote",t,n(e.children,r))}},1:{t:[" "],o:Me(d),i:1,u:Ue,l:(e,n,r)=>W("br",{key:r.key})},2:{t:["--","__","**","- ","* ","_ "],o:Te(p),i:1,u:Ue,l:(e,n,r)=>W("hr",{key:r.key})},3:{t:[" "],o:Te(h),i:0,u:e=>({lang:void 0,text:Fe(Se(e[0].replace(/^ {4}/gm,"")))}),l:(e,r,t)=>W("pre",{key:t.key},W("code",n({},e.attrs,{className:e.lang?"lang-"+e.lang:""}),e.text))},4:{t:["```","~~~"],o:Te(y),i:0,u:e=>({attrs:ce("code",e[3]||""),lang:e[2]||void 0,text:e[4],type:"3"})},5:{t:["`"],o:Ie(g),i:3,u:e=>({text:Fe(e[2])}),l:(e,n,r)=>W("code",{key:r.key},e.text)},6:{t:["[^"],o:Te(x),i:0,u:e=>(ie.push({footnote:e[2],identifier:e[1]}),{}),l:Ve},7:{t:["[^"],o:Ce(q),i:1,u:e=>({target:"#"+l(e[1],Ae),text:e[1]}),l:(e,n,r)=>W("a",{key:r.key,href:G(e.target,"a","href")},W("sup",{key:r.key},e.text))},8:{t:["[ ]","[x]"],o:Ce($),i:1,u:e=>({completed:"x"===e[1].toLowerCase()}),l:(e,n,r)=>W("input",{checked:e.completed,key:r.key,readOnly:!0,type:"checkbox"})},9:{t:["#"],o:Te(t.enforceAtxHeadings?z:S),i:1,u:(e,n,r)=>({children:Pe(n,e[2],r),id:l(e[2],Ae),level:e[1].length}),l:(e,n,r)=>W("h"+e.level,{id:e.id,key:r.key},n(e.children,r))},10:{t:e=>{const n=e.indexOf("\n");return n>0&&n<e.length-1&&("="===e[n+1]||"-"===e[n+1])},o:Te(E),i:1,u:(e,n,r)=>({children:Pe(n,e[1],r),level:"="===e[2]?1:2,type:"9"})},11:{t:["<"],o:Me(A),i:1,u(e,n,r){const[,t]=e[3].match(ae),o=RegExp("^"+t,"gm"),a=e[3].replace(o,""),i=Q(H,a)?Ne:Pe,u=e[1].toLowerCase(),l=-1!==c.indexOf(u),s=(l?u:e[1]).trim(),f={attrs:ce(s,e[2]),noInnerParse:l,tag:s};if(r.inAnchor=r.inAnchor||"a"===u,l)f.text=e[3];else{const e=r.inHTML;r.inHTML=!0,f.children=i(n,a,r),r.inHTML=e}return r.inAnchor=!1,f},l:(e,r,t)=>W(e.tag,n({key:t.key},e.attrs),e.text||(e.children?r(e.children,t):""))},13:{t:["<"],o:Me(O),i:1,u(e){const n=e[1].trim();return{attrs:ce(n,e[2]||""),tag:n}},l:(e,r,t)=>W(e.tag,n({},e.attrs,{key:t.key}))},12:{t:["\x3c!--"],o:Me(B),i:1,u:()=>({}),l:Ve},14:{t:["!["],o:Ie(be),i:1,u:e=>({alt:Fe(e[1]),target:Fe(e[2]),title:Fe(e[3])}),l:(e,n,r)=>W("img",{key:r.key,alt:e.alt||void 0,title:e.title||void 0,src:G(e.target,"img","src")})},15:{t:["["],o:Ce(ve),i:3,u:(e,n,r)=>({children:Ze(n,e[1],r),target:Fe(e[2]),title:Fe(e[3])}),l:(e,n,r)=>W("a",{key:r.key,href:G(e.target,"a","href"),title:e.title},n(e.children,r))},16:{t:["<"],o:Ce(I),i:0,u(e){let n=e[1],r=!1;return-1!==n.indexOf("@")&&-1===n.indexOf("//")&&(r=!0,n=n.replace("mailto:","")),{children:[{text:n,type:"27"}],target:r?"mailto:"+n:n,type:"15"}}},17:{t:(e,n)=>!n.inAnchor&&!t.disableAutoLink&&(ze(e,"http://")||ze(e,"https://")),o:Ce(C),i:0,u:e=>({children:[{text:e[1],type:"27"}],target:e[1],title:void 0,type:"15"})},20:qe(W,1),33:qe(W,2),19:{t:["\n"],o:Te(m),i:3,u:Ue,l:()=>"\n"},21:{o:je(function(e,n){if(n.inline||n.simple||n.inHTML&&-1===e.indexOf("\n\n")&&-1===n.prevCapture.indexOf("\n\n"))return null;let r="",t=0;for(;;){const n=e.indexOf("\n",t),o=e.slice(t,-1===n?void 0:n+1);if(Q(V,o))break;if(r+=o,-1===n||!o.trim())break;t=n+1}const o=Se(r);return""===o?null:[r,,o]}),i:3,u:Ge,l:(e,n,r)=>W("p",{key:r.key},n(e.children,r))},22:{t:["["],o:Ce(D),i:0,u:e=>(ue[e[1]]={target:e[2],title:e[4]},{}),l:Ve},23:{t:["!["],o:Ie(F),i:0,u:e=>({alt:e[1]?Fe(e[1]):void 0,ref:e[2]}),l:(e,n,r)=>ue[e.ref]?W("img",{key:r.key,alt:e.alt,src:G(ue[e.ref].target,"img","src"),title:ue[e.ref].title}):null},24:{t:e=>"["===e[0]&&-1===e.indexOf("]("),o:Ce(P),i:0,u:(e,n,r)=>({children:n(e[1],r),fallbackChildren:e[0],ref:e[2]}),l:(e,n,r)=>ue[e.ref]?W("a",{key:r.key,href:G(ue[e.ref].target,"a","href"),title:ue[e.ref].title},n(e.children,r)):W("span",{key:r.key},e.fallbackChildren)},25:{t:["|"],o:Te(M),i:1,u:Le,l(e,n,r){const t=e;return W("table",{key:r.key},W("thead",null,W("tr",null,t.header.map(function(e,o){return W("th",{key:o,style:Oe(t,o)},n(e,r))}))),W("tbody",null,t.cells.map(function(e,o){return W("tr",{key:o},e.map(function(e,o){return W("td",{key:o,style:Oe(t,o)},n(e,r))}))})))}},27:{o:je(function(e,n){let r;return ze(e,":")&&(r=ee.exec(e)),r||te.exec(e)}),i:4,u(e){const n=e[0];return{text:-1===n.indexOf("&")?n:n.replace(R,(e,n)=>t.namedCodesToUnicode[n]||e)}},l:e=>e.text},28:{t:["**","__"],o:Ie(J),i:2,u:(e,n,r)=>({children:n(e[2],r)}),l:(e,n,r)=>W("strong",{key:r.key},n(e.children,r))},29:{t:e=>{const n=e[0];return("*"===n||"_"===n)&&e[1]!==n},o:Ie(K),i:3,u:(e,n,r)=>({children:n(e[2],r)}),l:(e,n,r)=>W("em",{key:r.key},n(e.children,r))},30:{t:["\\"],o:Ie(ne),i:1,u:e=>({text:e[1],type:"27"})},31:{t:["=="],o:Ie(X),i:3,u:Ge,l:(e,n,r)=>W("mark",{key:r.key},n(e.children,r))},32:{t:["~~"],o:Ie(Y),i:3,u:Ge,l:(e,n,r)=>W("del",{key:r.key},n(e.children,r))}};!0===t.disableParsingRawHTML&&(delete le[11],delete le[13]);const se=function(e){var n=Object.keys(e);function r(t,o){var a=[];if(o.prevCapture=o.prevCapture||"",t.trim())for(;t;)for(var c=0;c<n.length;){var i=n[c],u=e[i];if(!u.t||Ee(t,o,u.t)){var l=u.o(t,o);if(l&&l[0]){t=t.substring(l[0].length);var s=u.u(l,r,o);o.prevCapture+=l[0],s.type||(s.type=i),a.push(s);break}c++}else c++}return o.prevCapture="",a}return n.sort(function(n,r){return e[n].i-e[r].i||(n<r?-1:1)}),function(e,n){return r(function(e){return e.replace(k,"\n").replace(v,"").replace(N," ")}(e),n)}}(le),fe=function(e,n){return function r(t,o={}){if(Array.isArray(t)){const e=o.key,n=[];let a=!1;for(let e=0;e<t.length;e++){o.key=e;const c=r(t[e],o),i=$e(c);i&&a?n[n.length-1]+=c:null!==c&&n.push(c),a=i}return o.key=e,n}return function(r,t,o){const a=e[r.type].l;return n?n(()=>a(r,t,o),r,t,o):a(r,t,o)}(t,r,o)}}(le,t.renderRule),_e=re(r);return ie.length?W("div",null,_e,W("footer",{key:"footer"},ie.map(function(e){return W("div",{id:l(e.identifier,Ae),key:e.identifier},e.identifier,fe(se(e.footnote,{inline:!0})))}))):_e}export default n=>{let{children:t="",options:o}=n,a=function(e,n){if(null==e)return{};var r,t,o={},a=Object.keys(e);for(t=0;t<a.length;t++)n.indexOf(r=a[t])>=0||(o[r]=e[r]);return o}(n,r);return e.cloneElement(We(t,o),a)};export{t as RuleType,We as compiler,De as sanitizer,Ae as slugify};
|
|
1
|
+
import*as n from"react";function t(){return t=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)({}).hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n},t.apply(null,arguments)}const r=["strong","em","del","mark"],e=[["**",r[0]],["__",r[0]],["~~",r[2]],["==",r[3]],["*","em"],["_","em"]];function o(n,t){for(var r=1,e=t+1;e<n.length&&r>0;)"\\"!==n[e]?("["===n[e]&&r++,"]"===n[e]&&r--,e++):e+=2;if(0===r&&e<n.length&&("("===n[e]||"["===n[e])){var o="("===n[e]?")":"]",u=1;for(e++;e<n.length&&u>0;)"\\"!==n[e]?("("===n[e]&&")"===o&&u++,n[e]===o&&u--,e++):e+=2;if(0===u)return e}return-1}function u(n,t){if(!t||!t.inline&&!t.simple)return null;var r=n[0];if("*"!==r&&"_"!==r&&"~"!==r&&"="!==r)return null;for(var u="",a=0,c="",i=0;i<6;i++){var l=e[i][0];if(n.startsWith(l)&&n.length>=2*l.length){u=l,a=l.length,c=e[i][1];break}}if(!u)return null;for(var f=a,s=!1,_=!1,d="",p=0,y="",h=!1,m="";f<n.length;){var g=n[f];if(h)y+=g,h=!1,m=g,f++;else if("\\"!==g)if("`"!==g||0!==p){if("["===g&&!s&&0===p){var k=o(n,f);if(-1!==k){y+=n.slice(f,k),f=k,m=n[k-1];continue}}if(_)y+=g,d?g===d&&(d=""):'"'===g||"'"===g?d=g:">"===g&&(_=!1),m=g,f++;else if("<"!==g||s){if("\n"===g&&"\n"===m&&!s&&0===p)return null;if(!s&&0===p){for(var v=0;f+v<n.length&&n[f+v]===u[0];)v++;if(v>=a&&(1!==a||"*"!==u&&"_"!==u||n[f-1]!==u&&n[f+1]!==u)){var x=[n.slice(0,f+v),c,y+n.slice(f+a,f+v)];return x.index=0,x.input=n,x}}y+=g,m=g,f++}else{var q=n[f+1],b=n.indexOf(">",f);if(-1!==b){var S=n.slice(f,b+1).endsWith("/>");"/"===q?p=Math.max(0,p-1):S||p++}_=!0,y+=g,m=g,f++}}else s=!s,y+=g,m=g,f++;else y+=g,h=!0,m=g,f++}return null}const a=["children","options"],c={blockQuote:"0",breakLine:"1",breakThematic:"2",codeBlock:"3",codeFenced:"4",codeInline:"5",footnote:"6",footnoteReference:"7",gfmTask:"8",heading:"9",headingSetext:"10",htmlBlock:"11",htmlComment:"12",htmlSelfClosing:"13",image:"14",link:"15",linkAngleBraceStyleDetector:"16",linkBareUrlDetector:"17",linkMailtoDetector:"18",newlineCoalescer:"19",orderedList:"20",paragraph:"21",ref:"22",refImage:"23",refLink:"24",table:"25",tableSeparator:"26",text:"27",textEscaped:"28",textFormatted:"34",unorderedList:"30"},i=["allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","cellPadding","cellSpacing","charSet","classId","colSpan","contentEditable","contextMenu","crossOrigin","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hrefLang","inputMode","keyParams","keyType","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","radioGroup","readOnly","rowSpan","spellCheck","srcDoc","srcLang","srcSet","tabIndex","useMap"].reduce((n,t)=>(n[t.toLowerCase()]=t,n),{class:"className",for:"htmlFor"}),l={amp:"&",apos:"'",gt:">",lt:"<",nbsp:" ",quot:"“"},f=["style","script","pre"],s=["src","href","data","formAction","srcDoc","action"],_=/([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi,d=/\n{2,}$/,p=/^(\s*>[\s\S]*?)(?=\n\n|$)/,y=/^ *> ?/gm,h=/^(?:\[!([^\]]*)\]\n)?([\s\S]*)/,m=/^ {2,}\n/,g=/^(?:([-*_])( *\1){2,}) *(?:\n *)+\n/,k=/^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/,v=/^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/,x=/^(`+)((?:\\`|(?!\1)`|[^`])+)\1/,q=/^(?:\n *)*\n/,b=/\r\n?/g,S=/^\[\^([^\]]+)](:(.*)((\n+ {4,}.*)|(\n(?!\[\^).+))*)/,$=/^\[\^([^\]]+)]/,z=/\f/g,A=/^---[ \t]*\n(.|\n)*\n---[ \t]*\n/,E=/^\[(x|\s)\]/,R=/^(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,w=/^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,L=/^([^\n]+)\n *(=|-)\2{2,} *\n/,B=/^<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>/i;function C(n){const t=B.exec(n);if(!t)return null;const r=t[1],e=r.toLowerCase(),o=e.length+1;let u=t[0].length;"\n"===n[u]&&u++;const a=u;let c=u,i=1;const l=n.length;for(;i>0;){const t=n.indexOf("<",u);if(-1===t)return null;let a=-1,f=-1;if("/"===n[t+1])f=t;else if(n[t+1]===e[0]||n[t+1]===r[0]){let u=!0;for(let o=0;o<e.length;o++){const a=n[t+1+o];if(a!==e[o]&&a!==r[o]){u=!1;break}}!u||" "!==n[t+o]&&">"!==n[t+o]||(a=t)}if(-1!==a||-1!==f)if(-1!==a&&(-1===f||a<f))u=a+o+1,i++;else{let t=f+2;for(;t<l;){const r=n[t];if(" "!==r&&"\t"!==r&&"\n"!==r&&"\r"!==r)break;t++}if(t+e.length>l)return null;let o=!0;for(let u=0;u<e.length;u++){const a=n[t+u];if(a!==e[u]&&a!==r[u]){o=!1;break}}if(!o){u=t;continue}for(t+=e.length;t<l;){const r=n[t];if(" "!==r&&"\t"!==r&&"\n"!==r&&"\r"!==r)break;t++}if(t>=l||">"!==n[t]){u=t;continue}c=f,u=t+1,i--}else u=t+1}let f=0;for(;u+f<l&&"\n"===n[u+f];)f++;return[n.slice(0,u+f),r,t[2],n.slice(a,c)]}const I=/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi,M=/^<!--[\s\S]*?(?:-->)/,T=/^(data|aria|x)-[a-z_][a-z\d_.-]*$/,F=/^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i,O=/^\{.*\}$/,P=/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,j=/^<([^ >]+[:@\/][^ >]+)>/,D=/-([a-z])?/gi,Z=/^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/,N=/^[^\n]+(?: \n|\n{2,})/,G=/^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/,U=/^!\[([^\]]*)\] ?\[([^\]]*)\]/,V=/^\[([^\]]*)\] ?\[([^\]]*)\]/,H=/(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/,Q=/\t/g,W=/(^ *\||\| *$)/g,J=/^ *:-+: *$/,K=/^ *:-+ *$/,X=/^ *-+: *$/,Y=/^(:[a-zA-Z0-9-_]+:)/,nn=/^\\([^0-9A-Za-z\s])/,tn=/\\([^0-9A-Za-z\s])/g,rn=/^[\s\S](?:(?! \n|[0-9]\.|http)[^=*_~\-\n:<`\\\[!])*/,en=/^\n+/,on=/^([ \t]*)/,un=/(?:^|\n)( *)$/,an="(?:\\d+\\.)",cn="(?:[*+-])";function ln(n){return"( *)("+(1===n?an:cn)+") +"}const fn=ln(1),sn=ln(2);function _n(n){return RegExp("^"+(1===n?fn:sn))}const dn=_n(1),pn=_n(2);function yn(n){return RegExp("^"+(1===n?fn:sn)+"[^\\n]*(?:\\n(?!\\1"+(1===n?an:cn)+" )[^\\n]*)*(\\n|$)","gm")}const hn=yn(1),mn=yn(2);function gn(n){const t=1===n?an:cn;return RegExp("^( *)("+t+") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1"+t+" (?!"+t+" ))\\n*|\\s*\\n*$)")}const kn=gn(1),vn=gn(2);function xn(n,t){const r=1===t,e=r?kn:vn,o=r?hn:mn,u=r?dn:pn;return{t:n=>u.test(n),o:In(function(n,t){const r=un.exec(t.prevCapture);return r&&(t.list||!t.inline&&!t.simple)?e.exec(n=r[1]+n):null}),u:1,i(n,t,e){const a=r?+n[2]:void 0,c=n[0].replace(d,"\n").match(o),i=u.exec(c[0]),l=RegExp("^ {1,"+(i?i[0].length:0)+"}","gm");let f=!1;return{items:c.map(function(n,r){const o=n.replace(l,"").replace(u,""),a=r===c.length-1,i=An(o,"\n\n")||a&&f;f=i;const s=e.inline,_=e.list;let d;e.list=!0,i?(e.inline=!1,d=$n(o)+"\n\n"):(e.inline=!0,d=$n(o));const p=t(d,e);return e.inline=s,e.list=_,p}),ordered:r,start:a}}}}const qn=RegExp("^\\[((?:\\[[^\\[\\]]*(?:\\[[^\\[\\]]*\\][^\\[\\]]*)*\\]|[^\\[\\]])*)\\]\\(\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*\\)"),bn=/^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/;function Sn(n){return"string"==typeof n}function $n(n){let t=n.length;for(;t>0&&n[t-1]<=" ";)t--;return n.slice(0,t)}function zn(n,t){return n.startsWith(t)}function An(n,t){return-1!==n.indexOf(t)}function En(n,t,r){if(Array.isArray(r)){for(let t=0;t<r.length;t++)if(zn(n,r[t]))return!0;return!1}return r(n,t)}function Rn(n){return n.replace(/[ÀÁÂÃÄÅàáâãä忯]/g,"a").replace(/[çÇ]/g,"c").replace(/[ðÐ]/g,"d").replace(/[ÈÉÊËéèêë]/g,"e").replace(/[ÏïÎîÍíÌì]/g,"i").replace(/[Ññ]/g,"n").replace(/[øØœŒÕõÔôÓóÒò]/g,"o").replace(/[ÜüÛûÚúÙù]/g,"u").replace(/[ŸÿÝý]/g,"y").replace(/[^a-z0-9- ]/gi,"").replace(/ /gi,"-").toLowerCase()}function wn(n){return X.test(n)?"right":J.test(n)?"center":K.test(n)?"left":null}function Ln(n,t,r,e){const o=r.inTable;r.inTable=!0;let u=[[]],a="";function c(){if(!a)return;const n=u[u.length-1];n.push.apply(n,t(a,r)),a=""}return n.trim().split(/(`[^`]*`|\\\||\|)/).filter(Boolean).forEach((n,t,r)=>{"|"===n.trim()&&(c(),e)?0!==t&&t!==r.length-1&&u.push([]):a+=n}),c(),r.inTable=o,u}function Bn(n,t,r){r.inline=!0;const e=n[2]?n[2].replace(W,"").split("|").map(wn):[],o=n[3]?function(n,t,r){return n.trim().split("\n").map(function(n){return Ln(n,t,r,!0)})}(n[3],t,r):[],u=Ln(n[1],t,r,!!o.length);return r.inline=!1,o.length?{align:e,cells:o,header:u,type:"25"}:{children:u,type:"21"}}function Cn(n,t){return null==n.align[t]?{}:{textAlign:n.align[t]}}function In(n){return n.inline=1,n}function Mn(n){return In(function(t,r){return r.inline?n.exec(t):null})}function Tn(n){return In(function(t,r){return r.inline||r.simple?n.exec(t):null})}function Fn(n){return function(t,r){return r.inline||r.simple?null:n.exec(t)}}function On(n){return In(function(t){return n.exec(t)})}const Pn=/(javascript|vbscript|data(?!:image)):/i;function jn(n){try{const t=decodeURIComponent(n).replace(/[^A-Za-z0-9/:]/g,"");if(Pn.test(t))return null}catch(n){return null}return n}function Dn(n){return n?n.replace(tn,"$1"):n}function Zn(n,t,r){const e=r.inline||!1,o=r.simple||!1;r.inline=!0,r.simple=!0;const u=n(t,r);return r.inline=e,r.simple=o,u}function Nn(n,t,r){const e=r.inline||!1,o=r.simple||!1;r.inline=!1,r.simple=!0;const u=n(t,r);return r.inline=e,r.simple=o,u}function Gn(n,t,r){const e=r.inline||!1;r.inline=!1;const o=n(t,r);return r.inline=e,o}const Un=(n,t,r)=>({children:Zn(t,n[2],r)});function Vn(){return{}}function Hn(...n){return n.filter(Boolean).join(" ")}function Qn(n,t,r){let e=n;const o=t.split(".");for(;o.length&&(e=e[o[0]],void 0!==e);)o.shift();return e||r}function Wn(n,t,r,e){if(!t||!t.trim())return null;const o=t.match(_);return o?o.reduce(function(t,o){const u=o.indexOf("=");if(-1!==u){const a=function(n){return-1!==n.indexOf("-")&&null===n.match(T)&&(n=n.replace(D,function(n,t){return t.toUpperCase()})),n}(o.slice(0,u)).trim(),c=i[a]||a;if("ref"===c)return t;const l=t[c]=function(n,t,r,e){return"style"===t?function(n){const t=[];if(!n)return t;let r="",e=0,o="";for(let u=0;u<n.length;u++){const a=n[u];if('"'===a||"'"===a)o?a===o&&(o="",e--):(o=a,e++);else if("("===a&&r.endsWith("url"))e++;else if(")"===a&&e>0)e--;else if(";"===a&&0===e){const n=r.indexOf(":");n>0&&t.push([r.slice(0,n).trim(),r.slice(n+1).trim()]),r="";continue}r+=a}const u=r.indexOf(":");return u>0&&t.push([r.slice(0,u).trim(),r.slice(u+1).trim()]),t}(r).reduce(function(t,[r,o]){return t[r.replace(/(-[a-z])/g,n=>n[1].toUpperCase())]=e(o,n,r),t},{}):-1!==s.indexOf(t)?e(Dn(r),n,t):(r.match(O)&&(r=Dn(r.slice(1,r.length-1))),"true"===r||"false"!==r&&r)}(n,a,function(n){const t=n[0];return('"'===t||"'"===t)&&n.length>=2&&n[n.length-1]===t?n.slice(1,-1):n}(o.slice(u+1).trim()),r);"string"==typeof l&&(B.test(l)||F.test(l))&&(t[c]=e(l.trim()))}else"style"!==o&&(t[i[o]||o]=!0);return t},{}):null}function Jn(n,t){for(let r=0;r<n.length;r++)if(n[r].test(t))return!0;return!1}function Kn(r="",e={}){e.overrides=e.overrides||{},e.namedCodesToUnicode=e.namedCodesToUnicode?t({},l,e.namedCodesToUnicode):l;const o=e.slugify||Rn,a=e.sanitizer||jn,c=e.createElement||n.createElement,i=[p,k,v,e.enforceAtxHeadings?w:R,L,Z,kn,vn],s=[...i,N,B,M,F];function _(n,r,...o){const u=Qn(e.overrides,n+".props",{});return c(function(n,t){const r=Qn(t,n);return r?"function"==typeof r||"object"==typeof r&&"render"in r?r:Qn(t,n+".component",n):n}(n,e.overrides),t({},r,u,{className:Hn(null==r?void 0:r.className,u.className)||void 0}),...o)}function d(n){n=n.replace(A,"");let r=!1;e.forceInline?r=!0:e.forceBlock||(r=!1===H.test(n));const u=W(r?n:$n(n).replace(en,"")+"\n\n",{inline:r});if(e.ast)return u;const a=J(u);for(;Sn(a[a.length-1])&&!a[a.length-1].trim();)a.pop();if(T.length&&a.push(_("footer",{key:"footer"},T.map(function(n){return _("div",{id:o(n.identifier,Rn),key:n.identifier},n.identifier,J(W(n.footnote,{inline:!0})))}))),null===e.wrapper)return a;const i=e.wrapper||(r?"span":"div");let l;if(a.length>1||e.forceWrapper)l=a;else{if(1===a.length)return l=a[0],"string"==typeof l?_("span",{key:"outer"},l):l;l=null}return c(i,t({key:"outer"},e.wrapperProps),l)}const T=[],O={},D={0:{t:[">"],o:Fn(p),u:1,i(n,t,r){const[,e,o]=n[0].replace(y,"").match(h);return{alert:e,children:t(o,r)}}},1:{t:[" "],o:Mn(m),u:1,i:Vn},2:{t:function(n,t){if(t.inline||t.simple)return!1;var r=n[0];return"-"===r||"*"===r||"_"===r},o:Fn(g),u:1,i:Vn},3:{t:[" "],o:Fn(v),u:0,i:n=>({lang:void 0,text:Dn($n(n[0].replace(/^ {4}/gm,"")))})},4:{t:["```","~~~"],o:Fn(k),u:0,i:n=>({attrs:Wn("code",n[3]||"",a,d),lang:n[2]||void 0,text:n[4],type:"3"})},5:{t:["`"],o:Tn(x),u:3,i:n=>({text:Dn(n[2])})},6:{t:["[^"],o:Fn(S),u:0,i:n=>(T.push({footnote:n[2],identifier:n[1]}),{})},7:{t:["[^"],o:Mn($),u:1,i:n=>({target:"#"+o(n[1],Rn),text:n[1]})},8:{t:["[ ]","[x]"],o:Mn(E),u:1,i:n=>({completed:"x"===n[1].toLowerCase()})},9:{t:["#"],o:Fn(e.enforceAtxHeadings?w:R),u:1,i:(n,t,r)=>({children:Zn(t,n[2],r),id:o(n[2],Rn),level:n[1].length})},10:{t:n=>{const t=n.indexOf("\n");return t>0&&t<n.length-1&&("="===n[t+1]||"-"===n[t+1])},o:Fn(L),u:1,i:(n,t,r)=>({children:Zn(t,n[1],r),level:"="===n[2]?1:2,type:"9"})},11:{t:["<"],o:In(C),u:1,i(n,t,r){const[,e]=n[3].match(on),o=RegExp("^"+e,"gm"),u=n[3].replace(o,""),c=Jn(s,u)?Gn:Zn,i=n[1].toLowerCase(),l=-1!==f.indexOf(i),_=(l?i:n[1]).trim(),p={attrs:Wn(_,n[2],a,d),noInnerParse:l,tag:_};if(r.inAnchor=r.inAnchor||"a"===i,l)p.text=n[3];else{const n=r.inHTML;r.inHTML=!0,p.children=c(t,u,r),r.inHTML=n}return r.inAnchor=!1,p}},13:{t:["<"],o:On(F),u:1,i(n){const t=n[1].trim();return{attrs:Wn(t,n[2]||"",a,d),tag:t}}},12:{t:["\x3c!--"],o:On(M),u:1,i:()=>({})},14:{t:["!["],o:Tn(bn),u:1,i:n=>({alt:Dn(n[1]),target:Dn(n[2]),title:Dn(n[3])})},15:{t:["["],o:Mn(qn),u:3,i:(n,t,r)=>({children:Nn(t,n[1],r),target:Dn(n[2]),title:Dn(n[3])})},16:{t:function(n,t){return!(!t.inline||t.inAnchor)&&"<"===n[0]&&(An(n,":")||An(n,"@")||An(n,"/"))},o:Mn(j),u:0,i(n){let t=n[1],r=!1;return An(t,"@")&&!An(t,"//")&&(r=!0,t=t.replace("mailto:","")),{children:[{text:t,type:"27"}],target:r?"mailto:"+t:t,type:"15"}}},17:{t:(n,t)=>!t.inAnchor&&!e.disableAutoLink&&zn(n,"http"),o:Mn(P),u:0,i:n=>({children:[{text:n[1],type:"27"}],target:n[1],title:void 0,type:"15"})},20:xn(0,1),30:xn(0,2),19:{t:["\n"],o:Fn(q),u:3,i:Vn},21:{t:function(n,t){return!t.inline&&!t.simple},o:In(function(n,t){if(t.inline||t.simple||t.inHTML&&!An(n,"\n\n")&&!An(t.prevCapture,"\n\n"))return null;let r="",e=0;for(;;){const t=n.indexOf("\n",e),o=n.slice(e,-1===t?void 0:t+1),u=n[e];if((">"===u||"#"===u||"|"===u||"`"===u||"~"===u||"*"===u||"-"===u||"_"===u||" "===u)&&Jn(i,o))break;if(r+=o,-1===t||!o.trim())break;e=t+1}const o=$n(r);return""===o?null:[r,,o]}),u:3,i:Un},22:{t:["["],o:Mn(G),u:0,i:n=>(O[n[1]]={target:n[2],title:n[4]},{})},23:{t:["!["],o:Tn(U),u:0,i:n=>({alt:n[1]?Dn(n[1]):void 0,ref:n[2]})},24:{t:n=>"["===n[0]&&!An(n,"]("),o:Mn(V),u:0,i:(n,t,r)=>({children:t(n[1],r),fallbackChildren:n[0],ref:n[2]})},25:{t:["|"],o:Fn(Z),u:1,i:Bn},27:{o:In(function(n,t){let r;return zn(n,":")&&(r=Y.exec(n)),r||rn.exec(n)}),u:4,i(n){const t=n[0];return{text:An(t,"&")?t.replace(I,(n,t)=>e.namedCodesToUnicode[t]||n):t}}},34:{t:["*","_","~","="],o:In(u),u:2,i:(n,t,r)=>({children:t(n[2],r),tag:n[1]})},28:{t:["\\"],o:Tn(nn),u:1,i:n=>({text:n[1],type:"27"})}};!0===e.disableParsingRawHTML&&(delete D[11],delete D[13]);const W=function(n){var t=Object.keys(n);function r(e,o){var u=[];if(o.prevCapture=o.prevCapture||"",e.trim())for(;e;)for(var a=0;a<t.length;){var c=t[a],i=n[c];if(!i.t||En(e,o,i.t)){var l=i.o(e,o);if(l&&l[0]){e=e.substring(l[0].length);var f=i.i(l,r,o);o.prevCapture+=l[0],f.type||(f.type=c),u.push(f);break}a++}else a++}return o.prevCapture="",u}return t.sort(function(t,r){return n[t].u-n[r].u||(t<r?-1:1)}),function(n,t){return r(function(n){return n.replace(b,"\n").replace(z,"").replace(Q," ")}(n),t)}}(D),J=function(n,r,e,o,u){function a(n){return Array.isArray(n)?n.map(n=>"text"in n?n.text:""):"text"in n?n.text:""}return function c(i,l={}){const f=(l.renderDepth||0)+1;if(f>2500)return a(i);l.renderDepth=f;try{if(Array.isArray(i)){const n=l.key,t=[];let r=!1;for(let n=0;n<i.length;n++){l.key=n;const e=c(i[n],l),o=Sn(e);o&&r?t[t.length-1]+=e:null!==e&&t.push(e),r=o}return l.key=n,l.renderDepth=f-1,t}const a=function(a,c,i){const l=()=>function(n,r,e,o,u,a,c){switch(n.type){case"0":{const t={key:e.key};return n.alert&&(t.className="markdown-alert-"+a(n.alert.toLowerCase(),Rn),n.children.unshift({attrs:{},children:[{type:"27",text:n.alert}],noInnerParse:!0,type:"11",tag:"header"})),o("blockquote",t,r(n.children,e))}case"1":return o("br",{key:e.key});case"2":return o("hr",{key:e.key});case"3":return o("pre",{key:e.key},o("code",t({},n.attrs,{className:n.lang?"lang-"+n.lang:""}),n.text));case"5":return o("code",{key:e.key},n.text);case"7":return o("a",{key:e.key,href:u(n.target,"a","href")},o("sup",{key:e.key},n.text));case"8":return o("input",{checked:n.completed,key:e.key,readOnly:!0,type:"checkbox"});case"9":return o("h"+n.level,{id:n.id,key:e.key},r(n.children,e));case"11":return o(n.tag,t({key:e.key},n.attrs),n.text||(n.children?r(n.children,e):""));case"13":return o(n.tag,t({},n.attrs,{key:e.key}));case"14":return o("img",{key:e.key,alt:n.alt||void 0,title:n.title||void 0,src:u(n.target,"img","src")});case"15":return o("a",{key:e.key,href:u(n.target,"a","href"),title:n.title},r(n.children,e));case"23":return c[n.ref]?o("img",{key:e.key,alt:n.alt,src:u(c[n.ref].target,"img","src"),title:c[n.ref].title}):null;case"24":return c[n.ref]?o("a",{key:e.key,href:u(c[n.ref].target,"a","href"),title:c[n.ref].title},r(n.children,e)):o("span",{key:e.key},n.fallbackChildren);case"25":{const t=n;return o("table",{key:e.key},o("thead",null,o("tr",null,t.header.map(function(n,u){return o("th",{key:u,style:Cn(t,u)},r(n,e))}))),o("tbody",null,t.cells.map(function(n,u){return o("tr",{key:u},n.map(function(n,u){return o("td",{key:u,style:Cn(t,u)},r(n,e))}))})))}case"27":return n.text;case"34":return o(n.tag,{key:e.key},r(n.children,e));case"20":case"30":return o(n.ordered?"ol":"ul",{key:e.key,start:"20"===n.type?n.start:void 0},n.items.map(function(n,t){return o("li",{key:t},r(n,e))}));case"19":return"\n";case"21":return o("p",{key:e.key},r(n.children,e));default:return null}}(a,c,i,r,e,o,u);return n?n(l,a,c,i):l()}(i,c,l);return l.renderDepth=f-1,a}catch(n){if(n instanceof RangeError&&n.message.includes("Maximum call stack"))return a(i);throw n}}}(e.renderRule,_,a,o,O);return d(r)}const Xn=n=>{let{children:r,options:e}=n,o=function(n,t){if(null==n)return{};var r={};for(var e in n)if({}.hasOwnProperty.call(n,e)){if(-1!==t.indexOf(e))continue;r[e]=n[e]}return r}(n,a);return Kn(null==r?"":r,t({},e,{wrapperProps:t({},null==e?void 0:e.wrapperProps,o)}))};export{c as RuleType,Kn as compiler,Xn as default,jn as sanitizer,Rn as slugify};
|
|
2
2
|
//# sourceMappingURL=index.modern.js.map
|