@intlayer/design-system 6.1.3 → 6.1.5
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/.vite/manifest.json +63 -7
- package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.cjs +2 -2
- package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.mjs +1 -1
- package/dist/components/DictionaryFieldEditor/VersionSwitcherDropDown/versionSwitcherDropDown.content.cjs +2 -1
- package/dist/components/DictionaryFieldEditor/VersionSwitcherDropDown/versionSwitcherDropDown.content.cjs.map +1 -1
- package/dist/components/ExpandCollapse/expandCollapse.content.cjs +2 -1
- package/dist/components/ExpandCollapse/expandCollapse.content.cjs.map +1 -1
- package/dist/components/Headers/index.cjs +12 -0
- package/dist/components/Headers/index.cjs.map +1 -1
- package/dist/components/Headers/index.d.ts +1 -0
- package/dist/components/Headers/index.d.ts.map +1 -1
- package/dist/components/Headers/index.mjs +13 -1
- package/dist/components/Headers/index.mjs.map +1 -1
- package/dist/components/IDE/Code.cjs +1 -1
- package/dist/components/IDE/Code.cjs.map +1 -1
- package/dist/components/IDE/Code.mjs +1 -1
- package/dist/components/IDE/Code.mjs.map +1 -1
- package/dist/components/IDE/MarkDownRender.cjs +2 -2
- package/dist/components/IDE/MarkDownRender.cjs.map +1 -1
- package/dist/components/IDE/MarkDownRender.d.ts.map +1 -1
- package/dist/components/IDE/MarkDownRender.mjs +2 -2
- package/dist/components/IDE/MarkDownRender.mjs.map +1 -1
- package/dist/components/IDE/code.content.cjs +2 -1
- package/dist/components/IDE/code.content.cjs.map +1 -1
- package/dist/components/IDE/copyCode.content.cjs +2 -1
- package/dist/components/IDE/copyCode.content.cjs.map +1 -1
- package/dist/components/LocaleSwitcherContentDropDown/localeSwitcher.content.cjs +2 -1
- package/dist/components/LocaleSwitcherContentDropDown/localeSwitcher.content.cjs.map +1 -1
- package/dist/components/LocaleSwitcherDropDown/localeSwitcher.content.cjs +2 -1
- package/dist/components/LocaleSwitcherDropDown/localeSwitcher.content.cjs.map +1 -1
- package/dist/components/MarkDownRender/MarkDownRender.cjs +189 -0
- package/dist/components/MarkDownRender/MarkDownRender.cjs.map +1 -0
- package/dist/components/MarkDownRender/MarkDownRender.d.ts +12 -0
- package/dist/components/MarkDownRender/MarkDownRender.d.ts.map +1 -0
- package/dist/components/MarkDownRender/MarkDownRender.mjs +189 -0
- package/dist/components/MarkDownRender/MarkDownRender.mjs.map +1 -0
- package/dist/components/MarkDownRender/index.cjs +2 -150
- package/dist/components/MarkDownRender/index.cjs.map +1 -1
- package/dist/components/MarkDownRender/index.d.ts +1 -11
- package/dist/components/MarkDownRender/index.d.ts.map +1 -1
- package/dist/components/MarkDownRender/index.mjs +1 -149
- package/dist/components/MarkDownRender/index.mjs.map +1 -1
- package/dist/components/MarkDownRender/processor.cjs +1819 -0
- package/dist/components/MarkDownRender/processor.cjs.map +1 -0
- package/dist/components/MarkDownRender/processor.d.ts +368 -0
- package/dist/components/MarkDownRender/processor.d.ts.map +1 -0
- package/dist/components/MarkDownRender/processor.mjs +1819 -0
- package/dist/components/MarkDownRender/processor.mjs.map +1 -0
- package/dist/components/Tab/Tab.cjs +171 -0
- package/dist/components/Tab/Tab.cjs.map +1 -0
- package/dist/components/Tab/Tab.d.ts +24 -0
- package/dist/components/Tab/Tab.d.ts.map +1 -0
- package/dist/components/Tab/Tab.mjs +171 -0
- package/dist/components/Tab/Tab.mjs.map +1 -0
- package/dist/components/Tab/TabContext.cjs +28 -0
- package/dist/components/Tab/TabContext.cjs.map +1 -0
- package/dist/components/Tab/TabContext.d.ts +19 -0
- package/dist/components/Tab/TabContext.d.ts.map +1 -0
- package/dist/components/Tab/TabContext.mjs +28 -0
- package/dist/components/Tab/TabContext.mjs.map +1 -0
- package/dist/components/Tab/index.cjs +5 -0
- package/dist/components/Tab/index.cjs.map +1 -0
- package/dist/components/Tab/index.d.ts +2 -0
- package/dist/components/Tab/index.d.ts.map +1 -0
- package/dist/components/Tab/index.mjs +5 -0
- package/dist/components/Tab/index.mjs.map +1 -0
- package/dist/components/TabSelector/TabSelector.cjs +6 -1
- package/dist/components/TabSelector/TabSelector.cjs.map +1 -1
- package/dist/components/TabSelector/TabSelector.d.ts +1 -1
- package/dist/components/TabSelector/TabSelector.d.ts.map +1 -1
- package/dist/components/TabSelector/TabSelector.mjs +6 -1
- package/dist/components/TabSelector/TabSelector.mjs.map +1 -1
- package/dist/components/Table/Table.cjs +15 -8
- package/dist/components/Table/Table.cjs.map +1 -1
- package/dist/components/Table/Table.d.ts.map +1 -1
- package/dist/components/Table/Table.mjs +15 -8
- package/dist/components/Table/Table.mjs.map +1 -1
- package/dist/components/Table/table.content.cjs +2 -1
- package/dist/components/Table/table.content.cjs.map +1 -1
- package/dist/components/index.cjs +5 -2
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.mjs +5 -2
- package/dist/components/index.mjs.map +1 -1
- package/dist/hooks/index.cjs +2 -0
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.mjs +2 -0
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/useHorizontalSwipe.cjs +144 -0
- package/dist/hooks/useHorizontalSwipe.cjs.map +1 -0
- package/dist/hooks/useHorizontalSwipe.d.ts +26 -0
- package/dist/hooks/useHorizontalSwipe.d.ts.map +1 -0
- package/dist/hooks/useHorizontalSwipe.mjs +144 -0
- package/dist/hooks/useHorizontalSwipe.mjs.map +1 -0
- package/package.json +44 -20
|
@@ -0,0 +1,1819 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const ReactExports = require("react");
|
|
5
|
+
var define_process_env_default = {};
|
|
6
|
+
const RuleType = {
|
|
7
|
+
blockQuote: "0",
|
|
8
|
+
breakLine: "1",
|
|
9
|
+
breakThematic: "2",
|
|
10
|
+
codeBlock: "3",
|
|
11
|
+
codeFenced: "4",
|
|
12
|
+
codeInline: "5",
|
|
13
|
+
footnote: "6",
|
|
14
|
+
footnoteReference: "7",
|
|
15
|
+
gfmTask: "8",
|
|
16
|
+
heading: "9",
|
|
17
|
+
headingSetext: "10",
|
|
18
|
+
/** only available if not `disableHTMLParsing` */
|
|
19
|
+
htmlBlock: "11",
|
|
20
|
+
htmlComment: "12",
|
|
21
|
+
/** only available if not `disableHTMLParsing` */
|
|
22
|
+
htmlSelfClosing: "13",
|
|
23
|
+
/** Custom components like <Tabs>, <TabItem> */
|
|
24
|
+
customComponent: "34",
|
|
25
|
+
image: "14",
|
|
26
|
+
link: "15",
|
|
27
|
+
/** emits a `link` 'node', does not render directly */
|
|
28
|
+
linkAngleBraceStyleDetector: "16",
|
|
29
|
+
/** emits a `link` 'node', does not render directly */
|
|
30
|
+
linkBareUrlDetector: "17",
|
|
31
|
+
/** emits a `link` 'node', does not render directly */
|
|
32
|
+
linkMailtoDetector: "18",
|
|
33
|
+
newlineCoalescer: "19",
|
|
34
|
+
orderedList: "20",
|
|
35
|
+
paragraph: "21",
|
|
36
|
+
ref: "22",
|
|
37
|
+
refImage: "23",
|
|
38
|
+
refLink: "24",
|
|
39
|
+
table: "25",
|
|
40
|
+
tableSeparator: "26",
|
|
41
|
+
text: "27",
|
|
42
|
+
textBolded: "28",
|
|
43
|
+
textEmphasized: "29",
|
|
44
|
+
textEscaped: "30",
|
|
45
|
+
textMarked: "31",
|
|
46
|
+
textStrikethroughed: "32",
|
|
47
|
+
unorderedList: "33"
|
|
48
|
+
};
|
|
49
|
+
if (define_process_env_default.NODE_ENV === "test") {
|
|
50
|
+
Object.keys(RuleType).forEach((key) => RuleType[key] = key);
|
|
51
|
+
}
|
|
52
|
+
const Priority = {
|
|
53
|
+
/**
|
|
54
|
+
* anything that must scan the tree before everything else
|
|
55
|
+
*/
|
|
56
|
+
MAX: 0,
|
|
57
|
+
/**
|
|
58
|
+
* scans for block-level constructs
|
|
59
|
+
*/
|
|
60
|
+
HIGH: 1,
|
|
61
|
+
/**
|
|
62
|
+
* inline w/ more priority than other inline
|
|
63
|
+
*/
|
|
64
|
+
MED: 2,
|
|
65
|
+
/**
|
|
66
|
+
* inline elements
|
|
67
|
+
*/
|
|
68
|
+
LOW: 3,
|
|
69
|
+
/**
|
|
70
|
+
* bare text and stuff that is considered leftovers
|
|
71
|
+
*/
|
|
72
|
+
MIN: 4
|
|
73
|
+
};
|
|
74
|
+
const ATTRIBUTE_TO_JSX_PROP_MAP = [
|
|
75
|
+
"allowFullScreen",
|
|
76
|
+
"allowTransparency",
|
|
77
|
+
"autoComplete",
|
|
78
|
+
"autoFocus",
|
|
79
|
+
"autoPlay",
|
|
80
|
+
"cellPadding",
|
|
81
|
+
"cellSpacing",
|
|
82
|
+
"charSet",
|
|
83
|
+
"classId",
|
|
84
|
+
"colSpan",
|
|
85
|
+
"contentEditable",
|
|
86
|
+
"contextMenu",
|
|
87
|
+
"crossOrigin",
|
|
88
|
+
"encType",
|
|
89
|
+
"formAction",
|
|
90
|
+
"formEncType",
|
|
91
|
+
"formMethod",
|
|
92
|
+
"formNoValidate",
|
|
93
|
+
"formTarget",
|
|
94
|
+
"frameBorder",
|
|
95
|
+
"hrefLang",
|
|
96
|
+
"inputMode",
|
|
97
|
+
"keyParams",
|
|
98
|
+
"keyType",
|
|
99
|
+
"marginHeight",
|
|
100
|
+
"marginWidth",
|
|
101
|
+
"maxLength",
|
|
102
|
+
"mediaGroup",
|
|
103
|
+
"minLength",
|
|
104
|
+
"noValidate",
|
|
105
|
+
"radioGroup",
|
|
106
|
+
"readOnly",
|
|
107
|
+
"rowSpan",
|
|
108
|
+
"spellCheck",
|
|
109
|
+
"srcDoc",
|
|
110
|
+
"srcLang",
|
|
111
|
+
"srcSet",
|
|
112
|
+
"tabIndex",
|
|
113
|
+
"useMap"
|
|
114
|
+
].reduce(
|
|
115
|
+
(obj, x) => {
|
|
116
|
+
obj[x.toLowerCase()] = x;
|
|
117
|
+
return obj;
|
|
118
|
+
},
|
|
119
|
+
{ class: "className", for: "htmlFor" }
|
|
120
|
+
);
|
|
121
|
+
const namedCodesToUnicode = {
|
|
122
|
+
amp: "&",
|
|
123
|
+
apos: "'",
|
|
124
|
+
gt: ">",
|
|
125
|
+
lt: "<",
|
|
126
|
+
nbsp: " ",
|
|
127
|
+
quot: "“"
|
|
128
|
+
};
|
|
129
|
+
const DO_NOT_PROCESS_HTML_ELEMENTS = ["style", "script", "pre"];
|
|
130
|
+
const ATTRIBUTES_TO_SANITIZE = [
|
|
131
|
+
"src",
|
|
132
|
+
"href",
|
|
133
|
+
"data",
|
|
134
|
+
"formAction",
|
|
135
|
+
"srcDoc",
|
|
136
|
+
"action"
|
|
137
|
+
];
|
|
138
|
+
const ATTR_EXTRACTOR_R = /([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi;
|
|
139
|
+
const AUTOLINK_MAILTO_CHECK_R = /mailto:/i;
|
|
140
|
+
const BLOCK_END_R = /\n{2,}$/;
|
|
141
|
+
const BLOCKQUOTE_R = /^(\s*>[\s\S]*?)(?=\n\n|$)/;
|
|
142
|
+
const BLOCKQUOTE_TRIM_LEFT_MULTILINE_R = /^ *> ?/gm;
|
|
143
|
+
const BLOCKQUOTE_ALERT_R = /^(?:\[!([^\]]*)\]\n)?([\s\S]*)/;
|
|
144
|
+
const BREAK_LINE_R = /^ {2,}\n/;
|
|
145
|
+
const BREAK_THEMATIC_R = /^(?:( *[-*_])){3,} *(?:\n *)+\n/;
|
|
146
|
+
const CODE_BLOCK_FENCED_R = /^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/;
|
|
147
|
+
const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/;
|
|
148
|
+
const CODE_INLINE_R = /^(`+)((?:\\`|(?!\1)`|[^`])+)\1/;
|
|
149
|
+
const CONSECUTIVE_NEWLINE_R = /^(?:\n *)*\n/;
|
|
150
|
+
const CR_NEWLINE_R = /\r\n?/g;
|
|
151
|
+
const FOOTNOTE_R = /^\[\^([^\]]+)](:(.*)((\n+ {4,}.*)|(\n(?!\[\^).+))*)/;
|
|
152
|
+
const FOOTNOTE_REFERENCE_R = /^\[\^([^\]]+)]/;
|
|
153
|
+
const FORMFEED_R = /\f/g;
|
|
154
|
+
const FRONT_MATTER_R = /^---[ \t]*\n(.|\n)*\n---[ \t]*\n/;
|
|
155
|
+
const GFM_TASK_R = /^\s*?\[(x|\s)\]/;
|
|
156
|
+
const HEADING_R = /^ *(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/;
|
|
157
|
+
const HEADING_ATX_COMPLIANT_R = /^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/;
|
|
158
|
+
const HEADING_SETEXT_R = /^([^\n]+)\n *(=|-){3,} *\n/;
|
|
159
|
+
const HTML_BLOCK_ELEMENT_R = /^ *(?!<[a-zA-Z][^ >/]* ?\/>)<([a-zA-Z][^ >/]*) ?((?:[^>]*[^/])?)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/i;
|
|
160
|
+
const HTML_CHAR_CODE_R = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi;
|
|
161
|
+
const HTML_COMMENT_R = /^<!--[\s\S]*?(?:-->)/;
|
|
162
|
+
const HTML_CUSTOM_ATTR_R = /^(data|aria|x)-[a-z_][a-z\d_.-]*$/;
|
|
163
|
+
const HTML_SELF_CLOSING_ELEMENT_R = /^ *<([a-zA-Z][a-zA-Z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i;
|
|
164
|
+
const CUSTOM_COMPONENT_R = /^ *<([A-Z][a-zA-Z0-9]*)(?:\s+((?:<.*?>|[^>])*))?>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/;
|
|
165
|
+
const INTERPOLATION_R = /^\{.*\}$/;
|
|
166
|
+
const LINK_AUTOLINK_BARE_URL_R = /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/;
|
|
167
|
+
const LINK_AUTOLINK_MAILTO_R = /^<([^ >]+@[^ >]+)>/;
|
|
168
|
+
const LINK_AUTOLINK_R = /^<([^ >]+:\/[^ >]+)>/;
|
|
169
|
+
const CAPTURE_LETTER_AFTER_HYPHEN = /-([a-z])?/gi;
|
|
170
|
+
const NP_TABLE_R = /^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/;
|
|
171
|
+
const PARAGRAPH_R = /^[^\n]+(?: \n|\n{2,})/;
|
|
172
|
+
const REFERENCE_IMAGE_OR_LINK = /^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/;
|
|
173
|
+
const REFERENCE_IMAGE_R = /^!\[([^\]]*)\] ?\[([^\]]*)\]/;
|
|
174
|
+
const REFERENCE_LINK_R = /^\[([^\]]*)\] ?\[([^\]]*)\]/;
|
|
175
|
+
const SHOULD_RENDER_AS_BLOCK_R = /(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/;
|
|
176
|
+
const TAB_R = /\t/g;
|
|
177
|
+
const TABLE_TRIM_PIPES = /(^ *\||\| *$)/g;
|
|
178
|
+
const TABLE_CENTER_ALIGN = /^ *:-+: *$/;
|
|
179
|
+
const TABLE_LEFT_ALIGN = /^ *:-+ *$/;
|
|
180
|
+
const TABLE_RIGHT_ALIGN = /^ *-+: *$/;
|
|
181
|
+
const LOOKAHEAD = (double) => `(?=[\\s\\S]+?\\1${double ? "\\1" : ""})`;
|
|
182
|
+
const INLINE_SKIP_R = "((?:\\[.*?\\][([].*?[)\\]]|<.*?>(?:.*?<.*?>)?|`.*?`|\\\\\\1|[\\s\\S])+?)";
|
|
183
|
+
const TEXT_BOLD_R = new RegExp(
|
|
184
|
+
`^([*_])\\1${LOOKAHEAD(1)}${INLINE_SKIP_R}\\1\\1(?!\\1)`
|
|
185
|
+
);
|
|
186
|
+
const TEXT_EMPHASIZED_R = new RegExp(
|
|
187
|
+
`^([*_])${LOOKAHEAD(0)}${INLINE_SKIP_R}\\1(?!\\1)`
|
|
188
|
+
);
|
|
189
|
+
const TEXT_MARKED_R = new RegExp(`^(==)${LOOKAHEAD(0)}${INLINE_SKIP_R}\\1`);
|
|
190
|
+
const TEXT_STRIKETHROUGHED_R = new RegExp(
|
|
191
|
+
`^(~~)${LOOKAHEAD(0)}${INLINE_SKIP_R}\\1`
|
|
192
|
+
);
|
|
193
|
+
const SHORTCODE_R = /^(:[a-zA-Z0-9-_]+:)/;
|
|
194
|
+
const TEXT_ESCAPED_R = /^\\([^0-9A-Za-z\s])/;
|
|
195
|
+
const UNESCAPE_R = /\\([^0-9A-Za-z\s])/g;
|
|
196
|
+
const TEXT_PLAIN_R = /^[\s\S](?:(?! \n|[0-9]\.|http)[^=*_~\-\n:<`\\\[!])*/;
|
|
197
|
+
const TRIM_STARTING_NEWLINES = /^\n+/;
|
|
198
|
+
const HTML_LEFT_TRIM_AMOUNT_R = /^([ \t]*)/;
|
|
199
|
+
const ORDERED = 1;
|
|
200
|
+
const UNORDERED = 2;
|
|
201
|
+
const LIST_LOOKBEHIND_R = /(?:^|\n)( *)$/;
|
|
202
|
+
const ORDERED_LIST_BULLET = "(?:\\d+\\.)";
|
|
203
|
+
const UNORDERED_LIST_BULLET = "(?:[*+-])";
|
|
204
|
+
const generateListItemPrefix = (type) => {
|
|
205
|
+
return "( *)(" + (type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET) + ") +";
|
|
206
|
+
};
|
|
207
|
+
const ORDERED_LIST_ITEM_PREFIX = generateListItemPrefix(ORDERED);
|
|
208
|
+
const UNORDERED_LIST_ITEM_PREFIX = generateListItemPrefix(UNORDERED);
|
|
209
|
+
const generateListItemPrefixRegex = (type) => {
|
|
210
|
+
return new RegExp(
|
|
211
|
+
"^" + (type === ORDERED ? ORDERED_LIST_ITEM_PREFIX : UNORDERED_LIST_ITEM_PREFIX)
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
const ORDERED_LIST_ITEM_PREFIX_R = generateListItemPrefixRegex(ORDERED);
|
|
215
|
+
const UNORDERED_LIST_ITEM_PREFIX_R = generateListItemPrefixRegex(UNORDERED);
|
|
216
|
+
const generateListItemRegex = (type) => {
|
|
217
|
+
return new RegExp(
|
|
218
|
+
"^" + (type === ORDERED ? ORDERED_LIST_ITEM_PREFIX : UNORDERED_LIST_ITEM_PREFIX) + "[^\\n]*(?:\\n(?!\\1" + (type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET) + " )[^\\n]*)*(\\n|$)",
|
|
219
|
+
"gm"
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
const ORDERED_LIST_ITEM_R = generateListItemRegex(ORDERED);
|
|
223
|
+
const UNORDERED_LIST_ITEM_R = generateListItemRegex(UNORDERED);
|
|
224
|
+
const generateListRegex = (type) => {
|
|
225
|
+
const bullet = type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET;
|
|
226
|
+
return new RegExp(
|
|
227
|
+
"^( *)(" + bullet + ") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1" + bullet + " (?!" + bullet + " ))\\n*|\\s*\\n*$)"
|
|
228
|
+
);
|
|
229
|
+
};
|
|
230
|
+
const ORDERED_LIST_R = generateListRegex(ORDERED);
|
|
231
|
+
const UNORDERED_LIST_R = generateListRegex(UNORDERED);
|
|
232
|
+
const generateListRule = (type, factory) => {
|
|
233
|
+
const ordered = type === ORDERED;
|
|
234
|
+
const LIST_R = ordered ? ORDERED_LIST_R : UNORDERED_LIST_R;
|
|
235
|
+
const LIST_ITEM_R = ordered ? ORDERED_LIST_ITEM_R : UNORDERED_LIST_ITEM_R;
|
|
236
|
+
const LIST_ITEM_PREFIX_R = ordered ? ORDERED_LIST_ITEM_PREFIX_R : UNORDERED_LIST_ITEM_PREFIX_R;
|
|
237
|
+
return {
|
|
238
|
+
_qualify: (source) => LIST_ITEM_PREFIX_R.test(source),
|
|
239
|
+
_match: allowInline((source, state) => {
|
|
240
|
+
const isStartOfLine = LIST_LOOKBEHIND_R.exec(state.prevCapture ?? "");
|
|
241
|
+
const isListAllowed = state.list ?? (!state.inline && !state.simple);
|
|
242
|
+
if (isStartOfLine && isListAllowed) {
|
|
243
|
+
source = isStartOfLine[1] + source;
|
|
244
|
+
return LIST_R.exec(source);
|
|
245
|
+
} else {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
}),
|
|
249
|
+
_order: Priority.HIGH,
|
|
250
|
+
_parse(capture, parse, state) {
|
|
251
|
+
const bullet = capture[2];
|
|
252
|
+
const start = ordered ? +bullet : void 0;
|
|
253
|
+
const items = capture[0].replace(BLOCK_END_R, "\n").match(LIST_ITEM_R);
|
|
254
|
+
if (!items) return { items: [], ordered, start };
|
|
255
|
+
let lastItemWasAParagraph = false;
|
|
256
|
+
const itemContent = items.map((item, i) => {
|
|
257
|
+
const spaceMatch = LIST_ITEM_PREFIX_R.exec(item);
|
|
258
|
+
if (!spaceMatch) return [];
|
|
259
|
+
const space = spaceMatch[0].length;
|
|
260
|
+
const spaceRegex = new RegExp("^ {1," + space + "}", "gm");
|
|
261
|
+
const content = item.replace(spaceRegex, "").replace(LIST_ITEM_PREFIX_R, "");
|
|
262
|
+
const isLastItem = i === items.length - 1;
|
|
263
|
+
const containsBlocks = content.indexOf("\n\n") !== -1;
|
|
264
|
+
const thisItemIsAParagraph = containsBlocks || isLastItem && lastItemWasAParagraph;
|
|
265
|
+
lastItemWasAParagraph = thisItemIsAParagraph;
|
|
266
|
+
const oldStateInline = state.inline;
|
|
267
|
+
const oldStateList = state.list;
|
|
268
|
+
state.list = true;
|
|
269
|
+
let adjustedContent;
|
|
270
|
+
if (thisItemIsAParagraph) {
|
|
271
|
+
state.inline = false;
|
|
272
|
+
adjustedContent = trimEnd(content) + "\n\n";
|
|
273
|
+
} else {
|
|
274
|
+
state.inline = true;
|
|
275
|
+
adjustedContent = trimEnd(content);
|
|
276
|
+
}
|
|
277
|
+
const result = parse(adjustedContent, state);
|
|
278
|
+
state.inline = oldStateInline;
|
|
279
|
+
state.list = oldStateList;
|
|
280
|
+
return result;
|
|
281
|
+
});
|
|
282
|
+
return {
|
|
283
|
+
items: itemContent,
|
|
284
|
+
ordered,
|
|
285
|
+
start
|
|
286
|
+
};
|
|
287
|
+
},
|
|
288
|
+
_render(node, _output, state = {}) {
|
|
289
|
+
const Tag = node.ordered ? "ol" : "ul";
|
|
290
|
+
const props = { key: state.key };
|
|
291
|
+
if (node.ordered && node.start != null) props.start = node.start;
|
|
292
|
+
if (factory) {
|
|
293
|
+
return factory(
|
|
294
|
+
Tag,
|
|
295
|
+
props,
|
|
296
|
+
...node.items.map(
|
|
297
|
+
(item, i) => factory("li", { key: i }, _output(item, state))
|
|
298
|
+
)
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
302
|
+
Tag,
|
|
303
|
+
{
|
|
304
|
+
start: node.type === RuleType.orderedList ? node.start : void 0,
|
|
305
|
+
children: node.items.map((item, i) => {
|
|
306
|
+
return /* @__PURE__ */ jsxRuntime.jsx("li", { children: _output(item, state) }, i);
|
|
307
|
+
})
|
|
308
|
+
},
|
|
309
|
+
state.key
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
const LINK_INSIDE = "(?:\\[[^\\[\\]]*(?:\\[[^\\[\\]]*\\][^\\[\\]]*)*\\]|[^\\[\\]])*";
|
|
315
|
+
const LINK_HREF_AND_TITLE = `\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['"]([\\s\\S]*?)['"])?\\s*`;
|
|
316
|
+
const LINK_R = new RegExp(
|
|
317
|
+
"^\\[(" + LINK_INSIDE + ")\\]\\(" + LINK_HREF_AND_TITLE + "\\)"
|
|
318
|
+
);
|
|
319
|
+
const IMAGE_R = /^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/;
|
|
320
|
+
const trimEnd = (str) => {
|
|
321
|
+
let end = str.length;
|
|
322
|
+
while (end > 0 && str[end - 1] <= " ") end--;
|
|
323
|
+
return str.slice(0, end);
|
|
324
|
+
};
|
|
325
|
+
const startsWith = (str, prefix) => {
|
|
326
|
+
return str.startsWith(prefix);
|
|
327
|
+
};
|
|
328
|
+
const qualifies = (source, state, qualify) => {
|
|
329
|
+
if (Array.isArray(qualify)) {
|
|
330
|
+
for (let i = 0; i < qualify.length; i++) {
|
|
331
|
+
if (startsWith(source, qualify[i])) return true;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
return qualify(source, state);
|
|
336
|
+
};
|
|
337
|
+
const unquote = (str) => {
|
|
338
|
+
const first = str[0];
|
|
339
|
+
if ((first === '"' || first === "'") && str.length >= 2 && str[str.length - 1] === first) {
|
|
340
|
+
return str.slice(1, -1);
|
|
341
|
+
}
|
|
342
|
+
return str;
|
|
343
|
+
};
|
|
344
|
+
const slugify = (str) => str.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();
|
|
345
|
+
const parseTableAlignCapture = (alignCapture) => {
|
|
346
|
+
if (TABLE_RIGHT_ALIGN.test(alignCapture)) {
|
|
347
|
+
return "right";
|
|
348
|
+
} else if (TABLE_CENTER_ALIGN.test(alignCapture)) {
|
|
349
|
+
return "center";
|
|
350
|
+
} else if (TABLE_LEFT_ALIGN.test(alignCapture)) {
|
|
351
|
+
return "left";
|
|
352
|
+
}
|
|
353
|
+
return "left";
|
|
354
|
+
};
|
|
355
|
+
const parseTableRow = (source, parse, state, tableOutput) => {
|
|
356
|
+
const start = performance.now();
|
|
357
|
+
const prevInTable = state.inTable;
|
|
358
|
+
state.inTable = true;
|
|
359
|
+
let cells = [[]];
|
|
360
|
+
let acc = "";
|
|
361
|
+
const flush = () => {
|
|
362
|
+
if (!acc) return;
|
|
363
|
+
const cell = cells[cells.length - 1];
|
|
364
|
+
cell.push.apply(cell, parse(acc, state));
|
|
365
|
+
acc = "";
|
|
366
|
+
};
|
|
367
|
+
source.trim().split(/(`[^`]*`|\\\||\|)/).filter(Boolean).forEach((fragment, i, arr) => {
|
|
368
|
+
if (fragment.trim() === "|") {
|
|
369
|
+
flush();
|
|
370
|
+
if (tableOutput) {
|
|
371
|
+
if (i !== 0 && i !== arr.length - 1) {
|
|
372
|
+
cells.push([]);
|
|
373
|
+
}
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
acc += fragment;
|
|
378
|
+
});
|
|
379
|
+
flush();
|
|
380
|
+
state.inTable = prevInTable;
|
|
381
|
+
const duration = performance.now() - start;
|
|
382
|
+
if (duration > 1) {
|
|
383
|
+
console.log(
|
|
384
|
+
`parseTableRow: ${duration.toFixed(3)}ms, source length: ${source.length}, cells count: ${cells.length}`
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
return cells;
|
|
388
|
+
};
|
|
389
|
+
const parseTableAlign = (source) => {
|
|
390
|
+
const alignText = source.replace(TABLE_TRIM_PIPES, "").split("|");
|
|
391
|
+
return alignText.map(parseTableAlignCapture);
|
|
392
|
+
};
|
|
393
|
+
const parseTableCells = (source, parse, state) => {
|
|
394
|
+
const start = performance.now();
|
|
395
|
+
const rowsText = source.trim().split("\n");
|
|
396
|
+
const result = rowsText.map((rowText) => {
|
|
397
|
+
return parseTableRow(rowText, parse, state, true);
|
|
398
|
+
});
|
|
399
|
+
const duration = performance.now() - start;
|
|
400
|
+
if (duration > 1) {
|
|
401
|
+
console.log(
|
|
402
|
+
`parseTableCells: ${duration.toFixed(3)}ms, source length: ${source.length}, rows count: ${rowsText.length}`
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
return result;
|
|
406
|
+
};
|
|
407
|
+
const parseTable = (capture, parse, state) => {
|
|
408
|
+
state.inline = true;
|
|
409
|
+
const align = capture[2] ? parseTableAlign(capture[2]) : [];
|
|
410
|
+
const cells = capture[3] ? parseTableCells(capture[3], parse, state) : [];
|
|
411
|
+
const header = parseTableRow(capture[1], parse, state, !!cells.length);
|
|
412
|
+
state.inline = false;
|
|
413
|
+
return cells.length ? {
|
|
414
|
+
align,
|
|
415
|
+
cells,
|
|
416
|
+
header,
|
|
417
|
+
type: RuleType.table
|
|
418
|
+
} : {
|
|
419
|
+
children: header.flat(),
|
|
420
|
+
type: RuleType.paragraph
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
const getTableStyle = (node, colIndex) => node.align[colIndex] == null ? {} : {
|
|
424
|
+
textAlign: node.align[colIndex]
|
|
425
|
+
};
|
|
426
|
+
const normalizeAttributeKey = (key) => {
|
|
427
|
+
const hyphenIndex = key.indexOf("-");
|
|
428
|
+
if (hyphenIndex !== -1 && key.match(HTML_CUSTOM_ATTR_R) === null) {
|
|
429
|
+
key = key.replace(CAPTURE_LETTER_AFTER_HYPHEN, (_, letter) => {
|
|
430
|
+
return letter.toUpperCase();
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
return key;
|
|
434
|
+
};
|
|
435
|
+
const parseStyleAttribute = (styleString) => {
|
|
436
|
+
const start = performance.now();
|
|
437
|
+
const styles = [];
|
|
438
|
+
let buffer = "";
|
|
439
|
+
let inUrl = false;
|
|
440
|
+
let inQuotes = false;
|
|
441
|
+
let quoteChar = "";
|
|
442
|
+
if (!styleString) return styles;
|
|
443
|
+
for (let i = 0; i < styleString.length; i++) {
|
|
444
|
+
const char = styleString[i];
|
|
445
|
+
if ((char === '"' || char === "'") && !inUrl) {
|
|
446
|
+
if (!inQuotes) {
|
|
447
|
+
inQuotes = true;
|
|
448
|
+
quoteChar = char;
|
|
449
|
+
} else if (char === quoteChar) {
|
|
450
|
+
inQuotes = false;
|
|
451
|
+
quoteChar = "";
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (char === "(" && buffer.endsWith("url")) {
|
|
455
|
+
inUrl = true;
|
|
456
|
+
} else if (char === ")" && inUrl) {
|
|
457
|
+
inUrl = false;
|
|
458
|
+
}
|
|
459
|
+
if (char === ";" && !inQuotes && !inUrl) {
|
|
460
|
+
const declaration2 = buffer.trim();
|
|
461
|
+
if (declaration2) {
|
|
462
|
+
const colonIndex = declaration2.indexOf(":");
|
|
463
|
+
if (colonIndex > 0) {
|
|
464
|
+
const key = declaration2.slice(0, colonIndex).trim();
|
|
465
|
+
const value = declaration2.slice(colonIndex + 1).trim();
|
|
466
|
+
styles.push([key, value]);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
buffer = "";
|
|
470
|
+
} else {
|
|
471
|
+
buffer += char;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const declaration = buffer.trim();
|
|
475
|
+
if (declaration) {
|
|
476
|
+
const colonIndex = declaration.indexOf(":");
|
|
477
|
+
if (colonIndex > 0) {
|
|
478
|
+
const key = declaration.slice(0, colonIndex).trim();
|
|
479
|
+
const value = declaration.slice(colonIndex + 1).trim();
|
|
480
|
+
styles.push([key, value]);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const duration = performance.now() - start;
|
|
484
|
+
if (duration > 1) {
|
|
485
|
+
console.log(
|
|
486
|
+
`parseStyleAttribute: ${duration.toFixed(3)}ms, styleString length: ${styleString.length}, styles count: ${styles.length}`
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
return styles;
|
|
490
|
+
};
|
|
491
|
+
const trimLeadingWhitespaceOutsideFences = (text, whitespace) => {
|
|
492
|
+
const start = performance.now();
|
|
493
|
+
if (!whitespace) return text;
|
|
494
|
+
const lines = text.split("\n");
|
|
495
|
+
let inFence = false;
|
|
496
|
+
let fenceToken = null;
|
|
497
|
+
const isFenceLine = (line) => line.match(/^\s*(`{3,}|~{3,})/);
|
|
498
|
+
const maybeToggleFence = (line) => {
|
|
499
|
+
const m = isFenceLine(line);
|
|
500
|
+
if (!m) return;
|
|
501
|
+
const token = m[1];
|
|
502
|
+
if (!inFence) {
|
|
503
|
+
inFence = true;
|
|
504
|
+
fenceToken = token;
|
|
505
|
+
} else if (fenceToken && line.includes(fenceToken)) {
|
|
506
|
+
inFence = false;
|
|
507
|
+
fenceToken = null;
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
const out = lines.map((line) => {
|
|
511
|
+
const fenceMatch = isFenceLine(line);
|
|
512
|
+
if (fenceMatch) {
|
|
513
|
+
const trimmedFenceLine = line.startsWith(whitespace) ? line.slice(whitespace.length) : line;
|
|
514
|
+
maybeToggleFence(line);
|
|
515
|
+
return trimmedFenceLine;
|
|
516
|
+
}
|
|
517
|
+
if (inFence) {
|
|
518
|
+
return line;
|
|
519
|
+
}
|
|
520
|
+
return line.startsWith(whitespace) ? line.slice(whitespace.length) : line;
|
|
521
|
+
});
|
|
522
|
+
const result = out.join("\n");
|
|
523
|
+
const duration = performance.now() - start;
|
|
524
|
+
if (duration > 1) {
|
|
525
|
+
console.log(
|
|
526
|
+
`trimLeadingWhitespaceOutsideFences: ${duration.toFixed(3)}ms, text length: ${text.length}, lines count: ${lines.length}`
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
return result;
|
|
530
|
+
};
|
|
531
|
+
const attributeValueToJSXPropValue = (tag, key, value, sanitizeUrlFn) => {
|
|
532
|
+
if (key === "style") {
|
|
533
|
+
return parseStyleAttribute(value).reduce(
|
|
534
|
+
(styles, [key2, value2]) => {
|
|
535
|
+
const camelCasedKey = key2.replace(
|
|
536
|
+
/(-[a-z])/g,
|
|
537
|
+
(substr) => substr[1].toUpperCase()
|
|
538
|
+
);
|
|
539
|
+
styles[camelCasedKey] = sanitizeUrlFn(
|
|
540
|
+
value2,
|
|
541
|
+
tag,
|
|
542
|
+
key2
|
|
543
|
+
);
|
|
544
|
+
return styles;
|
|
545
|
+
},
|
|
546
|
+
{}
|
|
547
|
+
);
|
|
548
|
+
} else if (ATTRIBUTES_TO_SANITIZE.indexOf(key) !== -1) {
|
|
549
|
+
return sanitizeUrlFn(unescape(value), tag, key);
|
|
550
|
+
} else if (value.match(INTERPOLATION_R)) {
|
|
551
|
+
value = unescape(value.slice(1, value.length - 1));
|
|
552
|
+
}
|
|
553
|
+
if (value === "true") {
|
|
554
|
+
return true;
|
|
555
|
+
} else if (value === "false") {
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
return value;
|
|
559
|
+
};
|
|
560
|
+
const normalizeWhitespace = (source) => {
|
|
561
|
+
const start = performance.now();
|
|
562
|
+
const result = source.replace(CR_NEWLINE_R, "\n").replace(FORMFEED_R, "").replace(TAB_R, " ");
|
|
563
|
+
const duration = performance.now() - start;
|
|
564
|
+
if (duration > 1) {
|
|
565
|
+
console.log(
|
|
566
|
+
`normalizeWhitespace: ${duration.toFixed(3)}ms, source length: ${source.length}`
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
return result;
|
|
570
|
+
};
|
|
571
|
+
const parserFor = (rules) => {
|
|
572
|
+
const start = performance.now();
|
|
573
|
+
var ruleList = Object.keys(rules);
|
|
574
|
+
if (define_process_env_default.NODE_ENV !== "production") {
|
|
575
|
+
ruleList.forEach((type) => {
|
|
576
|
+
const order = rules[type]._order;
|
|
577
|
+
if (typeof order !== "number" || !isFinite(order)) {
|
|
578
|
+
console.warn(
|
|
579
|
+
"intlayer: Invalid order for rule `" + type + "`: " + order
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
ruleList.sort((a, b) => {
|
|
585
|
+
return rules[a]._order - rules[b]._order || (a < b ? -1 : 1);
|
|
586
|
+
});
|
|
587
|
+
const nestedParse = (source, state = {}) => {
|
|
588
|
+
const parseStart = performance.now();
|
|
589
|
+
var result = [];
|
|
590
|
+
state.prevCapture = state.prevCapture || "";
|
|
591
|
+
if (source.trim()) {
|
|
592
|
+
while (source) {
|
|
593
|
+
var i = 0;
|
|
594
|
+
while (i < ruleList.length) {
|
|
595
|
+
var ruleType = ruleList[i];
|
|
596
|
+
var rule = rules[ruleType];
|
|
597
|
+
if (rule._qualify && !qualifies(source, state, rule._qualify)) {
|
|
598
|
+
i++;
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
const matchStart = performance.now();
|
|
602
|
+
var capture = rule._match(source, state);
|
|
603
|
+
const matchDuration = performance.now() - matchStart;
|
|
604
|
+
if (matchDuration > 1) {
|
|
605
|
+
console.log(
|
|
606
|
+
`${ruleType}._match: ${matchDuration.toFixed(3)}ms, source length: ${source.length}`
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
if (capture && capture[0]) {
|
|
610
|
+
source = source.substring(capture[0].length);
|
|
611
|
+
const ruleParseStart = performance.now();
|
|
612
|
+
const parsedAny = rule._parse(capture, nestedParse, state);
|
|
613
|
+
const ruleParseDuration = performance.now() - ruleParseStart;
|
|
614
|
+
if (ruleParseDuration > 1) {
|
|
615
|
+
console.log(
|
|
616
|
+
`${ruleType}._parse: ${ruleParseDuration.toFixed(3)}ms, capture length: ${capture[0].length}`
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
state.prevCapture += capture[0];
|
|
620
|
+
if (!parsedAny.type)
|
|
621
|
+
parsedAny.type = ruleType;
|
|
622
|
+
result.push(parsedAny);
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
i++;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
state.prevCapture = "";
|
|
630
|
+
const parseDuration = performance.now() - parseStart;
|
|
631
|
+
if (parseDuration > 1) {
|
|
632
|
+
console.log(
|
|
633
|
+
`nestedParse: ${parseDuration.toFixed(3)}ms, source length: ${source.length}, result count: ${result.length}`
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
return result;
|
|
637
|
+
};
|
|
638
|
+
const duration = performance.now() - start;
|
|
639
|
+
if (duration > 1) {
|
|
640
|
+
console.log(
|
|
641
|
+
`parserFor: ${duration.toFixed(3)}ms, rules count: ${ruleList.length}`
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
return (source, state) => nestedParse(normalizeWhitespace(source), state);
|
|
645
|
+
};
|
|
646
|
+
const allowInline = (fn) => {
|
|
647
|
+
fn.inline = 1;
|
|
648
|
+
return fn;
|
|
649
|
+
};
|
|
650
|
+
const inlineRegex = (regex) => allowInline((source, state) => {
|
|
651
|
+
if (state.inline) {
|
|
652
|
+
return regex.exec(source);
|
|
653
|
+
} else {
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
const simpleInlineRegex = (regex) => allowInline((source, state) => {
|
|
658
|
+
if (state.inline || state.simple) {
|
|
659
|
+
return regex.exec(source);
|
|
660
|
+
} else {
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
const blockRegex = (regex) => (source, state) => {
|
|
665
|
+
if (state.inline || state.simple) {
|
|
666
|
+
return null;
|
|
667
|
+
} else {
|
|
668
|
+
return regex.exec(source);
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
const anyScopeRegex = (regex) => allowInline(
|
|
672
|
+
(source) => regex.exec(source)
|
|
673
|
+
);
|
|
674
|
+
const SANITIZE_R = /(javascript|vbscript|data(?!:image)):/i;
|
|
675
|
+
const sanitizer = (input) => {
|
|
676
|
+
try {
|
|
677
|
+
const decoded = decodeURIComponent(input).replace(/[^A-Za-z0-9/:]/g, "");
|
|
678
|
+
if (SANITIZE_R.test(decoded)) {
|
|
679
|
+
if (define_process_env_default.NODE_ENV !== "production") {
|
|
680
|
+
console.warn(
|
|
681
|
+
"Input contains an unsafe JavaScript/VBScript/data expression, it will not be rendered.",
|
|
682
|
+
decoded
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
} catch (e) {
|
|
688
|
+
if (define_process_env_default.NODE_ENV !== "production") {
|
|
689
|
+
console.warn(
|
|
690
|
+
"Input could not be decoded due to malformed syntax or characters, it will not be rendered.",
|
|
691
|
+
input
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
return input;
|
|
697
|
+
};
|
|
698
|
+
const unescape = (rawString) => rawString ? rawString.replace(UNESCAPE_R, "$1") : rawString;
|
|
699
|
+
const parseInline = (parse, children, state) => {
|
|
700
|
+
const start = performance.now();
|
|
701
|
+
const isCurrentlyInline = state.inline ?? false;
|
|
702
|
+
const isCurrentlySimple = state.simple ?? false;
|
|
703
|
+
state.inline = true;
|
|
704
|
+
state.simple = true;
|
|
705
|
+
const result = parse(children, state);
|
|
706
|
+
state.inline = isCurrentlyInline;
|
|
707
|
+
state.simple = isCurrentlySimple;
|
|
708
|
+
const duration = performance.now() - start;
|
|
709
|
+
if (duration > 1) {
|
|
710
|
+
console.log(
|
|
711
|
+
`parseInline: ${duration.toFixed(3)}ms, children length: ${children.length}, result count: ${result.length}`
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
return result;
|
|
715
|
+
};
|
|
716
|
+
const parseSimpleInline = (parse, children, state) => {
|
|
717
|
+
const start = performance.now();
|
|
718
|
+
const isCurrentlyInline = state.inline ?? false;
|
|
719
|
+
const isCurrentlySimple = state.simple ?? false;
|
|
720
|
+
state.inline = false;
|
|
721
|
+
state.simple = true;
|
|
722
|
+
const result = parse(children, state);
|
|
723
|
+
state.inline = isCurrentlyInline;
|
|
724
|
+
state.simple = isCurrentlySimple;
|
|
725
|
+
const duration = performance.now() - start;
|
|
726
|
+
if (duration > 1) {
|
|
727
|
+
console.log(
|
|
728
|
+
`parseSimpleInline: ${duration.toFixed(3)}ms, children length: ${children.length}, result count: ${result.length}`
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
return result;
|
|
732
|
+
};
|
|
733
|
+
const parseBlock = (parse, children, state = {}) => {
|
|
734
|
+
const start = performance.now();
|
|
735
|
+
const isCurrentlyInline = state.inline || false;
|
|
736
|
+
state.inline = false;
|
|
737
|
+
const result = parse(children, state);
|
|
738
|
+
state.inline = isCurrentlyInline;
|
|
739
|
+
const duration = performance.now() - start;
|
|
740
|
+
if (duration > 1) {
|
|
741
|
+
console.log(
|
|
742
|
+
`parseBlock: ${duration.toFixed(3)}ms, children length: ${children.length}, result count: ${result.length}`
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
return result;
|
|
746
|
+
};
|
|
747
|
+
const parseCaptureInline = (capture, parse, state) => {
|
|
748
|
+
return {
|
|
749
|
+
children: parseInline(parse, capture[2], state)
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
const captureNothing = () => ({});
|
|
753
|
+
const renderNothing = () => null;
|
|
754
|
+
const reactFor = (render) => (ast, state = {}) => {
|
|
755
|
+
const start = performance.now();
|
|
756
|
+
const patchedRender = (ast2, state2 = {}) => reactFor(render)(ast2, state2);
|
|
757
|
+
if (Array.isArray(ast)) {
|
|
758
|
+
const oldKey = state.key;
|
|
759
|
+
const result2 = [];
|
|
760
|
+
let lastWasString = false;
|
|
761
|
+
for (let i = 0; i < ast.length; i++) {
|
|
762
|
+
state.key = i;
|
|
763
|
+
const nodeOut = patchedRender(ast[i], state);
|
|
764
|
+
const isString = typeof nodeOut === "string";
|
|
765
|
+
if (isString && lastWasString) {
|
|
766
|
+
result2[result2.length - 1] = result2[result2.length - 1] + nodeOut;
|
|
767
|
+
} else if (nodeOut !== null) {
|
|
768
|
+
result2.push(nodeOut);
|
|
769
|
+
}
|
|
770
|
+
lastWasString = isString;
|
|
771
|
+
}
|
|
772
|
+
state.key = oldKey;
|
|
773
|
+
const duration2 = performance.now() - start;
|
|
774
|
+
if (duration2 > 1) {
|
|
775
|
+
console.log(
|
|
776
|
+
`reactFor (array): ${duration2.toFixed(3)}ms, ast length: ${ast.length}`
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
return result2;
|
|
780
|
+
}
|
|
781
|
+
const result = render(
|
|
782
|
+
ast,
|
|
783
|
+
patchedRender,
|
|
784
|
+
state
|
|
785
|
+
);
|
|
786
|
+
const duration = performance.now() - start;
|
|
787
|
+
if (duration > 1) {
|
|
788
|
+
console.log(
|
|
789
|
+
`reactFor (single): ${duration.toFixed(3)}ms, ast type: ${ast.type}`
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
return result;
|
|
793
|
+
};
|
|
794
|
+
const createRenderer = (rules, userRender) => (ast, render, state) => {
|
|
795
|
+
const start = performance.now();
|
|
796
|
+
const renderer = rules[ast.type]._render;
|
|
797
|
+
const result = userRender ? userRender(() => renderer?.(ast, render, state), ast, render, state) : renderer?.(ast, render, state);
|
|
798
|
+
const duration = performance.now() - start;
|
|
799
|
+
if (duration > 1) {
|
|
800
|
+
console.log(
|
|
801
|
+
`createRenderer: ${duration.toFixed(3)}ms, ast type: ${ast.type}, hasUserRender: ${!!userRender}`
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
return result;
|
|
805
|
+
};
|
|
806
|
+
const cx = (...args) => args.filter(Boolean).join(" ");
|
|
807
|
+
const get = (src, path, fb) => {
|
|
808
|
+
let ptr = src;
|
|
809
|
+
const frags = path.split(".");
|
|
810
|
+
while (frags.length) {
|
|
811
|
+
ptr = ptr[frags[0]];
|
|
812
|
+
if (ptr === void 0) break;
|
|
813
|
+
else frags.shift();
|
|
814
|
+
}
|
|
815
|
+
return ptr ?? fb;
|
|
816
|
+
};
|
|
817
|
+
const getTag = (tag, overrides) => {
|
|
818
|
+
const override = get(overrides, tag);
|
|
819
|
+
if (!override) return tag;
|
|
820
|
+
return typeof override === "function" || typeof override === "object" && "render" in override ? override : get(overrides, `${tag}.component`, tag);
|
|
821
|
+
};
|
|
822
|
+
const compiler = (markdown = "", options = {}) => {
|
|
823
|
+
options.overrides = options.overrides ?? {};
|
|
824
|
+
options.namedCodesToUnicode = options.namedCodesToUnicode ? { ...namedCodesToUnicode, ...options.namedCodesToUnicode } : namedCodesToUnicode;
|
|
825
|
+
const slug = options.slugify ?? slugify;
|
|
826
|
+
const sanitize = options.sanitizer ?? sanitizer;
|
|
827
|
+
const createElementFn = options.createElement ?? ReactExports.createElement;
|
|
828
|
+
const NON_PARAGRAPH_BLOCK_SYNTAXES = [
|
|
829
|
+
BLOCKQUOTE_R,
|
|
830
|
+
CODE_BLOCK_FENCED_R,
|
|
831
|
+
CODE_BLOCK_R,
|
|
832
|
+
options.enforceAtxHeadings ? HEADING_ATX_COMPLIANT_R : HEADING_R,
|
|
833
|
+
HEADING_SETEXT_R,
|
|
834
|
+
NP_TABLE_R,
|
|
835
|
+
ORDERED_LIST_R,
|
|
836
|
+
UNORDERED_LIST_R
|
|
837
|
+
];
|
|
838
|
+
const BLOCK_SYNTAXES = [
|
|
839
|
+
...NON_PARAGRAPH_BLOCK_SYNTAXES,
|
|
840
|
+
PARAGRAPH_R,
|
|
841
|
+
HTML_BLOCK_ELEMENT_R,
|
|
842
|
+
HTML_COMMENT_R,
|
|
843
|
+
HTML_SELF_CLOSING_ELEMENT_R,
|
|
844
|
+
CUSTOM_COMPONENT_R
|
|
845
|
+
];
|
|
846
|
+
const containsBlockSyntax = (input) => {
|
|
847
|
+
const cleaned = input.replace(TRIM_STARTING_NEWLINES, "");
|
|
848
|
+
const slice = cleaned.length > 2048 ? cleaned.slice(0, 2048) : cleaned;
|
|
849
|
+
const syntaxes = options.disableParsingRawHTML ? [...NON_PARAGRAPH_BLOCK_SYNTAXES, PARAGRAPH_R, CUSTOM_COMPONENT_R] : BLOCK_SYNTAXES;
|
|
850
|
+
return syntaxes.some((r) => r.test(slice));
|
|
851
|
+
};
|
|
852
|
+
const matchParagraph = (source, state) => {
|
|
853
|
+
if (state.inline || state.simple || state.inHTML && source.indexOf("\n\n") === -1 && state.prevCapture?.indexOf("\n\n") === -1) {
|
|
854
|
+
return null;
|
|
855
|
+
}
|
|
856
|
+
let match = "";
|
|
857
|
+
source.split("\n").every((line) => {
|
|
858
|
+
line += "\n";
|
|
859
|
+
if (NON_PARAGRAPH_BLOCK_SYNTAXES.some((regex) => regex.test(line))) {
|
|
860
|
+
return false;
|
|
861
|
+
}
|
|
862
|
+
match += line;
|
|
863
|
+
return !!line.trim();
|
|
864
|
+
});
|
|
865
|
+
const captured = trimEnd(match);
|
|
866
|
+
if (captured === "") {
|
|
867
|
+
return null;
|
|
868
|
+
}
|
|
869
|
+
return [match, , captured];
|
|
870
|
+
};
|
|
871
|
+
const h = (tag, props, ...children) => {
|
|
872
|
+
const overrideProps = get(
|
|
873
|
+
options.overrides ?? {},
|
|
874
|
+
`${tag}.props`,
|
|
875
|
+
{}
|
|
876
|
+
);
|
|
877
|
+
return createElementFn(
|
|
878
|
+
getTag(tag, options.overrides ?? {}),
|
|
879
|
+
{
|
|
880
|
+
...props,
|
|
881
|
+
...overrideProps,
|
|
882
|
+
className: cx(props?.className, overrideProps.className) ?? void 0
|
|
883
|
+
},
|
|
884
|
+
...children
|
|
885
|
+
);
|
|
886
|
+
};
|
|
887
|
+
const compile = (input) => {
|
|
888
|
+
const start = performance.now();
|
|
889
|
+
const result = input.replace(FRONT_MATTER_R, "");
|
|
890
|
+
let inline = false;
|
|
891
|
+
if (options.forceInline) {
|
|
892
|
+
inline = true;
|
|
893
|
+
} else if (!options.forceBlock) {
|
|
894
|
+
inline = SHOULD_RENDER_AS_BLOCK_R.test(result) === false;
|
|
895
|
+
}
|
|
896
|
+
const arr = emitter(
|
|
897
|
+
parser(
|
|
898
|
+
inline ? result : `${trimEnd(result).replace(TRIM_STARTING_NEWLINES, "")}
|
|
899
|
+
|
|
900
|
+
`,
|
|
901
|
+
{
|
|
902
|
+
inline
|
|
903
|
+
}
|
|
904
|
+
)
|
|
905
|
+
);
|
|
906
|
+
while (typeof arr[arr.length - 1] === "string" && !arr[arr.length - 1].trim()) {
|
|
907
|
+
arr.pop();
|
|
908
|
+
}
|
|
909
|
+
if (options.wrapper === null) {
|
|
910
|
+
const duration2 = performance.now() - start;
|
|
911
|
+
if (duration2 > 1) {
|
|
912
|
+
console.log(
|
|
913
|
+
`compile: ${duration2.toFixed(3)}ms, input length: ${input.length}, inline: ${inline}`
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
return arr;
|
|
917
|
+
}
|
|
918
|
+
const wrapper = options.wrapper ?? (inline ? "span" : "div");
|
|
919
|
+
let jsx3;
|
|
920
|
+
if (arr.length > 1 || options.forceWrapper) {
|
|
921
|
+
jsx3 = arr;
|
|
922
|
+
} else if (arr.length === 1) {
|
|
923
|
+
jsx3 = arr[0];
|
|
924
|
+
if (typeof jsx3 === "string") {
|
|
925
|
+
const duration2 = performance.now() - start;
|
|
926
|
+
if (duration2 > 1) {
|
|
927
|
+
console.log(
|
|
928
|
+
`compile: ${duration2.toFixed(3)}ms, input length: ${input.length}, inline: ${inline}`
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { children: jsx3 }, "outer");
|
|
932
|
+
} else {
|
|
933
|
+
const duration2 = performance.now() - start;
|
|
934
|
+
if (duration2 > 1) {
|
|
935
|
+
console.log(
|
|
936
|
+
`compile: ${duration2.toFixed(3)}ms, input length: ${input.length}, inline: ${inline}`
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
return jsx3;
|
|
940
|
+
}
|
|
941
|
+
} else {
|
|
942
|
+
jsx3 = null;
|
|
943
|
+
}
|
|
944
|
+
const duration = performance.now() - start;
|
|
945
|
+
if (duration > 1) {
|
|
946
|
+
console.log(
|
|
947
|
+
`compile: ${duration.toFixed(3)}ms, input length: ${input.length}, inline: ${inline}`
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
return createElementFn(wrapper, { key: "outer" }, jsx3);
|
|
951
|
+
};
|
|
952
|
+
const attrStringToMap = (tag, str) => {
|
|
953
|
+
const start = performance.now();
|
|
954
|
+
if (!str || !str.trim()) {
|
|
955
|
+
return null;
|
|
956
|
+
}
|
|
957
|
+
const attributes = str.match(ATTR_EXTRACTOR_R);
|
|
958
|
+
if (!attributes) {
|
|
959
|
+
return null;
|
|
960
|
+
}
|
|
961
|
+
const result = attributes.reduce((map, raw) => {
|
|
962
|
+
const delimiterIdx = raw.indexOf("=");
|
|
963
|
+
if (delimiterIdx !== -1) {
|
|
964
|
+
const key = normalizeAttributeKey(raw.slice(0, delimiterIdx)).trim();
|
|
965
|
+
const value = unquote(raw.slice(delimiterIdx + 1).trim());
|
|
966
|
+
const mappedKey = ATTRIBUTE_TO_JSX_PROP_MAP[key] ?? key;
|
|
967
|
+
if (mappedKey === "ref") return map;
|
|
968
|
+
const normalizedValue = map[mappedKey] = attributeValueToJSXPropValue(
|
|
969
|
+
tag,
|
|
970
|
+
key,
|
|
971
|
+
value,
|
|
972
|
+
sanitize
|
|
973
|
+
);
|
|
974
|
+
if (typeof normalizedValue === "string" && (HTML_BLOCK_ELEMENT_R.test(normalizedValue) || HTML_SELF_CLOSING_ELEMENT_R.test(normalizedValue))) {
|
|
975
|
+
map[mappedKey] = compile(normalizedValue.trim());
|
|
976
|
+
}
|
|
977
|
+
} else if (raw !== "style") {
|
|
978
|
+
map[ATTRIBUTE_TO_JSX_PROP_MAP[raw] ?? raw] = true;
|
|
979
|
+
}
|
|
980
|
+
return map;
|
|
981
|
+
}, {});
|
|
982
|
+
const duration = performance.now() - start;
|
|
983
|
+
if (duration > 1) {
|
|
984
|
+
console.log(
|
|
985
|
+
`attrStringToMap: ${duration.toFixed(3)}ms, str length: ${str.length}, attributes count: ${attributes.length}`
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
return result;
|
|
989
|
+
};
|
|
990
|
+
if (define_process_env_default.NODE_ENV !== "production") {
|
|
991
|
+
if (typeof markdown !== "string") {
|
|
992
|
+
throw new Error(`intlayer: the first argument must be
|
|
993
|
+
a string`);
|
|
994
|
+
}
|
|
995
|
+
if (Object.prototype.toString.call(options.overrides) !== "[object Object]") {
|
|
996
|
+
throw new Error(`intlayer: options.overrides (second argument property) must be
|
|
997
|
+
undefined or an object literal with shape:
|
|
998
|
+
{
|
|
999
|
+
htmltagname: {
|
|
1000
|
+
component: string|ReactComponent(optional),
|
|
1001
|
+
props: object(optional)
|
|
1002
|
+
}
|
|
1003
|
+
}`);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const footnotes = [];
|
|
1007
|
+
const refs = {};
|
|
1008
|
+
const rules = {
|
|
1009
|
+
[RuleType.blockQuote]: {
|
|
1010
|
+
_qualify: [">"],
|
|
1011
|
+
_match: blockRegex(BLOCKQUOTE_R),
|
|
1012
|
+
_order: Priority.HIGH,
|
|
1013
|
+
_parse(capture, parse, state) {
|
|
1014
|
+
const start = performance.now();
|
|
1015
|
+
const matchAlert = capture[0].replace(BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, "").match(BLOCKQUOTE_ALERT_R);
|
|
1016
|
+
const alert = matchAlert?.[1];
|
|
1017
|
+
const content = matchAlert?.[2] ?? "";
|
|
1018
|
+
const result = {
|
|
1019
|
+
alert,
|
|
1020
|
+
children: parse(content, state)
|
|
1021
|
+
};
|
|
1022
|
+
const duration = performance.now() - start;
|
|
1023
|
+
if (duration > 1) {
|
|
1024
|
+
console.log(
|
|
1025
|
+
`blockQuote._parse: ${duration.toFixed(3)}ms, capture length: ${capture[0].length}`
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
return result;
|
|
1029
|
+
},
|
|
1030
|
+
_render(node, _output, state = {}) {
|
|
1031
|
+
const start = performance.now();
|
|
1032
|
+
const props = {
|
|
1033
|
+
key: state?.key
|
|
1034
|
+
};
|
|
1035
|
+
if (node.alert) {
|
|
1036
|
+
props.className = "markdown-alert-" + slug(node.alert.toLowerCase(), slugify);
|
|
1037
|
+
node.children.unshift({
|
|
1038
|
+
attrs: {},
|
|
1039
|
+
children: [{ type: RuleType.text, text: node.alert }],
|
|
1040
|
+
noInnerParse: true,
|
|
1041
|
+
type: RuleType.htmlBlock,
|
|
1042
|
+
tag: "header"
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
const result = h(
|
|
1046
|
+
"blockquote",
|
|
1047
|
+
props,
|
|
1048
|
+
_output(node.children, state)
|
|
1049
|
+
);
|
|
1050
|
+
const duration = performance.now() - start;
|
|
1051
|
+
if (duration > 1) {
|
|
1052
|
+
console.log(
|
|
1053
|
+
`blockQuote._render: ${duration.toFixed(3)}ms, children count: ${node.children.length}, has alert: ${!!node.alert}`
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
return result;
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
[RuleType.breakLine]: {
|
|
1060
|
+
_match: anyScopeRegex(BREAK_LINE_R),
|
|
1061
|
+
_order: Priority.HIGH,
|
|
1062
|
+
_parse: captureNothing,
|
|
1063
|
+
_render(_, __, state = {}) {
|
|
1064
|
+
return /* @__PURE__ */ jsxRuntime.jsx("br", {}, state.key);
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
[RuleType.breakThematic]: {
|
|
1068
|
+
_qualify: (source) => {
|
|
1069
|
+
const char = source[0];
|
|
1070
|
+
return char === "-" || char === "*" || char === "_";
|
|
1071
|
+
},
|
|
1072
|
+
_match: blockRegex(BREAK_THEMATIC_R),
|
|
1073
|
+
_order: Priority.HIGH,
|
|
1074
|
+
_parse: captureNothing,
|
|
1075
|
+
_render(_, __, state = {}) {
|
|
1076
|
+
return /* @__PURE__ */ jsxRuntime.jsx("hr", {}, state.key);
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
[RuleType.codeBlock]: {
|
|
1080
|
+
_qualify: [" "],
|
|
1081
|
+
_match: blockRegex(CODE_BLOCK_R),
|
|
1082
|
+
_order: Priority.MAX,
|
|
1083
|
+
_parse(capture) {
|
|
1084
|
+
return {
|
|
1085
|
+
type: RuleType.codeBlock,
|
|
1086
|
+
lang: void 0,
|
|
1087
|
+
text: unescape(trimEnd(capture[0].replace(/^ {4}/gm, "")))
|
|
1088
|
+
};
|
|
1089
|
+
},
|
|
1090
|
+
_render(node, _output, state = {}) {
|
|
1091
|
+
const start = performance.now();
|
|
1092
|
+
const attrs = { ...node.attrs ?? {} };
|
|
1093
|
+
const langClass = node.lang ? `lang-${node.lang}` : "lang-plaintext";
|
|
1094
|
+
attrs.className = attrs.className ? `${attrs.className} ${langClass}` : langClass;
|
|
1095
|
+
if (node.lang && !attrs.lang) attrs.lang = node.lang;
|
|
1096
|
+
const result = h(
|
|
1097
|
+
"pre",
|
|
1098
|
+
{ key: state.key },
|
|
1099
|
+
h("code", attrs, node.text)
|
|
1100
|
+
);
|
|
1101
|
+
const duration = performance.now() - start;
|
|
1102
|
+
if (duration > 1) {
|
|
1103
|
+
console.log(
|
|
1104
|
+
`codeBlock._render: ${duration.toFixed(3)}ms, text length: ${node.text.length}, lang: ${node.lang || "none"}`
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
return result;
|
|
1108
|
+
}
|
|
1109
|
+
},
|
|
1110
|
+
[RuleType.codeFenced]: {
|
|
1111
|
+
_qualify: ["```", "~~~"],
|
|
1112
|
+
_match: blockRegex(CODE_BLOCK_FENCED_R),
|
|
1113
|
+
_order: Priority.MAX,
|
|
1114
|
+
_parse(capture) {
|
|
1115
|
+
const rawText = capture[4];
|
|
1116
|
+
const text = rawText;
|
|
1117
|
+
return {
|
|
1118
|
+
// if capture[3] it's additional metadata
|
|
1119
|
+
attrs: attrStringToMap("code", capture[3] ?? ""),
|
|
1120
|
+
lang: capture[2] || void 0,
|
|
1121
|
+
text,
|
|
1122
|
+
type: RuleType.codeBlock
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
},
|
|
1126
|
+
[RuleType.codeInline]: {
|
|
1127
|
+
_qualify: ["`"],
|
|
1128
|
+
_match: simpleInlineRegex(CODE_INLINE_R),
|
|
1129
|
+
_order: Priority.LOW,
|
|
1130
|
+
_parse(capture) {
|
|
1131
|
+
return {
|
|
1132
|
+
text: unescape(capture[2])
|
|
1133
|
+
};
|
|
1134
|
+
},
|
|
1135
|
+
_render(node, _output, state = {}) {
|
|
1136
|
+
const start = performance.now();
|
|
1137
|
+
const result = h("code", { key: state.key }, node.text);
|
|
1138
|
+
const duration = performance.now() - start;
|
|
1139
|
+
if (duration > 1) {
|
|
1140
|
+
console.log(
|
|
1141
|
+
`codeInline._render: ${duration.toFixed(3)}ms, text length: ${node.text.length}`
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
return result;
|
|
1145
|
+
}
|
|
1146
|
+
},
|
|
1147
|
+
/**
|
|
1148
|
+
* footnotes are emitted at the end of compilation in a special <footer> block
|
|
1149
|
+
*/
|
|
1150
|
+
[RuleType.footnote]: {
|
|
1151
|
+
_qualify: ["[^"],
|
|
1152
|
+
_match: blockRegex(FOOTNOTE_R),
|
|
1153
|
+
_order: Priority.MAX,
|
|
1154
|
+
_parse(capture) {
|
|
1155
|
+
footnotes.push({
|
|
1156
|
+
footnote: capture[2],
|
|
1157
|
+
identifier: capture[1]
|
|
1158
|
+
});
|
|
1159
|
+
return {};
|
|
1160
|
+
},
|
|
1161
|
+
_render: renderNothing
|
|
1162
|
+
},
|
|
1163
|
+
[RuleType.footnoteReference]: {
|
|
1164
|
+
_qualify: ["[^"],
|
|
1165
|
+
_match: inlineRegex(FOOTNOTE_REFERENCE_R),
|
|
1166
|
+
_order: Priority.HIGH,
|
|
1167
|
+
_parse(capture) {
|
|
1168
|
+
return {
|
|
1169
|
+
target: `#${slug(capture[1], slugify)}`,
|
|
1170
|
+
text: capture[1]
|
|
1171
|
+
};
|
|
1172
|
+
},
|
|
1173
|
+
_render(node, _output, state = {}) {
|
|
1174
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1175
|
+
"a",
|
|
1176
|
+
{
|
|
1177
|
+
href: sanitize(node.target, "a", "href") ?? void 0,
|
|
1178
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("sup", { children: node.text }, state.key)
|
|
1179
|
+
},
|
|
1180
|
+
state.key
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
},
|
|
1184
|
+
[RuleType.gfmTask]: {
|
|
1185
|
+
_qualify: ["[ ]", "[x]"],
|
|
1186
|
+
_match: inlineRegex(GFM_TASK_R),
|
|
1187
|
+
_order: Priority.HIGH,
|
|
1188
|
+
_parse(capture) {
|
|
1189
|
+
return {
|
|
1190
|
+
completed: capture[1].toLowerCase() === "x"
|
|
1191
|
+
};
|
|
1192
|
+
},
|
|
1193
|
+
_render(node, _output, state = {}) {
|
|
1194
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1195
|
+
"input",
|
|
1196
|
+
{
|
|
1197
|
+
checked: node.completed,
|
|
1198
|
+
readOnly: true,
|
|
1199
|
+
type: "checkbox"
|
|
1200
|
+
},
|
|
1201
|
+
state.key
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
},
|
|
1205
|
+
[RuleType.heading]: {
|
|
1206
|
+
_qualify: ["#"],
|
|
1207
|
+
_match: blockRegex(
|
|
1208
|
+
options.enforceAtxHeadings ? HEADING_ATX_COMPLIANT_R : HEADING_R
|
|
1209
|
+
),
|
|
1210
|
+
_order: Priority.HIGH,
|
|
1211
|
+
_parse(capture, parse, state) {
|
|
1212
|
+
const start = performance.now();
|
|
1213
|
+
const result = {
|
|
1214
|
+
children: parseInline(parse, capture[2], state),
|
|
1215
|
+
id: slug(capture[2], slugify),
|
|
1216
|
+
level: capture[1].length
|
|
1217
|
+
};
|
|
1218
|
+
const duration = performance.now() - start;
|
|
1219
|
+
if (duration > 1) {
|
|
1220
|
+
console.log(
|
|
1221
|
+
`heading._parse: ${duration.toFixed(3)}ms, capture length: ${capture[0].length}, level: ${capture[1].length}`
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
return result;
|
|
1225
|
+
},
|
|
1226
|
+
_render(node, _output, state = {}) {
|
|
1227
|
+
const start = performance.now();
|
|
1228
|
+
const result = h(
|
|
1229
|
+
`h${node.level}`,
|
|
1230
|
+
{ id: node.id, key: state.key },
|
|
1231
|
+
_output(node.children, state)
|
|
1232
|
+
);
|
|
1233
|
+
const duration = performance.now() - start;
|
|
1234
|
+
if (duration > 1) {
|
|
1235
|
+
console.log(
|
|
1236
|
+
`heading._render: ${duration.toFixed(3)}ms, level: ${node.level}, children count: ${node.children.length}, id: ${node.id}`
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1239
|
+
return result;
|
|
1240
|
+
}
|
|
1241
|
+
},
|
|
1242
|
+
[RuleType.headingSetext]: {
|
|
1243
|
+
_match: blockRegex(HEADING_SETEXT_R),
|
|
1244
|
+
_order: Priority.MAX,
|
|
1245
|
+
_parse(capture, parse, state) {
|
|
1246
|
+
return {
|
|
1247
|
+
children: parseInline(parse, capture[1], state),
|
|
1248
|
+
level: capture[2] === "=" ? 1 : 2,
|
|
1249
|
+
type: RuleType.heading
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
},
|
|
1253
|
+
[RuleType.htmlBlock]: {
|
|
1254
|
+
_qualify: (source) => {
|
|
1255
|
+
if (options.disableParsingRawHTML) return false;
|
|
1256
|
+
if (source[0] !== "<") return false;
|
|
1257
|
+
if (!/^<([a-z][a-z0-9:-]*)\b/.test(source)) return false;
|
|
1258
|
+
const tag = source.match(/^<([a-z][a-z0-9:-]*)\b/)?.[1];
|
|
1259
|
+
return tag ? source.indexOf(`</${tag}>`) !== -1 : false;
|
|
1260
|
+
},
|
|
1261
|
+
/**
|
|
1262
|
+
* find the first matching end tag and process the interior
|
|
1263
|
+
*/
|
|
1264
|
+
_match: anyScopeRegex(HTML_BLOCK_ELEMENT_R),
|
|
1265
|
+
_order: Priority.HIGH,
|
|
1266
|
+
_parse(capture, parse, state) {
|
|
1267
|
+
const m = capture[3].match(
|
|
1268
|
+
HTML_LEFT_TRIM_AMOUNT_R
|
|
1269
|
+
);
|
|
1270
|
+
const whitespace = m?.[1] ?? "";
|
|
1271
|
+
const trimmed = trimLeadingWhitespaceOutsideFences(
|
|
1272
|
+
capture[3],
|
|
1273
|
+
whitespace
|
|
1274
|
+
);
|
|
1275
|
+
const parseFunc = containsBlockSyntax(trimmed) ? parseBlock : parseInline;
|
|
1276
|
+
const tagName = capture[1].toLowerCase();
|
|
1277
|
+
const noInnerParse = DO_NOT_PROCESS_HTML_ELEMENTS.indexOf(tagName) !== -1;
|
|
1278
|
+
const tag = (noInnerParse ? tagName : capture[1]).trim();
|
|
1279
|
+
const ast = {
|
|
1280
|
+
attrs: attrStringToMap(tag, capture[2] ?? ""),
|
|
1281
|
+
noInnerParse,
|
|
1282
|
+
tag
|
|
1283
|
+
};
|
|
1284
|
+
state.inAnchor = state.inAnchor || tagName === "a";
|
|
1285
|
+
if (noInnerParse) {
|
|
1286
|
+
ast.text = capture[3];
|
|
1287
|
+
} else {
|
|
1288
|
+
const prevInHTML = state.inHTML;
|
|
1289
|
+
state.inHTML = true;
|
|
1290
|
+
ast.children = parseFunc(parse, trimmed, state);
|
|
1291
|
+
state.inHTML = prevInHTML;
|
|
1292
|
+
}
|
|
1293
|
+
state.inAnchor = false;
|
|
1294
|
+
return ast;
|
|
1295
|
+
},
|
|
1296
|
+
_render(node, _output, state = {}) {
|
|
1297
|
+
const start = performance.now();
|
|
1298
|
+
const result = h(
|
|
1299
|
+
node.tag,
|
|
1300
|
+
{ key: state.key, ...node.attrs ?? {} },
|
|
1301
|
+
node.text ?? (node.children ? _output(node.children, state) : "")
|
|
1302
|
+
);
|
|
1303
|
+
const duration = performance.now() - start;
|
|
1304
|
+
if (duration > 1) {
|
|
1305
|
+
console.log(
|
|
1306
|
+
`htmlBlock._render: ${duration.toFixed(3)}ms, tag: ${node.tag}, has text: ${!!node.text}, has children: ${!!node.children}`
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
return result;
|
|
1310
|
+
}
|
|
1311
|
+
},
|
|
1312
|
+
[RuleType.htmlSelfClosing]: {
|
|
1313
|
+
_qualify: (source) => {
|
|
1314
|
+
if (options.disableParsingRawHTML) return false;
|
|
1315
|
+
if (source[0] !== "<") return false;
|
|
1316
|
+
return /^<([a-zA-Z][a-zA-Z0-9:]*)[\s>/]/.test(source);
|
|
1317
|
+
},
|
|
1318
|
+
/**
|
|
1319
|
+
* find the first matching end tag and process the interior
|
|
1320
|
+
*/
|
|
1321
|
+
_match: anyScopeRegex(HTML_SELF_CLOSING_ELEMENT_R),
|
|
1322
|
+
_order: Priority.HIGH,
|
|
1323
|
+
_parse(capture) {
|
|
1324
|
+
const tag = capture[1].trim();
|
|
1325
|
+
return {
|
|
1326
|
+
attrs: attrStringToMap(tag, capture[2] || ""),
|
|
1327
|
+
tag
|
|
1328
|
+
};
|
|
1329
|
+
},
|
|
1330
|
+
_render(node, _output, state = {}) {
|
|
1331
|
+
const start = performance.now();
|
|
1332
|
+
const result = h(node.tag, {
|
|
1333
|
+
key: state.key,
|
|
1334
|
+
...node.attrs ?? {}
|
|
1335
|
+
});
|
|
1336
|
+
const duration = performance.now() - start;
|
|
1337
|
+
if (duration > 1) {
|
|
1338
|
+
console.log(
|
|
1339
|
+
`htmlSelfClosing._render: ${duration.toFixed(3)}ms, tag: ${node.tag}`
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
return result;
|
|
1343
|
+
}
|
|
1344
|
+
},
|
|
1345
|
+
[RuleType.htmlComment]: {
|
|
1346
|
+
_qualify: ["<!--"],
|
|
1347
|
+
_match: anyScopeRegex(HTML_COMMENT_R),
|
|
1348
|
+
_order: Priority.HIGH,
|
|
1349
|
+
_parse() {
|
|
1350
|
+
return {};
|
|
1351
|
+
},
|
|
1352
|
+
_render: renderNothing
|
|
1353
|
+
},
|
|
1354
|
+
[RuleType.customComponent]: {
|
|
1355
|
+
_qualify: (source) => {
|
|
1356
|
+
const match = source.match(/^ *<([A-Z][a-zA-Z0-9]*)/);
|
|
1357
|
+
return !!match;
|
|
1358
|
+
},
|
|
1359
|
+
_match: blockRegex(CUSTOM_COMPONENT_R),
|
|
1360
|
+
_order: Priority.MAX,
|
|
1361
|
+
_parse(capture, parse, state) {
|
|
1362
|
+
const m = capture[3].match(
|
|
1363
|
+
HTML_LEFT_TRIM_AMOUNT_R
|
|
1364
|
+
);
|
|
1365
|
+
const whitespace = m?.[1] ?? "";
|
|
1366
|
+
const trimmed = trimLeadingWhitespaceOutsideFences(
|
|
1367
|
+
capture[3],
|
|
1368
|
+
whitespace
|
|
1369
|
+
);
|
|
1370
|
+
const parseFunc = containsBlockSyntax(trimmed) ? parseBlock : parseInline;
|
|
1371
|
+
const tagName = capture[1];
|
|
1372
|
+
const noInnerParse = false;
|
|
1373
|
+
const ast = {
|
|
1374
|
+
attrs: attrStringToMap(tagName, capture[2] ?? ""),
|
|
1375
|
+
noInnerParse,
|
|
1376
|
+
tag: tagName
|
|
1377
|
+
};
|
|
1378
|
+
{
|
|
1379
|
+
const prevInHTML = state.inHTML;
|
|
1380
|
+
state.inHTML = true;
|
|
1381
|
+
const parsedChildren = parseFunc(parse, trimmed, state);
|
|
1382
|
+
ast.children = parsedChildren;
|
|
1383
|
+
state.inHTML = prevInHTML;
|
|
1384
|
+
}
|
|
1385
|
+
return ast;
|
|
1386
|
+
},
|
|
1387
|
+
_render(node, _output, state = {}) {
|
|
1388
|
+
const customComponent = getTag(node.tag, options.overrides ?? {});
|
|
1389
|
+
if (typeof customComponent === "function") {
|
|
1390
|
+
const renderedChildren = node.children ? _output(node.children, state) : null;
|
|
1391
|
+
return customComponent({
|
|
1392
|
+
key: state.key,
|
|
1393
|
+
...node.attrs,
|
|
1394
|
+
children: renderedChildren
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
return createElementFn(
|
|
1398
|
+
node.tag,
|
|
1399
|
+
{ key: state.key, ...node.attrs },
|
|
1400
|
+
node.text ?? (node.children ? _output(node.children, state) : "")
|
|
1401
|
+
);
|
|
1402
|
+
}
|
|
1403
|
+
},
|
|
1404
|
+
[RuleType.image]: {
|
|
1405
|
+
_qualify: ["!["],
|
|
1406
|
+
_match: simpleInlineRegex(IMAGE_R),
|
|
1407
|
+
_order: Priority.HIGH,
|
|
1408
|
+
_parse(capture) {
|
|
1409
|
+
return {
|
|
1410
|
+
alt: unescape(capture[1]),
|
|
1411
|
+
target: unescape(capture[2]),
|
|
1412
|
+
title: unescape(capture[3])
|
|
1413
|
+
};
|
|
1414
|
+
},
|
|
1415
|
+
_render(node, _output, state = {}) {
|
|
1416
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1417
|
+
"img",
|
|
1418
|
+
{
|
|
1419
|
+
alt: node.alt ?? void 0,
|
|
1420
|
+
title: node.title ?? void 0,
|
|
1421
|
+
src: sanitize(node.target, "img", "src") ?? void 0
|
|
1422
|
+
},
|
|
1423
|
+
state.key
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
},
|
|
1427
|
+
[RuleType.link]: {
|
|
1428
|
+
_qualify: ["["],
|
|
1429
|
+
_match: inlineRegex(LINK_R),
|
|
1430
|
+
_order: Priority.LOW,
|
|
1431
|
+
_parse(capture, parse, state) {
|
|
1432
|
+
return {
|
|
1433
|
+
children: parseSimpleInline(parse, capture[1], state),
|
|
1434
|
+
target: unescape(capture[2]),
|
|
1435
|
+
title: unescape(capture[3])
|
|
1436
|
+
};
|
|
1437
|
+
},
|
|
1438
|
+
_render(node, _output, state = {}) {
|
|
1439
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1440
|
+
"a",
|
|
1441
|
+
{
|
|
1442
|
+
href: sanitize(node.target, "a", "href") ?? void 0,
|
|
1443
|
+
title: node.title,
|
|
1444
|
+
children: _output(node.children, state)
|
|
1445
|
+
},
|
|
1446
|
+
state.key
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
},
|
|
1450
|
+
// https://daringfireball.net/projects/markdown/syntax#autolink
|
|
1451
|
+
[RuleType.linkAngleBraceStyleDetector]: {
|
|
1452
|
+
_qualify: ["<"],
|
|
1453
|
+
_match: inlineRegex(LINK_AUTOLINK_R),
|
|
1454
|
+
_order: Priority.MAX,
|
|
1455
|
+
_parse(capture) {
|
|
1456
|
+
return {
|
|
1457
|
+
children: [
|
|
1458
|
+
{
|
|
1459
|
+
text: capture[1],
|
|
1460
|
+
type: RuleType.text
|
|
1461
|
+
}
|
|
1462
|
+
],
|
|
1463
|
+
target: capture[1],
|
|
1464
|
+
type: RuleType.link
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
},
|
|
1468
|
+
[RuleType.linkBareUrlDetector]: {
|
|
1469
|
+
_qualify: (source, state) => {
|
|
1470
|
+
if (state.inAnchor || options.disableAutoLink) return false;
|
|
1471
|
+
return startsWith(source, "http://") || startsWith(source, "https://");
|
|
1472
|
+
},
|
|
1473
|
+
_match: inlineRegex(LINK_AUTOLINK_BARE_URL_R),
|
|
1474
|
+
_order: Priority.MAX,
|
|
1475
|
+
_parse(capture) {
|
|
1476
|
+
return {
|
|
1477
|
+
children: [
|
|
1478
|
+
{
|
|
1479
|
+
text: capture[1],
|
|
1480
|
+
type: RuleType.text
|
|
1481
|
+
}
|
|
1482
|
+
],
|
|
1483
|
+
target: capture[1],
|
|
1484
|
+
title: void 0,
|
|
1485
|
+
type: RuleType.link
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
[RuleType.linkMailtoDetector]: {
|
|
1490
|
+
_qualify: ["<"],
|
|
1491
|
+
_match: inlineRegex(LINK_AUTOLINK_MAILTO_R),
|
|
1492
|
+
_order: Priority.MAX,
|
|
1493
|
+
_parse(capture) {
|
|
1494
|
+
let address = capture[1];
|
|
1495
|
+
let target = capture[1];
|
|
1496
|
+
if (!AUTOLINK_MAILTO_CHECK_R.test(target)) {
|
|
1497
|
+
target = "mailto:" + target;
|
|
1498
|
+
}
|
|
1499
|
+
return {
|
|
1500
|
+
children: [
|
|
1501
|
+
{
|
|
1502
|
+
text: address.replace("mailto:", ""),
|
|
1503
|
+
type: RuleType.text
|
|
1504
|
+
}
|
|
1505
|
+
],
|
|
1506
|
+
target,
|
|
1507
|
+
type: RuleType.link
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
[RuleType.orderedList]: generateListRule(
|
|
1512
|
+
ORDERED,
|
|
1513
|
+
(tag, props, ...children) => h(tag, props, ...children)
|
|
1514
|
+
),
|
|
1515
|
+
[RuleType.unorderedList]: generateListRule(
|
|
1516
|
+
UNORDERED,
|
|
1517
|
+
(tag, props, ...children) => h(tag, props, ...children)
|
|
1518
|
+
),
|
|
1519
|
+
[RuleType.newlineCoalescer]: {
|
|
1520
|
+
_match: blockRegex(CONSECUTIVE_NEWLINE_R),
|
|
1521
|
+
_order: Priority.LOW,
|
|
1522
|
+
_parse: captureNothing,
|
|
1523
|
+
_render() {
|
|
1524
|
+
return "\n";
|
|
1525
|
+
}
|
|
1526
|
+
},
|
|
1527
|
+
[RuleType.paragraph]: {
|
|
1528
|
+
_match: allowInline(matchParagraph),
|
|
1529
|
+
_order: Priority.LOW,
|
|
1530
|
+
_parse(capture, parse, state) {
|
|
1531
|
+
const start = performance.now();
|
|
1532
|
+
const result = parseCaptureInline(capture, parse, state);
|
|
1533
|
+
const duration = performance.now() - start;
|
|
1534
|
+
if (duration > 1) {
|
|
1535
|
+
console.log(
|
|
1536
|
+
`paragraph._parse: ${duration.toFixed(3)}ms, capture length: ${capture[0].length}`
|
|
1537
|
+
);
|
|
1538
|
+
}
|
|
1539
|
+
return result;
|
|
1540
|
+
},
|
|
1541
|
+
_render(node, _output, state = {}) {
|
|
1542
|
+
const start = performance.now();
|
|
1543
|
+
const result = /* @__PURE__ */ jsxRuntime.jsx("p", { children: _output(node.children, state) }, state.key);
|
|
1544
|
+
const duration = performance.now() - start;
|
|
1545
|
+
if (duration > 1) {
|
|
1546
|
+
console.log(
|
|
1547
|
+
`paragraph._render: ${duration.toFixed(3)}ms, children count: ${node.children.length}`
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
return result;
|
|
1551
|
+
}
|
|
1552
|
+
},
|
|
1553
|
+
[RuleType.ref]: {
|
|
1554
|
+
_qualify: ["["],
|
|
1555
|
+
_match: inlineRegex(REFERENCE_IMAGE_OR_LINK),
|
|
1556
|
+
_order: Priority.MAX,
|
|
1557
|
+
_parse(capture) {
|
|
1558
|
+
refs[capture[1]] = {
|
|
1559
|
+
target: capture[2],
|
|
1560
|
+
title: capture[4]
|
|
1561
|
+
};
|
|
1562
|
+
return {};
|
|
1563
|
+
},
|
|
1564
|
+
_render: renderNothing
|
|
1565
|
+
},
|
|
1566
|
+
[RuleType.refImage]: {
|
|
1567
|
+
_qualify: ["!["],
|
|
1568
|
+
_match: simpleInlineRegex(REFERENCE_IMAGE_R),
|
|
1569
|
+
_order: Priority.MAX,
|
|
1570
|
+
_parse(capture) {
|
|
1571
|
+
return {
|
|
1572
|
+
alt: capture[1] ? unescape(capture[1]) : void 0,
|
|
1573
|
+
ref: capture[2]
|
|
1574
|
+
};
|
|
1575
|
+
},
|
|
1576
|
+
_render(node, _output, state = {}) {
|
|
1577
|
+
return refs[node.ref] ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1578
|
+
"img",
|
|
1579
|
+
{
|
|
1580
|
+
alt: node.alt,
|
|
1581
|
+
src: sanitize(refs[node.ref].target, "img", "src") ?? void 0,
|
|
1582
|
+
title: refs[node.ref].title
|
|
1583
|
+
},
|
|
1584
|
+
state.key
|
|
1585
|
+
) : null;
|
|
1586
|
+
}
|
|
1587
|
+
},
|
|
1588
|
+
[RuleType.refLink]: {
|
|
1589
|
+
_qualify: (source) => source[0] === "[" && source.indexOf("](") === -1,
|
|
1590
|
+
_match: inlineRegex(REFERENCE_LINK_R),
|
|
1591
|
+
_order: Priority.MAX,
|
|
1592
|
+
_parse(capture, parse, state) {
|
|
1593
|
+
return {
|
|
1594
|
+
children: parse(capture[1], state),
|
|
1595
|
+
fallbackChildren: capture[0],
|
|
1596
|
+
ref: capture[2]
|
|
1597
|
+
};
|
|
1598
|
+
},
|
|
1599
|
+
_render(node, _output, state = {}) {
|
|
1600
|
+
return refs[node.ref] ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1601
|
+
"a",
|
|
1602
|
+
{
|
|
1603
|
+
href: sanitize(refs[node.ref].target, "a", "href") ?? void 0,
|
|
1604
|
+
title: refs[node.ref].title,
|
|
1605
|
+
children: _output(node.children, state)
|
|
1606
|
+
},
|
|
1607
|
+
state.key
|
|
1608
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("span", { children: node.fallbackChildren }, state.key);
|
|
1609
|
+
}
|
|
1610
|
+
},
|
|
1611
|
+
[RuleType.table]: {
|
|
1612
|
+
_qualify: ["|"],
|
|
1613
|
+
_match: blockRegex(NP_TABLE_R),
|
|
1614
|
+
_order: Priority.HIGH,
|
|
1615
|
+
_parse(capture, parse, state) {
|
|
1616
|
+
const start = performance.now();
|
|
1617
|
+
const result = parseTable(capture, parse, state);
|
|
1618
|
+
const duration = performance.now() - start;
|
|
1619
|
+
if (duration > 1) {
|
|
1620
|
+
console.log(
|
|
1621
|
+
`table._parse: ${duration.toFixed(3)}ms, capture length: ${capture[0].length}`
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
return result;
|
|
1625
|
+
},
|
|
1626
|
+
_render(node, _output, state = {}) {
|
|
1627
|
+
const start = performance.now();
|
|
1628
|
+
const table = node;
|
|
1629
|
+
const result = h(
|
|
1630
|
+
"table",
|
|
1631
|
+
{ key: state.key },
|
|
1632
|
+
h(
|
|
1633
|
+
"thead",
|
|
1634
|
+
{},
|
|
1635
|
+
h(
|
|
1636
|
+
"tr",
|
|
1637
|
+
{},
|
|
1638
|
+
...table.header.map(
|
|
1639
|
+
(content, i) => h(
|
|
1640
|
+
"th",
|
|
1641
|
+
{ key: i, style: getTableStyle(table, i) },
|
|
1642
|
+
_output(content, state)
|
|
1643
|
+
)
|
|
1644
|
+
)
|
|
1645
|
+
)
|
|
1646
|
+
),
|
|
1647
|
+
h(
|
|
1648
|
+
"tbody",
|
|
1649
|
+
{},
|
|
1650
|
+
...table.cells.map(
|
|
1651
|
+
(row, i) => h(
|
|
1652
|
+
"tr",
|
|
1653
|
+
{ key: i },
|
|
1654
|
+
...row.map(
|
|
1655
|
+
(content, c) => h(
|
|
1656
|
+
"td",
|
|
1657
|
+
{ key: c, style: getTableStyle(table, c) },
|
|
1658
|
+
_output(content, state)
|
|
1659
|
+
)
|
|
1660
|
+
)
|
|
1661
|
+
)
|
|
1662
|
+
)
|
|
1663
|
+
)
|
|
1664
|
+
);
|
|
1665
|
+
const duration = performance.now() - start;
|
|
1666
|
+
if (duration > 1) {
|
|
1667
|
+
console.log(
|
|
1668
|
+
`table._render: ${duration.toFixed(3)}ms, header count: ${table.header.length}, rows count: ${table.cells.length}`
|
|
1669
|
+
);
|
|
1670
|
+
}
|
|
1671
|
+
return result;
|
|
1672
|
+
}
|
|
1673
|
+
},
|
|
1674
|
+
[RuleType.text]: {
|
|
1675
|
+
// Here we look for anything followed by non-symbols,
|
|
1676
|
+
// double newlines, or double-space-newlines
|
|
1677
|
+
// We break on any symbol characters so that this grammar
|
|
1678
|
+
// is easy to extend without needing to modify this regex
|
|
1679
|
+
_match: allowInline((source, _state) => {
|
|
1680
|
+
let ret;
|
|
1681
|
+
if (startsWith(source, ":")) ret = SHORTCODE_R.exec(source);
|
|
1682
|
+
if (ret) return ret;
|
|
1683
|
+
return TEXT_PLAIN_R.exec(source);
|
|
1684
|
+
}),
|
|
1685
|
+
_order: Priority.MIN,
|
|
1686
|
+
_parse(capture) {
|
|
1687
|
+
const text = capture[0];
|
|
1688
|
+
return {
|
|
1689
|
+
text: text.indexOf("&") === -1 ? text : text.replace(
|
|
1690
|
+
HTML_CHAR_CODE_R,
|
|
1691
|
+
(full, inner) => options.namedCodesToUnicode?.[inner] ?? full
|
|
1692
|
+
)
|
|
1693
|
+
};
|
|
1694
|
+
},
|
|
1695
|
+
_render(node) {
|
|
1696
|
+
return node.text;
|
|
1697
|
+
}
|
|
1698
|
+
},
|
|
1699
|
+
[RuleType.textBolded]: {
|
|
1700
|
+
_qualify: ["**", "__"],
|
|
1701
|
+
_match: simpleInlineRegex(TEXT_BOLD_R),
|
|
1702
|
+
_order: Priority.MED,
|
|
1703
|
+
_parse(capture, parse, state) {
|
|
1704
|
+
return {
|
|
1705
|
+
// capture[1] -> the syntax control character
|
|
1706
|
+
// capture[2] -> inner content
|
|
1707
|
+
children: parse(capture[2], state)
|
|
1708
|
+
};
|
|
1709
|
+
},
|
|
1710
|
+
_render(node, _output, state = {}) {
|
|
1711
|
+
const start = performance.now();
|
|
1712
|
+
const result = /* @__PURE__ */ jsxRuntime.jsx("strong", { children: _output(node.children, state) }, state.key);
|
|
1713
|
+
const duration = performance.now() - start;
|
|
1714
|
+
if (duration > 1) {
|
|
1715
|
+
console.log(
|
|
1716
|
+
`textBolded._render: ${duration.toFixed(3)}ms, children count: ${node.children.length}`
|
|
1717
|
+
);
|
|
1718
|
+
}
|
|
1719
|
+
return result;
|
|
1720
|
+
}
|
|
1721
|
+
},
|
|
1722
|
+
[RuleType.textEmphasized]: {
|
|
1723
|
+
_qualify: (source) => {
|
|
1724
|
+
const char = source[0];
|
|
1725
|
+
return (char === "*" || char === "_") && source[1] !== char;
|
|
1726
|
+
},
|
|
1727
|
+
_match: simpleInlineRegex(TEXT_EMPHASIZED_R),
|
|
1728
|
+
_order: Priority.LOW,
|
|
1729
|
+
_parse(capture, parse, state) {
|
|
1730
|
+
return {
|
|
1731
|
+
// capture[1] -> opening * or _
|
|
1732
|
+
// capture[2] -> inner content
|
|
1733
|
+
children: parse(capture[2], state)
|
|
1734
|
+
};
|
|
1735
|
+
},
|
|
1736
|
+
_render(node, _output, state = {}) {
|
|
1737
|
+
const start = performance.now();
|
|
1738
|
+
const result = /* @__PURE__ */ jsxRuntime.jsx("em", { children: _output(node.children, state) }, state.key);
|
|
1739
|
+
const duration = performance.now() - start;
|
|
1740
|
+
if (duration > 1) {
|
|
1741
|
+
console.log(
|
|
1742
|
+
`textEmphasized._render: ${duration.toFixed(3)}ms, children count: ${node.children.length}`
|
|
1743
|
+
);
|
|
1744
|
+
}
|
|
1745
|
+
return result;
|
|
1746
|
+
}
|
|
1747
|
+
},
|
|
1748
|
+
[RuleType.textEscaped]: {
|
|
1749
|
+
_qualify: ["\\"],
|
|
1750
|
+
// We don't allow escaping numbers, letters, or spaces here so that
|
|
1751
|
+
// backslashes used in plain text still get rendered. But allowing
|
|
1752
|
+
// escaping anything else provides a very flexible escape mechanism,
|
|
1753
|
+
// regardless of how this grammar is extended.
|
|
1754
|
+
_match: simpleInlineRegex(TEXT_ESCAPED_R),
|
|
1755
|
+
_order: Priority.HIGH,
|
|
1756
|
+
_parse(capture) {
|
|
1757
|
+
return {
|
|
1758
|
+
text: capture[1],
|
|
1759
|
+
type: RuleType.text
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
},
|
|
1763
|
+
[RuleType.textMarked]: {
|
|
1764
|
+
_qualify: ["=="],
|
|
1765
|
+
_match: simpleInlineRegex(TEXT_MARKED_R),
|
|
1766
|
+
_order: Priority.LOW,
|
|
1767
|
+
_parse: parseCaptureInline,
|
|
1768
|
+
_render(node, _output, state = {}) {
|
|
1769
|
+
return /* @__PURE__ */ jsxRuntime.jsx("mark", { children: _output(node.children, state) }, state.key);
|
|
1770
|
+
}
|
|
1771
|
+
},
|
|
1772
|
+
[RuleType.textStrikethroughed]: {
|
|
1773
|
+
_qualify: ["~~"],
|
|
1774
|
+
_match: simpleInlineRegex(TEXT_STRIKETHROUGHED_R),
|
|
1775
|
+
_order: Priority.LOW,
|
|
1776
|
+
_parse: parseCaptureInline,
|
|
1777
|
+
_render(node, _output, state = {}) {
|
|
1778
|
+
return /* @__PURE__ */ jsxRuntime.jsx("del", { children: _output(node.children, state) }, state.key);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
if (options.disableParsingRawHTML === true) {
|
|
1783
|
+
delete rules[RuleType.htmlBlock];
|
|
1784
|
+
delete rules[RuleType.htmlSelfClosing];
|
|
1785
|
+
}
|
|
1786
|
+
const parser = parserFor(rules);
|
|
1787
|
+
const emitter = reactFor(createRenderer(rules, options.renderRule));
|
|
1788
|
+
const jsx2 = compile(markdown);
|
|
1789
|
+
if (footnotes.length) {
|
|
1790
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1791
|
+
jsx2,
|
|
1792
|
+
/* @__PURE__ */ jsxRuntime.jsx("footer", { children: footnotes.map((def) => /* @__PURE__ */ jsxRuntime.jsxs("div", { id: slug(def.identifier, slugify), children: [
|
|
1793
|
+
def.identifier,
|
|
1794
|
+
emitter(
|
|
1795
|
+
parser(def.footnote, { inline: true })
|
|
1796
|
+
)
|
|
1797
|
+
] }, def.identifier)) }, "footer")
|
|
1798
|
+
] });
|
|
1799
|
+
}
|
|
1800
|
+
return jsx2;
|
|
1801
|
+
};
|
|
1802
|
+
const MarkdownProcessor = ({ children = "", options, ...props }) => {
|
|
1803
|
+
if (define_process_env_default.NODE_ENV !== "production" && typeof children !== "string") {
|
|
1804
|
+
console.error(
|
|
1805
|
+
"intlayer: <Markdown> component only accepts a single string as a child, received:",
|
|
1806
|
+
children
|
|
1807
|
+
);
|
|
1808
|
+
}
|
|
1809
|
+
return ReactExports.cloneElement(
|
|
1810
|
+
compiler(children, options),
|
|
1811
|
+
props
|
|
1812
|
+
);
|
|
1813
|
+
};
|
|
1814
|
+
exports.MarkdownProcessor = MarkdownProcessor;
|
|
1815
|
+
exports.RuleType = RuleType;
|
|
1816
|
+
exports.compiler = compiler;
|
|
1817
|
+
exports.sanitizer = sanitizer;
|
|
1818
|
+
exports.slugify = slugify;
|
|
1819
|
+
//# sourceMappingURL=processor.cjs.map
|