marked 7.0.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/marked.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * marked v7.0.0 - a markdown parser
2
+ * marked v7.0.2 - a markdown parser
3
3
  * Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
4
4
  * https://github.com/markedjs/marked
5
5
  */
@@ -9,2237 +9,2623 @@
9
9
  * The code in this file is generated from files in ./src/
10
10
  */
11
11
 
12
- var __accessCheck = (obj, member, msg) => {
13
- if (!member.has(obj))
14
- throw TypeError("Cannot " + msg);
15
- };
16
- var __privateAdd = (obj, member, value) => {
17
- if (member.has(obj))
18
- throw TypeError("Cannot add the same private member more than once");
19
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
- };
21
- var __privateMethod = (obj, member, method) => {
22
- __accessCheck(obj, member, "access private method");
23
- return method;
24
- };
25
-
26
- // src/defaults.ts
12
+ /**
13
+ * Gets the original marked default options.
14
+ */
27
15
  function _getDefaults() {
28
- return {
29
- async: false,
30
- baseUrl: null,
31
- breaks: false,
32
- extensions: null,
33
- gfm: true,
34
- headerIds: false,
35
- headerPrefix: "",
36
- highlight: null,
37
- hooks: null,
38
- langPrefix: "language-",
39
- mangle: false,
40
- pedantic: false,
41
- renderer: null,
42
- sanitize: false,
43
- sanitizer: null,
44
- silent: false,
45
- smartypants: false,
46
- tokenizer: null,
47
- walkTokens: null,
48
- xhtml: false
49
- };
16
+ return {
17
+ async: false,
18
+ baseUrl: null,
19
+ breaks: false,
20
+ extensions: null,
21
+ gfm: true,
22
+ headerIds: false,
23
+ headerPrefix: '',
24
+ highlight: null,
25
+ hooks: null,
26
+ langPrefix: 'language-',
27
+ mangle: false,
28
+ pedantic: false,
29
+ renderer: null,
30
+ sanitize: false,
31
+ sanitizer: null,
32
+ silent: false,
33
+ smartypants: false,
34
+ tokenizer: null,
35
+ walkTokens: null,
36
+ xhtml: false
37
+ };
50
38
  }
51
- var _defaults = _getDefaults();
39
+ let _defaults = _getDefaults();
52
40
  function changeDefaults(newDefaults) {
53
- _defaults = newDefaults;
41
+ _defaults = newDefaults;
54
42
  }
55
43
 
56
- // src/helpers.ts
57
- var escapeTest = /[&<>"']/;
58
- var escapeReplace = new RegExp(escapeTest.source, "g");
59
- var escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
60
- var escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, "g");
61
- var escapeReplacements = {
62
- "&": "&amp;",
63
- "<": "&lt;",
64
- ">": "&gt;",
65
- '"': "&quot;",
66
- "'": "&#39;"
44
+ /**
45
+ * Helpers
46
+ */
47
+ const escapeTest = /[&<>"']/;
48
+ const escapeReplace = new RegExp(escapeTest.source, 'g');
49
+ const escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
50
+ const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
51
+ const escapeReplacements = {
52
+ '&': '&amp;',
53
+ '<': '&lt;',
54
+ '>': '&gt;',
55
+ '"': '&quot;',
56
+ "'": '&#39;'
67
57
  };
68
- var getEscapeReplacement = (ch) => escapeReplacements[ch];
58
+ const getEscapeReplacement = (ch) => escapeReplacements[ch];
69
59
  function escape(html, encode) {
70
- if (encode) {
71
- if (escapeTest.test(html)) {
72
- return html.replace(escapeReplace, getEscapeReplacement);
60
+ if (encode) {
61
+ if (escapeTest.test(html)) {
62
+ return html.replace(escapeReplace, getEscapeReplacement);
63
+ }
73
64
  }
74
- } else {
75
- if (escapeTestNoEncode.test(html)) {
76
- return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
65
+ else {
66
+ if (escapeTestNoEncode.test(html)) {
67
+ return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
68
+ }
77
69
  }
78
- }
79
- return html;
70
+ return html;
80
71
  }
81
- var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
72
+ const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
82
73
  function unescape(html) {
83
- return html.replace(unescapeTest, (_, n) => {
84
- n = n.toLowerCase();
85
- if (n === "colon")
86
- return ":";
87
- if (n.charAt(0) === "#") {
88
- return n.charAt(1) === "x" ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
89
- }
90
- return "";
91
- });
74
+ // explicitly match decimal, hex, and named HTML entities
75
+ return html.replace(unescapeTest, (_, n) => {
76
+ n = n.toLowerCase();
77
+ if (n === 'colon')
78
+ return ':';
79
+ if (n.charAt(0) === '#') {
80
+ return n.charAt(1) === 'x'
81
+ ? String.fromCharCode(parseInt(n.substring(2), 16))
82
+ : String.fromCharCode(+n.substring(1));
83
+ }
84
+ return '';
85
+ });
92
86
  }
93
- var caret = /(^|[^\[])\^/g;
87
+ const caret = /(^|[^\[])\^/g;
94
88
  function edit(regex, opt) {
95
- regex = typeof regex === "string" ? regex : regex.source;
96
- opt = opt || "";
97
- const obj = {
98
- replace: (name, val) => {
99
- val = typeof val === "object" && "source" in val ? val.source : val;
100
- val = val.replace(caret, "$1");
101
- regex = regex.replace(name, val);
102
- return obj;
103
- },
104
- getRegex: () => {
105
- return new RegExp(regex, opt);
106
- }
107
- };
108
- return obj;
89
+ regex = typeof regex === 'string' ? regex : regex.source;
90
+ opt = opt || '';
91
+ const obj = {
92
+ replace: (name, val) => {
93
+ val = typeof val === 'object' && 'source' in val ? val.source : val;
94
+ val = val.replace(caret, '$1');
95
+ regex = regex.replace(name, val);
96
+ return obj;
97
+ },
98
+ getRegex: () => {
99
+ return new RegExp(regex, opt);
100
+ }
101
+ };
102
+ return obj;
109
103
  }
110
- var nonWordAndColonTest = /[^\w:]/g;
111
- var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
104
+ const nonWordAndColonTest = /[^\w:]/g;
105
+ const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
112
106
  function cleanUrl(sanitize, base, href) {
113
- if (sanitize) {
114
- let prot;
107
+ if (sanitize) {
108
+ let prot;
109
+ try {
110
+ prot = decodeURIComponent(unescape(href))
111
+ .replace(nonWordAndColonTest, '')
112
+ .toLowerCase();
113
+ }
114
+ catch (e) {
115
+ return null;
116
+ }
117
+ if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
118
+ return null;
119
+ }
120
+ }
121
+ if (base && !originIndependentUrl.test(href)) {
122
+ href = resolveUrl(base, href);
123
+ }
115
124
  try {
116
- prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, "").toLowerCase();
117
- } catch (e) {
118
- return null;
119
- }
120
- if (prot.indexOf("javascript:") === 0 || prot.indexOf("vbscript:") === 0 || prot.indexOf("data:") === 0) {
121
- return null;
122
- }
123
- }
124
- if (base && !originIndependentUrl.test(href)) {
125
- href = resolveUrl(base, href);
126
- }
127
- try {
128
- href = encodeURI(href).replace(/%25/g, "%");
129
- } catch (e) {
130
- return null;
131
- }
132
- return href;
125
+ href = encodeURI(href).replace(/%25/g, '%');
126
+ }
127
+ catch (e) {
128
+ return null;
129
+ }
130
+ return href;
133
131
  }
134
- var baseUrls = {};
135
- var justDomain = /^[^:]+:\/*[^/]*$/;
136
- var protocol = /^([^:]+:)[\s\S]*$/;
137
- var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
132
+ const baseUrls = {};
133
+ const justDomain = /^[^:]+:\/*[^/]*$/;
134
+ const protocol = /^([^:]+:)[\s\S]*$/;
135
+ const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
138
136
  function resolveUrl(base, href) {
139
- if (!baseUrls[" " + base]) {
140
- if (justDomain.test(base)) {
141
- baseUrls[" " + base] = base + "/";
142
- } else {
143
- baseUrls[" " + base] = rtrim(base, "/", true);
144
- }
145
- }
146
- base = baseUrls[" " + base];
147
- const relativeBase = base.indexOf(":") === -1;
148
- if (href.substring(0, 2) === "//") {
149
- if (relativeBase) {
150
- return href;
151
- }
152
- return base.replace(protocol, "$1") + href;
153
- } else if (href.charAt(0) === "/") {
154
- if (relativeBase) {
155
- return href;
156
- }
157
- return base.replace(domain, "$1") + href;
158
- } else {
159
- return base + href;
160
- }
137
+ if (!baseUrls[' ' + base]) {
138
+ // we can ignore everything in base after the last slash of its path component,
139
+ // but we might need to add _that_
140
+ // https://tools.ietf.org/html/rfc3986#section-3
141
+ if (justDomain.test(base)) {
142
+ baseUrls[' ' + base] = base + '/';
143
+ }
144
+ else {
145
+ baseUrls[' ' + base] = rtrim(base, '/', true);
146
+ }
147
+ }
148
+ base = baseUrls[' ' + base];
149
+ const relativeBase = base.indexOf(':') === -1;
150
+ if (href.substring(0, 2) === '//') {
151
+ if (relativeBase) {
152
+ return href;
153
+ }
154
+ return base.replace(protocol, '$1') + href;
155
+ }
156
+ else if (href.charAt(0) === '/') {
157
+ if (relativeBase) {
158
+ return href;
159
+ }
160
+ return base.replace(domain, '$1') + href;
161
+ }
162
+ else {
163
+ return base + href;
164
+ }
161
165
  }
162
- var noopTest = { exec: () => null };
166
+ const noopTest = { exec: () => null };
163
167
  function splitCells(tableRow, count) {
164
- const row = tableRow.replace(/\|/g, (match, offset, str) => {
165
- let escaped = false, curr = offset;
166
- while (--curr >= 0 && str[curr] === "\\")
167
- escaped = !escaped;
168
- if (escaped) {
169
- return "|";
170
- } else {
171
- return " |";
172
- }
173
- }), cells = row.split(/ \|/);
174
- let i = 0;
175
- if (!cells[0].trim()) {
176
- cells.shift();
177
- }
178
- if (cells.length > 0 && !cells[cells.length - 1].trim()) {
179
- cells.pop();
180
- }
181
- if (cells.length > count) {
182
- cells.splice(count);
183
- } else {
184
- while (cells.length < count)
185
- cells.push("");
186
- }
187
- for (; i < cells.length; i++) {
188
- cells[i] = cells[i].trim().replace(/\\\|/g, "|");
189
- }
190
- return cells;
168
+ // ensure that every cell-delimiting pipe has a space
169
+ // before it to distinguish it from an escaped pipe
170
+ const row = tableRow.replace(/\|/g, (match, offset, str) => {
171
+ let escaped = false, curr = offset;
172
+ while (--curr >= 0 && str[curr] === '\\')
173
+ escaped = !escaped;
174
+ if (escaped) {
175
+ // odd number of slashes means | is escaped
176
+ // so we leave it alone
177
+ return '|';
178
+ }
179
+ else {
180
+ // add space before unescaped |
181
+ return ' |';
182
+ }
183
+ }), cells = row.split(/ \|/);
184
+ let i = 0;
185
+ // First/last cell in a row cannot be empty if it has no leading/trailing pipe
186
+ if (!cells[0].trim()) {
187
+ cells.shift();
188
+ }
189
+ if (cells.length > 0 && !cells[cells.length - 1].trim()) {
190
+ cells.pop();
191
+ }
192
+ if (count) {
193
+ if (cells.length > count) {
194
+ cells.splice(count);
195
+ }
196
+ else {
197
+ while (cells.length < count)
198
+ cells.push('');
199
+ }
200
+ }
201
+ for (; i < cells.length; i++) {
202
+ // leading or trailing whitespace is ignored per the gfm spec
203
+ cells[i] = cells[i].trim().replace(/\\\|/g, '|');
204
+ }
205
+ return cells;
191
206
  }
207
+ /**
208
+ * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
209
+ * /c*$/ is vulnerable to REDOS.
210
+ *
211
+ * @param str
212
+ * @param c
213
+ * @param invert Remove suffix of non-c chars instead. Default falsey.
214
+ */
192
215
  function rtrim(str, c, invert) {
193
- const l = str.length;
194
- if (l === 0) {
195
- return "";
196
- }
197
- let suffLen = 0;
198
- while (suffLen < l) {
199
- const currChar = str.charAt(l - suffLen - 1);
200
- if (currChar === c && !invert) {
201
- suffLen++;
202
- } else if (currChar !== c && invert) {
203
- suffLen++;
204
- } else {
205
- break;
206
- }
207
- }
208
- return str.slice(0, l - suffLen);
216
+ const l = str.length;
217
+ if (l === 0) {
218
+ return '';
219
+ }
220
+ // Length of suffix matching the invert condition.
221
+ let suffLen = 0;
222
+ // Step left until we fail to match the invert condition.
223
+ while (suffLen < l) {
224
+ const currChar = str.charAt(l - suffLen - 1);
225
+ if (currChar === c && !invert) {
226
+ suffLen++;
227
+ }
228
+ else if (currChar !== c && invert) {
229
+ suffLen++;
230
+ }
231
+ else {
232
+ break;
233
+ }
234
+ }
235
+ return str.slice(0, l - suffLen);
209
236
  }
210
237
  function findClosingBracket(str, b) {
211
- if (str.indexOf(b[1]) === -1) {
238
+ if (str.indexOf(b[1]) === -1) {
239
+ return -1;
240
+ }
241
+ const l = str.length;
242
+ let level = 0, i = 0;
243
+ for (; i < l; i++) {
244
+ if (str[i] === '\\') {
245
+ i++;
246
+ }
247
+ else if (str[i] === b[0]) {
248
+ level++;
249
+ }
250
+ else if (str[i] === b[1]) {
251
+ level--;
252
+ if (level < 0) {
253
+ return i;
254
+ }
255
+ }
256
+ }
212
257
  return -1;
213
- }
214
- const l = str.length;
215
- let level = 0, i = 0;
216
- for (; i < l; i++) {
217
- if (str[i] === "\\") {
218
- i++;
219
- } else if (str[i] === b[0]) {
220
- level++;
221
- } else if (str[i] === b[1]) {
222
- level--;
223
- if (level < 0) {
224
- return i;
225
- }
226
- }
227
- }
228
- return -1;
229
258
  }
230
259
  function checkDeprecations(opt, callback) {
231
- if (!opt || opt.silent) {
232
- return;
233
- }
234
- if (callback) {
235
- console.warn("marked(): callback is deprecated since version 5.0.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/using_pro#async");
236
- }
237
- if (opt.sanitize || opt.sanitizer) {
238
- console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options");
239
- }
240
- if (opt.highlight || opt.langPrefix !== "language-") {
241
- console.warn("marked(): highlight and langPrefix parameters are deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-highlight.");
242
- }
243
- if (opt.mangle) {
244
- console.warn("marked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.");
245
- }
246
- if (opt.baseUrl) {
247
- console.warn("marked(): baseUrl parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-base-url.");
248
- }
249
- if (opt.smartypants) {
250
- console.warn("marked(): smartypants parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-smartypants.");
251
- }
252
- if (opt.xhtml) {
253
- console.warn("marked(): xhtml parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-xhtml.");
254
- }
255
- if (opt.headerIds || opt.headerPrefix) {
256
- console.warn("marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.");
257
- }
260
+ if (!opt || opt.silent) {
261
+ return;
262
+ }
263
+ if (callback) {
264
+ console.warn('marked(): callback is deprecated since version 5.0.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/using_pro#async');
265
+ }
266
+ if (opt.sanitize || opt.sanitizer) {
267
+ console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
268
+ }
269
+ if (opt.highlight || opt.langPrefix !== 'language-') {
270
+ console.warn('marked(): highlight and langPrefix parameters are deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-highlight.');
271
+ }
272
+ if (opt.mangle) {
273
+ console.warn('marked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.');
274
+ }
275
+ if (opt.baseUrl) {
276
+ console.warn('marked(): baseUrl parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-base-url.');
277
+ }
278
+ if (opt.smartypants) {
279
+ console.warn('marked(): smartypants parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-smartypants.');
280
+ }
281
+ if (opt.xhtml) {
282
+ console.warn('marked(): xhtml parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-xhtml.');
283
+ }
284
+ if (opt.headerIds || opt.headerPrefix) {
285
+ console.warn('marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.');
286
+ }
258
287
  }
259
288
 
260
- // src/Tokenizer.ts
261
- function outputLink(cap, link, raw, lexer2) {
262
- const href = link.href;
263
- const title = link.title ? escape(link.title) : null;
264
- const text = cap[1].replace(/\\([\[\]])/g, "$1");
265
- if (cap[0].charAt(0) !== "!") {
266
- lexer2.state.inLink = true;
267
- const token = {
268
- type: "link",
269
- raw,
270
- href,
271
- title,
272
- text,
273
- tokens: lexer2.inlineTokens(text)
289
+ function outputLink(cap, link, raw, lexer) {
290
+ const href = link.href;
291
+ const title = link.title ? escape(link.title) : null;
292
+ const text = cap[1].replace(/\\([\[\]])/g, '$1');
293
+ if (cap[0].charAt(0) !== '!') {
294
+ lexer.state.inLink = true;
295
+ const token = {
296
+ type: 'link',
297
+ raw,
298
+ href,
299
+ title,
300
+ text,
301
+ tokens: lexer.inlineTokens(text)
302
+ };
303
+ lexer.state.inLink = false;
304
+ return token;
305
+ }
306
+ return {
307
+ type: 'image',
308
+ raw,
309
+ href,
310
+ title,
311
+ text: escape(text)
274
312
  };
275
- lexer2.state.inLink = false;
276
- return token;
277
- }
278
- return {
279
- type: "image",
280
- raw,
281
- href,
282
- title,
283
- text: escape(text)
284
- };
285
313
  }
286
314
  function indentCodeCompensation(raw, text) {
287
- const matchIndentToCode = raw.match(/^(\s+)(?:```)/);
288
- if (matchIndentToCode === null) {
289
- return text;
290
- }
291
- const indentToCode = matchIndentToCode[1];
292
- return text.split("\n").map((node) => {
293
- const matchIndentInNode = node.match(/^\s+/);
294
- if (matchIndentInNode === null) {
295
- return node;
296
- }
297
- const [indentInNode] = matchIndentInNode;
298
- if (indentInNode.length >= indentToCode.length) {
299
- return node.slice(indentToCode.length);
300
- }
301
- return node;
302
- }).join("\n");
315
+ const matchIndentToCode = raw.match(/^(\s+)(?:```)/);
316
+ if (matchIndentToCode === null) {
317
+ return text;
318
+ }
319
+ const indentToCode = matchIndentToCode[1];
320
+ return text
321
+ .split('\n')
322
+ .map(node => {
323
+ const matchIndentInNode = node.match(/^\s+/);
324
+ if (matchIndentInNode === null) {
325
+ return node;
326
+ }
327
+ const [indentInNode] = matchIndentInNode;
328
+ if (indentInNode.length >= indentToCode.length) {
329
+ return node.slice(indentToCode.length);
330
+ }
331
+ return node;
332
+ })
333
+ .join('\n');
303
334
  }
304
- var _Tokenizer = class {
305
- constructor(options2) {
306
- this.options = options2 || _defaults;
307
- }
308
- space(src) {
309
- const cap = this.rules.block.newline.exec(src);
310
- if (cap && cap[0].length > 0) {
311
- return {
312
- type: "space",
313
- raw: cap[0]
314
- };
315
- }
316
- }
317
- code(src) {
318
- const cap = this.rules.block.code.exec(src);
319
- if (cap) {
320
- const text = cap[0].replace(/^ {1,4}/gm, "");
321
- return {
322
- type: "code",
323
- raw: cap[0],
324
- codeBlockStyle: "indented",
325
- text: !this.options.pedantic ? rtrim(text, "\n") : text
326
- };
327
- }
328
- }
329
- fences(src) {
330
- const cap = this.rules.block.fences.exec(src);
331
- if (cap) {
332
- const raw = cap[0];
333
- const text = indentCodeCompensation(raw, cap[3] || "");
334
- return {
335
- type: "code",
336
- raw,
337
- lang: cap[2] ? cap[2].trim().replace(this.rules.inline._escapes, "$1") : cap[2],
338
- text
339
- };
340
- }
341
- }
342
- heading(src) {
343
- const cap = this.rules.block.heading.exec(src);
344
- if (cap) {
345
- let text = cap[2].trim();
346
- if (/#$/.test(text)) {
347
- const trimmed = rtrim(text, "#");
348
- if (this.options.pedantic) {
349
- text = trimmed.trim();
350
- } else if (!trimmed || / $/.test(trimmed)) {
351
- text = trimmed.trim();
352
- }
353
- }
354
- return {
355
- type: "heading",
356
- raw: cap[0],
357
- depth: cap[1].length,
358
- text,
359
- tokens: this.lexer.inline(text)
360
- };
361
- }
362
- }
363
- hr(src) {
364
- const cap = this.rules.block.hr.exec(src);
365
- if (cap) {
366
- return {
367
- type: "hr",
368
- raw: cap[0]
369
- };
370
- }
371
- }
372
- blockquote(src) {
373
- const cap = this.rules.block.blockquote.exec(src);
374
- if (cap) {
375
- const text = cap[0].replace(/^ *>[ \t]?/gm, "");
376
- const top = this.lexer.state.top;
377
- this.lexer.state.top = true;
378
- const tokens = this.lexer.blockTokens(text);
379
- this.lexer.state.top = top;
380
- return {
381
- type: "blockquote",
382
- raw: cap[0],
383
- tokens,
384
- text
385
- };
386
- }
387
- }
388
- list(src) {
389
- let cap = this.rules.block.list.exec(src);
390
- if (cap) {
391
- let raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine, line, nextLine, rawLine, itemContents, endEarly;
392
- let bull = cap[1].trim();
393
- const isordered = bull.length > 1;
394
- const list = {
395
- type: "list",
396
- raw: "",
397
- ordered: isordered,
398
- start: isordered ? +bull.slice(0, -1) : "",
399
- loose: false,
400
- items: []
401
- };
402
- bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
403
- if (this.options.pedantic) {
404
- bull = isordered ? bull : "[*+-]";
405
- }
406
- const itemRegex = new RegExp(`^( {0,3}${bull})((?:[ ][^\\n]*)?(?:\\n|$))`);
407
- while (src) {
408
- endEarly = false;
409
- if (!(cap = itemRegex.exec(src))) {
410
- break;
411
- }
412
- if (this.rules.block.hr.test(src)) {
413
- break;
414
- }
415
- raw = cap[0];
416
- src = src.substring(raw.length);
417
- line = cap[2].split("\n", 1)[0].replace(/^\t+/, (t) => " ".repeat(3 * t.length));
418
- nextLine = src.split("\n", 1)[0];
419
- if (this.options.pedantic) {
420
- indent = 2;
421
- itemContents = line.trimLeft();
422
- } else {
423
- indent = cap[2].search(/[^ ]/);
424
- indent = indent > 4 ? 1 : indent;
425
- itemContents = line.slice(indent);
426
- indent += cap[1].length;
427
- }
428
- blankLine = false;
429
- if (!line && /^ *$/.test(nextLine)) {
430
- raw += nextLine + "\n";
431
- src = src.substring(nextLine.length + 1);
432
- endEarly = true;
433
- }
434
- if (!endEarly) {
435
- const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`);
436
- const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
437
- const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
438
- const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
439
- while (src) {
440
- rawLine = src.split("\n", 1)[0];
441
- nextLine = rawLine;
335
+ /**
336
+ * Tokenizer
337
+ */
338
+ class _Tokenizer {
339
+ options;
340
+ rules;
341
+ lexer;
342
+ constructor(options) {
343
+ this.options = options || _defaults;
344
+ }
345
+ space(src) {
346
+ const cap = this.rules.block.newline.exec(src);
347
+ if (cap && cap[0].length > 0) {
348
+ return {
349
+ type: 'space',
350
+ raw: cap[0]
351
+ };
352
+ }
353
+ }
354
+ code(src) {
355
+ const cap = this.rules.block.code.exec(src);
356
+ if (cap) {
357
+ const text = cap[0].replace(/^ {1,4}/gm, '');
358
+ return {
359
+ type: 'code',
360
+ raw: cap[0],
361
+ codeBlockStyle: 'indented',
362
+ text: !this.options.pedantic
363
+ ? rtrim(text, '\n')
364
+ : text
365
+ };
366
+ }
367
+ }
368
+ fences(src) {
369
+ const cap = this.rules.block.fences.exec(src);
370
+ if (cap) {
371
+ const raw = cap[0];
372
+ const text = indentCodeCompensation(raw, cap[3] || '');
373
+ return {
374
+ type: 'code',
375
+ raw,
376
+ lang: cap[2] ? cap[2].trim().replace(this.rules.inline._escapes, '$1') : cap[2],
377
+ text
378
+ };
379
+ }
380
+ }
381
+ heading(src) {
382
+ const cap = this.rules.block.heading.exec(src);
383
+ if (cap) {
384
+ let text = cap[2].trim();
385
+ // remove trailing #s
386
+ if (/#$/.test(text)) {
387
+ const trimmed = rtrim(text, '#');
388
+ if (this.options.pedantic) {
389
+ text = trimmed.trim();
390
+ }
391
+ else if (!trimmed || / $/.test(trimmed)) {
392
+ // CommonMark requires space before trailing #s
393
+ text = trimmed.trim();
394
+ }
395
+ }
396
+ return {
397
+ type: 'heading',
398
+ raw: cap[0],
399
+ depth: cap[1].length,
400
+ text,
401
+ tokens: this.lexer.inline(text)
402
+ };
403
+ }
404
+ }
405
+ hr(src) {
406
+ const cap = this.rules.block.hr.exec(src);
407
+ if (cap) {
408
+ return {
409
+ type: 'hr',
410
+ raw: cap[0]
411
+ };
412
+ }
413
+ }
414
+ blockquote(src) {
415
+ const cap = this.rules.block.blockquote.exec(src);
416
+ if (cap) {
417
+ const text = cap[0].replace(/^ *>[ \t]?/gm, '');
418
+ const top = this.lexer.state.top;
419
+ this.lexer.state.top = true;
420
+ const tokens = this.lexer.blockTokens(text);
421
+ this.lexer.state.top = top;
422
+ return {
423
+ type: 'blockquote',
424
+ raw: cap[0],
425
+ tokens,
426
+ text
427
+ };
428
+ }
429
+ }
430
+ list(src) {
431
+ let cap = this.rules.block.list.exec(src);
432
+ if (cap) {
433
+ let raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine, line, nextLine, rawLine, itemContents, endEarly;
434
+ let bull = cap[1].trim();
435
+ const isordered = bull.length > 1;
436
+ const list = {
437
+ type: 'list',
438
+ raw: '',
439
+ ordered: isordered,
440
+ start: isordered ? +bull.slice(0, -1) : '',
441
+ loose: false,
442
+ items: []
443
+ };
444
+ bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
442
445
  if (this.options.pedantic) {
443
- nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, " ");
444
- }
445
- if (fencesBeginRegex.test(nextLine)) {
446
- break;
447
- }
448
- if (headingBeginRegex.test(nextLine)) {
449
- break;
450
- }
451
- if (nextBulletRegex.test(nextLine)) {
452
- break;
453
- }
454
- if (hrRegex.test(src)) {
455
- break;
456
- }
457
- if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) {
458
- itemContents += "\n" + nextLine.slice(indent);
459
- } else {
460
- if (blankLine) {
461
- break;
462
- }
463
- if (line.search(/[^ ]/) >= 4) {
464
- break;
465
- }
466
- if (fencesBeginRegex.test(line)) {
467
- break;
468
- }
469
- if (headingBeginRegex.test(line)) {
470
- break;
471
- }
472
- if (hrRegex.test(line)) {
473
- break;
474
- }
475
- itemContents += "\n" + nextLine;
476
- }
477
- if (!blankLine && !nextLine.trim()) {
478
- blankLine = true;
479
- }
480
- raw += rawLine + "\n";
481
- src = src.substring(rawLine.length + 1);
482
- line = nextLine.slice(indent);
483
- }
484
- }
485
- if (!list.loose) {
486
- if (endsWithBlankLine) {
487
- list.loose = true;
488
- } else if (/\n *\n *$/.test(raw)) {
489
- endsWithBlankLine = true;
490
- }
491
- }
492
- if (this.options.gfm) {
493
- istask = /^\[[ xX]\] /.exec(itemContents);
494
- if (istask) {
495
- ischecked = istask[0] !== "[ ] ";
496
- itemContents = itemContents.replace(/^\[[ xX]\] +/, "");
497
- }
498
- }
499
- list.items.push({
500
- type: "list_item",
501
- raw,
502
- task: !!istask,
503
- checked: ischecked,
504
- loose: false,
505
- text: itemContents
506
- });
507
- list.raw += raw;
508
- }
509
- list.items[list.items.length - 1].raw = raw.trimRight();
510
- list.items[list.items.length - 1].text = itemContents.trimRight();
511
- list.raw = list.raw.trimRight();
512
- const l = list.items.length;
513
- for (i = 0; i < l; i++) {
514
- this.lexer.state.top = false;
515
- list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
516
- if (!list.loose) {
517
- const spacers = list.items[i].tokens.filter((t) => t.type === "space");
518
- const hasMultipleLineBreaks = spacers.length > 0 && spacers.some((t) => /\n.*\n/.test(t.raw));
519
- list.loose = hasMultipleLineBreaks;
520
- }
521
- }
522
- if (list.loose) {
523
- for (i = 0; i < l; i++) {
524
- list.items[i].loose = true;
525
- }
526
- }
527
- return list;
528
- }
529
- }
530
- html(src) {
531
- const cap = this.rules.block.html.exec(src);
532
- if (cap) {
533
- const token = {
534
- type: "html",
535
- block: true,
536
- raw: cap[0],
537
- pre: !this.options.sanitizer && (cap[1] === "pre" || cap[1] === "script" || cap[1] === "style"),
538
- text: cap[0]
539
- };
540
- if (this.options.sanitize) {
541
- const text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
542
- const paragraph = token;
543
- paragraph.type = "paragraph";
544
- paragraph.text = text;
545
- paragraph.tokens = this.lexer.inline(text);
546
- }
547
- return token;
548
- }
549
- }
550
- def(src) {
551
- const cap = this.rules.block.def.exec(src);
552
- if (cap) {
553
- const tag = cap[1].toLowerCase().replace(/\s+/g, " ");
554
- const href = cap[2] ? cap[2].replace(/^<(.*)>$/, "$1").replace(this.rules.inline._escapes, "$1") : "";
555
- const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline._escapes, "$1") : cap[3];
556
- return {
557
- type: "def",
558
- tag,
559
- raw: cap[0],
560
- href,
561
- title
562
- };
563
- }
564
- }
565
- table(src) {
566
- const cap = this.rules.block.table.exec(src);
567
- if (cap) {
568
- const item = {
569
- type: "table",
570
- // splitCells expects a number as second argument
571
- // @ts-expect-error
572
- header: splitCells(cap[1]).map((c) => {
573
- return { text: c };
574
- }),
575
- align: cap[2].replace(/^ *|\| *$/g, "").split(/ *\| */),
576
- rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, "").split("\n") : []
577
- };
578
- if (item.header.length === item.align.length) {
579
- item.raw = cap[0];
580
- let l = item.align.length;
581
- let i, j, k, row;
582
- for (i = 0; i < l; i++) {
583
- if (/^ *-+: *$/.test(item.align[i])) {
584
- item.align[i] = "right";
585
- } else if (/^ *:-+: *$/.test(item.align[i])) {
586
- item.align[i] = "center";
587
- } else if (/^ *:-+ *$/.test(item.align[i])) {
588
- item.align[i] = "left";
589
- } else {
590
- item.align[i] = null;
591
- }
592
- }
593
- l = item.rows.length;
594
- for (i = 0; i < l; i++) {
595
- item.rows[i] = splitCells(item.rows[i], item.header.length).map((c) => {
596
- return { text: c };
597
- });
598
- }
599
- l = item.header.length;
600
- for (j = 0; j < l; j++) {
601
- item.header[j].tokens = this.lexer.inline(item.header[j].text);
602
- }
603
- l = item.rows.length;
604
- for (j = 0; j < l; j++) {
605
- row = item.rows[j];
606
- for (k = 0; k < row.length; k++) {
607
- row[k].tokens = this.lexer.inline(row[k].text);
608
- }
609
- }
610
- return item;
611
- }
612
- }
613
- }
614
- lheading(src) {
615
- const cap = this.rules.block.lheading.exec(src);
616
- if (cap) {
617
- return {
618
- type: "heading",
619
- raw: cap[0],
620
- depth: cap[2].charAt(0) === "=" ? 1 : 2,
621
- text: cap[1],
622
- tokens: this.lexer.inline(cap[1])
623
- };
624
- }
625
- }
626
- paragraph(src) {
627
- const cap = this.rules.block.paragraph.exec(src);
628
- if (cap) {
629
- const text = cap[1].charAt(cap[1].length - 1) === "\n" ? cap[1].slice(0, -1) : cap[1];
630
- return {
631
- type: "paragraph",
632
- raw: cap[0],
633
- text,
634
- tokens: this.lexer.inline(text)
635
- };
636
- }
637
- }
638
- text(src) {
639
- const cap = this.rules.block.text.exec(src);
640
- if (cap) {
641
- return {
642
- type: "text",
643
- raw: cap[0],
644
- text: cap[0],
645
- tokens: this.lexer.inline(cap[0])
646
- };
647
- }
648
- }
649
- escape(src) {
650
- const cap = this.rules.inline.escape.exec(src);
651
- if (cap) {
652
- return {
653
- type: "escape",
654
- raw: cap[0],
655
- text: escape(cap[1])
656
- };
657
- }
658
- }
659
- tag(src) {
660
- const cap = this.rules.inline.tag.exec(src);
661
- if (cap) {
662
- if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
663
- this.lexer.state.inLink = true;
664
- } else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
665
- this.lexer.state.inLink = false;
666
- }
667
- if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
668
- this.lexer.state.inRawBlock = true;
669
- } else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
670
- this.lexer.state.inRawBlock = false;
671
- }
672
- return {
673
- type: this.options.sanitize ? "text" : "html",
674
- raw: cap[0],
675
- inLink: this.lexer.state.inLink,
676
- inRawBlock: this.lexer.state.inRawBlock,
677
- block: false,
678
- text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0]
679
- };
680
- }
681
- }
682
- link(src) {
683
- const cap = this.rules.inline.link.exec(src);
684
- if (cap) {
685
- const trimmedUrl = cap[2].trim();
686
- if (!this.options.pedantic && /^</.test(trimmedUrl)) {
687
- if (!/>$/.test(trimmedUrl)) {
688
- return;
689
- }
690
- const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), "\\");
691
- if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
692
- return;
693
- }
694
- } else {
695
- const lastParenIndex = findClosingBracket(cap[2], "()");
696
- if (lastParenIndex > -1) {
697
- const start = cap[0].indexOf("!") === 0 ? 5 : 4;
698
- const linkLen = start + cap[1].length + lastParenIndex;
699
- cap[2] = cap[2].substring(0, lastParenIndex);
700
- cap[0] = cap[0].substring(0, linkLen).trim();
701
- cap[3] = "";
702
- }
703
- }
704
- let href = cap[2];
705
- let title = "";
706
- if (this.options.pedantic) {
707
- const link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
708
- if (link) {
709
- href = link[1];
710
- title = link[3];
711
- }
712
- } else {
713
- title = cap[3] ? cap[3].slice(1, -1) : "";
714
- }
715
- href = href.trim();
716
- if (/^</.test(href)) {
717
- if (this.options.pedantic && !/>$/.test(trimmedUrl)) {
718
- href = href.slice(1);
719
- } else {
720
- href = href.slice(1, -1);
721
- }
722
- }
723
- return outputLink(cap, {
724
- href: href ? href.replace(this.rules.inline._escapes, "$1") : href,
725
- title: title ? title.replace(this.rules.inline._escapes, "$1") : title
726
- }, cap[0], this.lexer);
727
- }
728
- }
729
- reflink(src, links) {
730
- let cap;
731
- if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
732
- let link = (cap[2] || cap[1]).replace(/\s+/g, " ");
733
- link = links[link.toLowerCase()];
734
- if (!link) {
735
- const text = cap[0].charAt(0);
736
- return {
737
- type: "text",
738
- raw: text,
739
- text
740
- };
741
- }
742
- return outputLink(cap, link, cap[0], this.lexer);
743
- }
744
- }
745
- emStrong(src, maskedSrc, prevChar = "") {
746
- let match = this.rules.inline.emStrong.lDelim.exec(src);
747
- if (!match)
748
- return;
749
- if (match[3] && prevChar.match(/[\p{L}\p{N}]/u))
750
- return;
751
- const nextChar = match[1] || match[2] || "";
752
- if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
753
- const lLength = match[0].length - 1;
754
- let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
755
- const endReg = match[0][0] === "*" ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
756
- endReg.lastIndex = 0;
757
- maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
758
- while ((match = endReg.exec(maskedSrc)) != null) {
759
- rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
760
- if (!rDelim)
761
- continue;
762
- rLength = rDelim.length;
763
- if (match[3] || match[4]) {
764
- delimTotal += rLength;
765
- continue;
766
- } else if (match[5] || match[6]) {
767
- if (lLength % 3 && !((lLength + rLength) % 3)) {
768
- midDelimTotal += rLength;
769
- continue;
770
- }
771
- }
772
- delimTotal -= rLength;
773
- if (delimTotal > 0)
774
- continue;
775
- rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
776
- const raw = src.slice(0, lLength + match.index + rLength + 1);
777
- if (Math.min(lLength, rLength) % 2) {
778
- const text2 = raw.slice(1, -1);
779
- return {
780
- type: "em",
781
- raw,
782
- text: text2,
783
- tokens: this.lexer.inlineTokens(text2)
784
- };
446
+ bull = isordered ? bull : '[*+-]';
447
+ }
448
+ // Get next list item
449
+ const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
450
+ // Check if current bullet point can start a new List Item
451
+ while (src) {
452
+ endEarly = false;
453
+ if (!(cap = itemRegex.exec(src))) {
454
+ break;
455
+ }
456
+ if (this.rules.block.hr.test(src)) { // End list if bullet was actually HR (possibly move into itemRegex?)
457
+ break;
458
+ }
459
+ raw = cap[0];
460
+ src = src.substring(raw.length);
461
+ line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length));
462
+ nextLine = src.split('\n', 1)[0];
463
+ if (this.options.pedantic) {
464
+ indent = 2;
465
+ itemContents = line.trimLeft();
466
+ }
467
+ else {
468
+ indent = cap[2].search(/[^ ]/); // Find first non-space char
469
+ indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
470
+ itemContents = line.slice(indent);
471
+ indent += cap[1].length;
472
+ }
473
+ blankLine = false;
474
+ if (!line && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
475
+ raw += nextLine + '\n';
476
+ src = src.substring(nextLine.length + 1);
477
+ endEarly = true;
478
+ }
479
+ if (!endEarly) {
480
+ const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
481
+ const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
482
+ const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
483
+ const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
484
+ // Check if following lines should be included in List Item
485
+ while (src) {
486
+ rawLine = src.split('\n', 1)[0];
487
+ nextLine = rawLine;
488
+ // Re-align to follow commonmark nesting rules
489
+ if (this.options.pedantic) {
490
+ nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
491
+ }
492
+ // End list item if found code fences
493
+ if (fencesBeginRegex.test(nextLine)) {
494
+ break;
495
+ }
496
+ // End list item if found start of new heading
497
+ if (headingBeginRegex.test(nextLine)) {
498
+ break;
499
+ }
500
+ // End list item if found start of new bullet
501
+ if (nextBulletRegex.test(nextLine)) {
502
+ break;
503
+ }
504
+ // Horizontal rule found
505
+ if (hrRegex.test(src)) {
506
+ break;
507
+ }
508
+ if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
509
+ itemContents += '\n' + nextLine.slice(indent);
510
+ }
511
+ else {
512
+ // not enough indentation
513
+ if (blankLine) {
514
+ break;
515
+ }
516
+ // paragraph continuation unless last line was a different block level element
517
+ if (line.search(/[^ ]/) >= 4) { // indented code block
518
+ break;
519
+ }
520
+ if (fencesBeginRegex.test(line)) {
521
+ break;
522
+ }
523
+ if (headingBeginRegex.test(line)) {
524
+ break;
525
+ }
526
+ if (hrRegex.test(line)) {
527
+ break;
528
+ }
529
+ itemContents += '\n' + nextLine;
530
+ }
531
+ if (!blankLine && !nextLine.trim()) { // Check if current line is blank
532
+ blankLine = true;
533
+ }
534
+ raw += rawLine + '\n';
535
+ src = src.substring(rawLine.length + 1);
536
+ line = nextLine.slice(indent);
537
+ }
538
+ }
539
+ if (!list.loose) {
540
+ // If the previous item ended with a blank line, the list is loose
541
+ if (endsWithBlankLine) {
542
+ list.loose = true;
543
+ }
544
+ else if (/\n *\n *$/.test(raw)) {
545
+ endsWithBlankLine = true;
546
+ }
547
+ }
548
+ // Check for task list items
549
+ if (this.options.gfm) {
550
+ istask = /^\[[ xX]\] /.exec(itemContents);
551
+ if (istask) {
552
+ ischecked = istask[0] !== '[ ] ';
553
+ itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
554
+ }
555
+ }
556
+ list.items.push({
557
+ type: 'list_item',
558
+ raw,
559
+ task: !!istask,
560
+ checked: ischecked,
561
+ loose: false,
562
+ text: itemContents
563
+ });
564
+ list.raw += raw;
565
+ }
566
+ // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
567
+ list.items[list.items.length - 1].raw = raw.trimRight();
568
+ list.items[list.items.length - 1].text = itemContents.trimRight();
569
+ list.raw = list.raw.trimRight();
570
+ const l = list.items.length;
571
+ // Item child tokens handled here at end because we needed to have the final item to trim it first
572
+ for (i = 0; i < l; i++) {
573
+ this.lexer.state.top = false;
574
+ list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
575
+ if (!list.loose) {
576
+ // Check if list should be loose
577
+ const spacers = list.items[i].tokens.filter(t => t.type === 'space');
578
+ const hasMultipleLineBreaks = spacers.length > 0 && spacers.some(t => /\n.*\n/.test(t.raw));
579
+ list.loose = hasMultipleLineBreaks;
580
+ }
581
+ }
582
+ // Set all items to loose if list is loose
583
+ if (list.loose) {
584
+ for (i = 0; i < l; i++) {
585
+ list.items[i].loose = true;
586
+ }
587
+ }
588
+ return list;
589
+ }
590
+ }
591
+ html(src) {
592
+ const cap = this.rules.block.html.exec(src);
593
+ if (cap) {
594
+ const token = {
595
+ type: 'html',
596
+ block: true,
597
+ raw: cap[0],
598
+ pre: !this.options.sanitizer
599
+ && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
600
+ text: cap[0]
601
+ };
602
+ if (this.options.sanitize) {
603
+ const text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
604
+ const paragraph = token;
605
+ paragraph.type = 'paragraph';
606
+ paragraph.text = text;
607
+ paragraph.tokens = this.lexer.inline(text);
608
+ }
609
+ return token;
610
+ }
611
+ }
612
+ def(src) {
613
+ const cap = this.rules.block.def.exec(src);
614
+ if (cap) {
615
+ const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
616
+ const href = cap[2] ? cap[2].replace(/^<(.*)>$/, '$1').replace(this.rules.inline._escapes, '$1') : '';
617
+ const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline._escapes, '$1') : cap[3];
618
+ return {
619
+ type: 'def',
620
+ tag,
621
+ raw: cap[0],
622
+ href,
623
+ title
624
+ };
785
625
  }
786
- const text = raw.slice(2, -2);
787
- return {
788
- type: "strong",
789
- raw,
790
- text,
791
- tokens: this.lexer.inlineTokens(text)
792
- };
793
- }
794
- }
795
- }
796
- codespan(src) {
797
- const cap = this.rules.inline.code.exec(src);
798
- if (cap) {
799
- let text = cap[2].replace(/\n/g, " ");
800
- const hasNonSpaceChars = /[^ ]/.test(text);
801
- const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
802
- if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
803
- text = text.substring(1, text.length - 1);
804
- }
805
- text = escape(text, true);
806
- return {
807
- type: "codespan",
808
- raw: cap[0],
809
- text
810
- };
811
- }
812
- }
813
- br(src) {
814
- const cap = this.rules.inline.br.exec(src);
815
- if (cap) {
816
- return {
817
- type: "br",
818
- raw: cap[0]
819
- };
820
- }
821
- }
822
- del(src) {
823
- const cap = this.rules.inline.del.exec(src);
824
- if (cap) {
825
- return {
826
- type: "del",
827
- raw: cap[0],
828
- text: cap[2],
829
- tokens: this.lexer.inlineTokens(cap[2])
830
- };
831
- }
832
- }
833
- autolink(src, mangle2) {
834
- const cap = this.rules.inline.autolink.exec(src);
835
- if (cap) {
836
- let text, href;
837
- if (cap[2] === "@") {
838
- text = escape(this.options.mangle ? mangle2(cap[1]) : cap[1]);
839
- href = "mailto:" + text;
840
- } else {
841
- text = escape(cap[1]);
842
- href = text;
843
- }
844
- return {
845
- type: "link",
846
- raw: cap[0],
847
- text,
848
- href,
849
- tokens: [
850
- {
851
- type: "text",
852
- raw: text,
853
- text
854
- }
855
- ]
856
- };
857
- }
858
- }
859
- url(src, mangle2) {
860
- let cap;
861
- if (cap = this.rules.inline.url.exec(src)) {
862
- let text, href;
863
- if (cap[2] === "@") {
864
- text = escape(this.options.mangle ? mangle2(cap[0]) : cap[0]);
865
- href = "mailto:" + text;
866
- } else {
867
- let prevCapZero;
868
- do {
869
- prevCapZero = cap[0];
870
- cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
871
- } while (prevCapZero !== cap[0]);
872
- text = escape(cap[0]);
873
- if (cap[1] === "www.") {
874
- href = "http://" + cap[0];
875
- } else {
876
- href = cap[0];
877
- }
878
- }
879
- return {
880
- type: "link",
881
- raw: cap[0],
882
- text,
883
- href,
884
- tokens: [
885
- {
886
- type: "text",
887
- raw: text,
888
- text
889
- }
890
- ]
891
- };
892
- }
893
- }
894
- inlineText(src, smartypants2) {
895
- const cap = this.rules.inline.text.exec(src);
896
- if (cap) {
897
- let text;
898
- if (this.lexer.state.inRawBlock) {
899
- text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0];
900
- } else {
901
- text = escape(this.options.smartypants ? smartypants2(cap[0]) : cap[0]);
902
- }
903
- return {
904
- type: "text",
905
- raw: cap[0],
906
- text
907
- };
908
- }
909
- }
910
- };
626
+ }
627
+ table(src) {
628
+ const cap = this.rules.block.table.exec(src);
629
+ if (cap) {
630
+ const item = {
631
+ type: 'table',
632
+ raw: cap[0],
633
+ header: splitCells(cap[1]).map(c => {
634
+ return { text: c };
635
+ }),
636
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
637
+ rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
638
+ };
639
+ if (item.header.length === item.align.length) {
640
+ let l = item.align.length;
641
+ let i, j, k, row;
642
+ for (i = 0; i < l; i++) {
643
+ if (/^ *-+: *$/.test(item.align[i])) {
644
+ item.align[i] = 'right';
645
+ }
646
+ else if (/^ *:-+: *$/.test(item.align[i])) {
647
+ item.align[i] = 'center';
648
+ }
649
+ else if (/^ *:-+ *$/.test(item.align[i])) {
650
+ item.align[i] = 'left';
651
+ }
652
+ else {
653
+ item.align[i] = null;
654
+ }
655
+ }
656
+ l = item.rows.length;
657
+ for (i = 0; i < l; i++) {
658
+ item.rows[i] = splitCells(item.rows[i], item.header.length).map(c => {
659
+ return { text: c };
660
+ });
661
+ }
662
+ // parse child tokens inside headers and cells
663
+ // header child tokens
664
+ l = item.header.length;
665
+ for (j = 0; j < l; j++) {
666
+ item.header[j].tokens = this.lexer.inline(item.header[j].text);
667
+ }
668
+ // cell child tokens
669
+ l = item.rows.length;
670
+ for (j = 0; j < l; j++) {
671
+ row = item.rows[j];
672
+ for (k = 0; k < row.length; k++) {
673
+ row[k].tokens = this.lexer.inline(row[k].text);
674
+ }
675
+ }
676
+ return item;
677
+ }
678
+ }
679
+ }
680
+ lheading(src) {
681
+ const cap = this.rules.block.lheading.exec(src);
682
+ if (cap) {
683
+ return {
684
+ type: 'heading',
685
+ raw: cap[0],
686
+ depth: cap[2].charAt(0) === '=' ? 1 : 2,
687
+ text: cap[1],
688
+ tokens: this.lexer.inline(cap[1])
689
+ };
690
+ }
691
+ }
692
+ paragraph(src) {
693
+ const cap = this.rules.block.paragraph.exec(src);
694
+ if (cap) {
695
+ const text = cap[1].charAt(cap[1].length - 1) === '\n'
696
+ ? cap[1].slice(0, -1)
697
+ : cap[1];
698
+ return {
699
+ type: 'paragraph',
700
+ raw: cap[0],
701
+ text,
702
+ tokens: this.lexer.inline(text)
703
+ };
704
+ }
705
+ }
706
+ text(src) {
707
+ const cap = this.rules.block.text.exec(src);
708
+ if (cap) {
709
+ return {
710
+ type: 'text',
711
+ raw: cap[0],
712
+ text: cap[0],
713
+ tokens: this.lexer.inline(cap[0])
714
+ };
715
+ }
716
+ }
717
+ escape(src) {
718
+ const cap = this.rules.inline.escape.exec(src);
719
+ if (cap) {
720
+ return {
721
+ type: 'escape',
722
+ raw: cap[0],
723
+ text: escape(cap[1])
724
+ };
725
+ }
726
+ }
727
+ tag(src) {
728
+ const cap = this.rules.inline.tag.exec(src);
729
+ if (cap) {
730
+ if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
731
+ this.lexer.state.inLink = true;
732
+ }
733
+ else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
734
+ this.lexer.state.inLink = false;
735
+ }
736
+ if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
737
+ this.lexer.state.inRawBlock = true;
738
+ }
739
+ else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
740
+ this.lexer.state.inRawBlock = false;
741
+ }
742
+ return {
743
+ type: this.options.sanitize
744
+ ? 'text'
745
+ : 'html',
746
+ raw: cap[0],
747
+ inLink: this.lexer.state.inLink,
748
+ inRawBlock: this.lexer.state.inRawBlock,
749
+ block: false,
750
+ text: this.options.sanitize
751
+ ? (this.options.sanitizer
752
+ ? this.options.sanitizer(cap[0])
753
+ : escape(cap[0]))
754
+ : cap[0]
755
+ };
756
+ }
757
+ }
758
+ link(src) {
759
+ const cap = this.rules.inline.link.exec(src);
760
+ if (cap) {
761
+ const trimmedUrl = cap[2].trim();
762
+ if (!this.options.pedantic && /^</.test(trimmedUrl)) {
763
+ // commonmark requires matching angle brackets
764
+ if (!(/>$/.test(trimmedUrl))) {
765
+ return;
766
+ }
767
+ // ending angle bracket cannot be escaped
768
+ const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
769
+ if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
770
+ return;
771
+ }
772
+ }
773
+ else {
774
+ // find closing parenthesis
775
+ const lastParenIndex = findClosingBracket(cap[2], '()');
776
+ if (lastParenIndex > -1) {
777
+ const start = cap[0].indexOf('!') === 0 ? 5 : 4;
778
+ const linkLen = start + cap[1].length + lastParenIndex;
779
+ cap[2] = cap[2].substring(0, lastParenIndex);
780
+ cap[0] = cap[0].substring(0, linkLen).trim();
781
+ cap[3] = '';
782
+ }
783
+ }
784
+ let href = cap[2];
785
+ let title = '';
786
+ if (this.options.pedantic) {
787
+ // split pedantic href and title
788
+ const link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
789
+ if (link) {
790
+ href = link[1];
791
+ title = link[3];
792
+ }
793
+ }
794
+ else {
795
+ title = cap[3] ? cap[3].slice(1, -1) : '';
796
+ }
797
+ href = href.trim();
798
+ if (/^</.test(href)) {
799
+ if (this.options.pedantic && !(/>$/.test(trimmedUrl))) {
800
+ // pedantic allows starting angle bracket without ending angle bracket
801
+ href = href.slice(1);
802
+ }
803
+ else {
804
+ href = href.slice(1, -1);
805
+ }
806
+ }
807
+ return outputLink(cap, {
808
+ href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
809
+ title: title ? title.replace(this.rules.inline._escapes, '$1') : title
810
+ }, cap[0], this.lexer);
811
+ }
812
+ }
813
+ reflink(src, links) {
814
+ let cap;
815
+ if ((cap = this.rules.inline.reflink.exec(src))
816
+ || (cap = this.rules.inline.nolink.exec(src))) {
817
+ let link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
818
+ link = links[link.toLowerCase()];
819
+ if (!link) {
820
+ const text = cap[0].charAt(0);
821
+ return {
822
+ type: 'text',
823
+ raw: text,
824
+ text
825
+ };
826
+ }
827
+ return outputLink(cap, link, cap[0], this.lexer);
828
+ }
829
+ }
830
+ emStrong(src, maskedSrc, prevChar = '') {
831
+ let match = this.rules.inline.emStrong.lDelim.exec(src);
832
+ if (!match)
833
+ return;
834
+ // _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
835
+ if (match[3] && prevChar.match(/[\p{L}\p{N}]/u))
836
+ return;
837
+ const nextChar = match[1] || match[2] || '';
838
+ if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
839
+ const lLength = match[0].length - 1;
840
+ let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
841
+ const endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
842
+ endReg.lastIndex = 0;
843
+ // Clip maskedSrc to same section of string as src (move to lexer?)
844
+ maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
845
+ while ((match = endReg.exec(maskedSrc)) != null) {
846
+ rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
847
+ if (!rDelim)
848
+ continue; // skip single * in __abc*abc__
849
+ rLength = rDelim.length;
850
+ if (match[3] || match[4]) { // found another Left Delim
851
+ delimTotal += rLength;
852
+ continue;
853
+ }
854
+ else if (match[5] || match[6]) { // either Left or Right Delim
855
+ if (lLength % 3 && !((lLength + rLength) % 3)) {
856
+ midDelimTotal += rLength;
857
+ continue; // CommonMark Emphasis Rules 9-10
858
+ }
859
+ }
860
+ delimTotal -= rLength;
861
+ if (delimTotal > 0)
862
+ continue; // Haven't found enough closing delimiters
863
+ // Remove extra characters. *a*** -> *a*
864
+ rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
865
+ const raw = src.slice(0, lLength + match.index + rLength + 1);
866
+ // Create `em` if smallest delimiter has odd char count. *a***
867
+ if (Math.min(lLength, rLength) % 2) {
868
+ const text = raw.slice(1, -1);
869
+ return {
870
+ type: 'em',
871
+ raw,
872
+ text,
873
+ tokens: this.lexer.inlineTokens(text)
874
+ };
875
+ }
876
+ // Create 'strong' if smallest delimiter has even char count. **a***
877
+ const text = raw.slice(2, -2);
878
+ return {
879
+ type: 'strong',
880
+ raw,
881
+ text,
882
+ tokens: this.lexer.inlineTokens(text)
883
+ };
884
+ }
885
+ }
886
+ }
887
+ codespan(src) {
888
+ const cap = this.rules.inline.code.exec(src);
889
+ if (cap) {
890
+ let text = cap[2].replace(/\n/g, ' ');
891
+ const hasNonSpaceChars = /[^ ]/.test(text);
892
+ const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
893
+ if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
894
+ text = text.substring(1, text.length - 1);
895
+ }
896
+ text = escape(text, true);
897
+ return {
898
+ type: 'codespan',
899
+ raw: cap[0],
900
+ text
901
+ };
902
+ }
903
+ }
904
+ br(src) {
905
+ const cap = this.rules.inline.br.exec(src);
906
+ if (cap) {
907
+ return {
908
+ type: 'br',
909
+ raw: cap[0]
910
+ };
911
+ }
912
+ }
913
+ del(src) {
914
+ const cap = this.rules.inline.del.exec(src);
915
+ if (cap) {
916
+ return {
917
+ type: 'del',
918
+ raw: cap[0],
919
+ text: cap[2],
920
+ tokens: this.lexer.inlineTokens(cap[2])
921
+ };
922
+ }
923
+ }
924
+ autolink(src, mangle) {
925
+ const cap = this.rules.inline.autolink.exec(src);
926
+ if (cap) {
927
+ let text, href;
928
+ if (cap[2] === '@') {
929
+ text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
930
+ href = 'mailto:' + text;
931
+ }
932
+ else {
933
+ text = escape(cap[1]);
934
+ href = text;
935
+ }
936
+ return {
937
+ type: 'link',
938
+ raw: cap[0],
939
+ text,
940
+ href,
941
+ tokens: [
942
+ {
943
+ type: 'text',
944
+ raw: text,
945
+ text
946
+ }
947
+ ]
948
+ };
949
+ }
950
+ }
951
+ url(src, mangle) {
952
+ let cap;
953
+ if (cap = this.rules.inline.url.exec(src)) {
954
+ let text, href;
955
+ if (cap[2] === '@') {
956
+ text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
957
+ href = 'mailto:' + text;
958
+ }
959
+ else {
960
+ // do extended autolink path validation
961
+ let prevCapZero;
962
+ do {
963
+ prevCapZero = cap[0];
964
+ cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
965
+ } while (prevCapZero !== cap[0]);
966
+ text = escape(cap[0]);
967
+ if (cap[1] === 'www.') {
968
+ href = 'http://' + cap[0];
969
+ }
970
+ else {
971
+ href = cap[0];
972
+ }
973
+ }
974
+ return {
975
+ type: 'link',
976
+ raw: cap[0],
977
+ text,
978
+ href,
979
+ tokens: [
980
+ {
981
+ type: 'text',
982
+ raw: text,
983
+ text
984
+ }
985
+ ]
986
+ };
987
+ }
988
+ }
989
+ inlineText(src, smartypants) {
990
+ const cap = this.rules.inline.text.exec(src);
991
+ if (cap) {
992
+ let text;
993
+ if (this.lexer.state.inRawBlock) {
994
+ text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0];
995
+ }
996
+ else {
997
+ text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
998
+ }
999
+ return {
1000
+ type: 'text',
1001
+ raw: cap[0],
1002
+ text
1003
+ };
1004
+ }
1005
+ }
1006
+ }
911
1007
 
912
- // src/rules.ts
913
- var block = {
914
- newline: /^(?: *(?:\n|$))+/,
915
- code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
916
- fences: /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
917
- hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
918
- heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
919
- blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
920
- list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
921
- html: "^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",
922
- def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
923
- table: noopTest,
924
- lheading: /^((?:(?!^bull ).|\n(?!\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
925
- // regex template, placeholders will be replaced according to different paragraph
926
- // interruption rules of commonmark and the original markdown spec:
927
- _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
928
- text: /^[^\n]+/
1008
+ /**
1009
+ * Block-Level Grammar
1010
+ */
1011
+ // Not all rules are defined in the object literal
1012
+ // @ts-expect-error
1013
+ const block = {
1014
+ newline: /^(?: *(?:\n|$))+/,
1015
+ code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
1016
+ fences: /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1017
+ hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
1018
+ heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
1019
+ blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
1020
+ list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
1021
+ html: '^ {0,3}(?:' // optional indentation
1022
+ + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1023
+ + '|comment[^\\n]*(\\n+|$)' // (2)
1024
+ + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
1025
+ + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
1026
+ + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
1027
+ + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
1028
+ + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
1029
+ + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
1030
+ + ')',
1031
+ def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
1032
+ table: noopTest,
1033
+ lheading: /^((?:(?!^bull ).|\n(?!\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
1034
+ // regex template, placeholders will be replaced according to different paragraph
1035
+ // interruption rules of commonmark and the original markdown spec:
1036
+ _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
1037
+ text: /^[^\n]+/
929
1038
  };
930
1039
  block._label = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
931
1040
  block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
932
- block.def = edit(block.def).replace("label", block._label).replace("title", block._title).getRegex();
1041
+ block.def = edit(block.def)
1042
+ .replace('label', block._label)
1043
+ .replace('title', block._title)
1044
+ .getRegex();
933
1045
  block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
934
- block.listItemStart = edit(/^( *)(bull) */).replace("bull", block.bullet).getRegex();
935
- block.list = edit(block.list).replace(/bull/g, block.bullet).replace("hr", "\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def", "\\n+(?=" + block.def.source + ")").getRegex();
936
- block._tag = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
1046
+ block.listItemStart = edit(/^( *)(bull) */)
1047
+ .replace('bull', block.bullet)
1048
+ .getRegex();
1049
+ block.list = edit(block.list)
1050
+ .replace(/bull/g, block.bullet)
1051
+ .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
1052
+ .replace('def', '\\n+(?=' + block.def.source + ')')
1053
+ .getRegex();
1054
+ block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
1055
+ + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
1056
+ + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
1057
+ + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
1058
+ + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
1059
+ + '|track|ul';
937
1060
  block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
938
- block.html = edit(block.html, "i").replace("comment", block._comment).replace("tag", block._tag).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
939
- block.lheading = edit(block.lheading).replace(/bull/g, block.bullet).getRegex();
940
- block.paragraph = edit(block._paragraph).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
941
- block.blockquote = edit(block.blockquote).replace("paragraph", block.paragraph).getRegex();
1061
+ block.html = edit(block.html, 'i')
1062
+ .replace('comment', block._comment)
1063
+ .replace('tag', block._tag)
1064
+ .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
1065
+ .getRegex();
1066
+ block.lheading = edit(block.lheading)
1067
+ .replace(/bull/g, block.bullet) // lists can interrupt
1068
+ .getRegex();
1069
+ block.paragraph = edit(block._paragraph)
1070
+ .replace('hr', block.hr)
1071
+ .replace('heading', ' {0,3}#{1,6} ')
1072
+ .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1073
+ .replace('|table', '')
1074
+ .replace('blockquote', ' {0,3}>')
1075
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1076
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1077
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1078
+ .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
1079
+ .getRegex();
1080
+ block.blockquote = edit(block.blockquote)
1081
+ .replace('paragraph', block.paragraph)
1082
+ .getRegex();
1083
+ /**
1084
+ * Normal Block Grammar
1085
+ */
942
1086
  block.normal = { ...block };
1087
+ /**
1088
+ * GFM Block Grammar
1089
+ */
943
1090
  block.gfm = {
944
- ...block.normal,
945
- table: "^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"
946
- // Cells
1091
+ ...block.normal,
1092
+ table: '^ *([^\\n ].*\\|.*)\\n' // Header
1093
+ + ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?' // Align
1094
+ + '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
947
1095
  };
948
- block.gfm.table = edit(block.gfm.table).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("blockquote", " {0,3}>").replace("code", " {4}[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
949
- block.gfm.paragraph = edit(block._paragraph).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("table", block.gfm.table).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
1096
+ block.gfm.table = edit(block.gfm.table)
1097
+ .replace('hr', block.hr)
1098
+ .replace('heading', ' {0,3}#{1,6} ')
1099
+ .replace('blockquote', ' {0,3}>')
1100
+ .replace('code', ' {4}[^\\n]')
1101
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1102
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1103
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1104
+ .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1105
+ .getRegex();
1106
+ block.gfm.paragraph = edit(block._paragraph)
1107
+ .replace('hr', block.hr)
1108
+ .replace('heading', ' {0,3}#{1,6} ')
1109
+ .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1110
+ .replace('table', block.gfm.table) // interrupt paragraphs with table
1111
+ .replace('blockquote', ' {0,3}>')
1112
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1113
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1114
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1115
+ .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
1116
+ .getRegex();
1117
+ /**
1118
+ * Pedantic grammar (original John Gruber's loose markdown specification)
1119
+ */
950
1120
  block.pedantic = {
951
- ...block.normal,
952
- html: edit(
953
- `^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`
954
- ).replace("comment", block._comment).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
955
- def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
956
- heading: /^(#{1,6})(.*)(?:\n+|$)/,
957
- fences: noopTest,
958
- // fences not supported
959
- lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
960
- paragraph: edit(block.normal._paragraph).replace("hr", block.hr).replace("heading", " *#{1,6} *[^\n]").replace("lheading", block.lheading).replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").getRegex()
1121
+ ...block.normal,
1122
+ html: edit('^ *(?:comment *(?:\\n|\\s*$)'
1123
+ + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
1124
+ + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
1125
+ .replace('comment', block._comment)
1126
+ .replace(/tag/g, '(?!(?:'
1127
+ + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
1128
+ + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
1129
+ + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
1130
+ .getRegex(),
1131
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1132
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
1133
+ fences: noopTest,
1134
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
1135
+ paragraph: edit(block.normal._paragraph)
1136
+ .replace('hr', block.hr)
1137
+ .replace('heading', ' *#{1,6} *[^\n]')
1138
+ .replace('lheading', block.lheading)
1139
+ .replace('blockquote', ' {0,3}>')
1140
+ .replace('|fences', '')
1141
+ .replace('|list', '')
1142
+ .replace('|html', '')
1143
+ .getRegex()
961
1144
  };
962
- var inline = {
963
- escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
964
- autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
965
- url: noopTest,
966
- tag: "^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",
967
- // CDATA section
968
- link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
969
- reflink: /^!?\[(label)\]\[(ref)\]/,
970
- nolink: /^!?\[(ref)\](?:\[\])?/,
971
- reflinkSearch: "reflink|nolink(?!\\()",
972
- emStrong: {
973
- lDelim: /^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,
974
- // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
975
- // | Skip orphan inside strong | Consume to delim | (1) #*** | (2) a***#, a*** | (3) #***a, ***a | (4) ***# | (5) #***# | (6) a***a
976
- rDelimAst: /^[^_*]*?__[^_*]*?\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\*)[punct](\*+)(?=[\s]|$)|[^punct\s](\*+)(?!\*)(?=[punct\s]|$)|(?!\*)[punct\s](\*+)(?=[^punct\s])|[\s](\*+)(?!\*)(?=[punct])|(?!\*)[punct](\*+)(?!\*)(?=[punct])|[^punct\s](\*+)(?=[^punct\s])/,
977
- rDelimUnd: /^[^_*]*?\*\*[^_*]*?_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\s]|$)|[^punct\s](_+)(?!_)(?=[punct\s]|$)|(?!_)[punct\s](_+)(?=[^punct\s])|[\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])/
978
- // ^- Not allowed for _
979
- },
980
- code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
981
- br: /^( {2,}|\\)\n(?!\s*$)/,
982
- del: noopTest,
983
- text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
984
- punctuation: /^((?![*_])[\spunctuation])/
1145
+ /**
1146
+ * Inline-Level Grammar
1147
+ */
1148
+ // Not all rules are defined in the object literal
1149
+ // @ts-expect-error
1150
+ const inline = {
1151
+ escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
1152
+ autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
1153
+ url: noopTest,
1154
+ tag: '^comment'
1155
+ + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
1156
+ + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
1157
+ + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
1158
+ + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
1159
+ + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
1160
+ link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
1161
+ reflink: /^!?\[(label)\]\[(ref)\]/,
1162
+ nolink: /^!?\[(ref)\](?:\[\])?/,
1163
+ reflinkSearch: 'reflink|nolink(?!\\()',
1164
+ emStrong: {
1165
+ lDelim: /^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,
1166
+ // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
1167
+ // | Skip orphan inside strong | Consume to delim | (1) #*** | (2) a***#, a*** | (3) #***a, ***a | (4) ***# | (5) #***# | (6) a***a
1168
+ rDelimAst: /^[^_*]*?__[^_*]*?\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\*)[punct](\*+)(?=[\s]|$)|[^punct\s](\*+)(?!\*)(?=[punct\s]|$)|(?!\*)[punct\s](\*+)(?=[^punct\s])|[\s](\*+)(?!\*)(?=[punct])|(?!\*)[punct](\*+)(?!\*)(?=[punct])|[^punct\s](\*+)(?=[^punct\s])/,
1169
+ rDelimUnd: /^[^_*]*?\*\*[^_*]*?_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\s]|$)|[^punct\s](_+)(?!_)(?=[punct\s]|$)|(?!_)[punct\s](_+)(?=[^punct\s])|[\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])/ // ^- Not allowed for _
1170
+ },
1171
+ code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1172
+ br: /^( {2,}|\\)\n(?!\s*$)/,
1173
+ del: noopTest,
1174
+ text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
1175
+ punctuation: /^((?![*_])[\spunctuation])/
985
1176
  };
986
- inline._punctuation = "\\p{P}$+<=>`^|~";
987
- inline.punctuation = edit(inline.punctuation, "u").replace(/punctuation/g, inline._punctuation).getRegex();
1177
+ // list of unicode punctuation marks, plus any missing characters from CommonMark spec
1178
+ inline._punctuation = '\\p{P}$+<=>`^|~';
1179
+ inline.punctuation = edit(inline.punctuation, 'u').replace(/punctuation/g, inline._punctuation).getRegex();
1180
+ // sequences em should skip over [title](link), `code`, <html>
988
1181
  inline.blockSkip = /\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g;
989
1182
  inline.anyPunctuation = /\\[punct]/g;
990
1183
  inline._escapes = /\\([punct])/g;
991
- inline._comment = edit(block._comment).replace("(?:-->|$)", "-->").getRegex();
992
- inline.emStrong.lDelim = edit(inline.emStrong.lDelim, "u").replace(/punct/g, inline._punctuation).getRegex();
993
- inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, "gu").replace(/punct/g, inline._punctuation).getRegex();
994
- inline.emStrong.rDelimUnd = edit(inline.emStrong.rDelimUnd, "gu").replace(/punct/g, inline._punctuation).getRegex();
995
- inline.anyPunctuation = edit(inline.anyPunctuation, "gu").replace(/punct/g, inline._punctuation).getRegex();
996
- inline._escapes = edit(inline._escapes, "gu").replace(/punct/g, inline._punctuation).getRegex();
1184
+ inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
1185
+ inline.emStrong.lDelim = edit(inline.emStrong.lDelim, 'u')
1186
+ .replace(/punct/g, inline._punctuation)
1187
+ .getRegex();
1188
+ inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, 'gu')
1189
+ .replace(/punct/g, inline._punctuation)
1190
+ .getRegex();
1191
+ inline.emStrong.rDelimUnd = edit(inline.emStrong.rDelimUnd, 'gu')
1192
+ .replace(/punct/g, inline._punctuation)
1193
+ .getRegex();
1194
+ inline.anyPunctuation = edit(inline.anyPunctuation, 'gu')
1195
+ .replace(/punct/g, inline._punctuation)
1196
+ .getRegex();
1197
+ inline._escapes = edit(inline._escapes, 'gu')
1198
+ .replace(/punct/g, inline._punctuation)
1199
+ .getRegex();
997
1200
  inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
998
1201
  inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
999
- inline.autolink = edit(inline.autolink).replace("scheme", inline._scheme).replace("email", inline._email).getRegex();
1202
+ inline.autolink = edit(inline.autolink)
1203
+ .replace('scheme', inline._scheme)
1204
+ .replace('email', inline._email)
1205
+ .getRegex();
1000
1206
  inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
1001
- inline.tag = edit(inline.tag).replace("comment", inline._comment).replace("attribute", inline._attribute).getRegex();
1207
+ inline.tag = edit(inline.tag)
1208
+ .replace('comment', inline._comment)
1209
+ .replace('attribute', inline._attribute)
1210
+ .getRegex();
1002
1211
  inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1003
1212
  inline._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
1004
1213
  inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1005
- inline.link = edit(inline.link).replace("label", inline._label).replace("href", inline._href).replace("title", inline._title).getRegex();
1006
- inline.reflink = edit(inline.reflink).replace("label", inline._label).replace("ref", block._label).getRegex();
1007
- inline.nolink = edit(inline.nolink).replace("ref", block._label).getRegex();
1008
- inline.reflinkSearch = edit(inline.reflinkSearch, "g").replace("reflink", inline.reflink).replace("nolink", inline.nolink).getRegex();
1214
+ inline.link = edit(inline.link)
1215
+ .replace('label', inline._label)
1216
+ .replace('href', inline._href)
1217
+ .replace('title', inline._title)
1218
+ .getRegex();
1219
+ inline.reflink = edit(inline.reflink)
1220
+ .replace('label', inline._label)
1221
+ .replace('ref', block._label)
1222
+ .getRegex();
1223
+ inline.nolink = edit(inline.nolink)
1224
+ .replace('ref', block._label)
1225
+ .getRegex();
1226
+ inline.reflinkSearch = edit(inline.reflinkSearch, 'g')
1227
+ .replace('reflink', inline.reflink)
1228
+ .replace('nolink', inline.nolink)
1229
+ .getRegex();
1230
+ /**
1231
+ * Normal Inline Grammar
1232
+ */
1009
1233
  inline.normal = { ...inline };
1234
+ /**
1235
+ * Pedantic Inline Grammar
1236
+ */
1010
1237
  inline.pedantic = {
1011
- ...inline.normal,
1012
- strong: {
1013
- start: /^__|\*\*/,
1014
- middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
1015
- endAst: /\*\*(?!\*)/g,
1016
- endUnd: /__(?!_)/g
1017
- },
1018
- em: {
1019
- start: /^_|\*/,
1020
- middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
1021
- endAst: /\*(?!\*)/g,
1022
- endUnd: /_(?!_)/g
1023
- },
1024
- link: edit(/^!?\[(label)\]\((.*?)\)/).replace("label", inline._label).getRegex(),
1025
- reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", inline._label).getRegex()
1238
+ ...inline.normal,
1239
+ strong: {
1240
+ start: /^__|\*\*/,
1241
+ middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
1242
+ endAst: /\*\*(?!\*)/g,
1243
+ endUnd: /__(?!_)/g
1244
+ },
1245
+ em: {
1246
+ start: /^_|\*/,
1247
+ middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
1248
+ endAst: /\*(?!\*)/g,
1249
+ endUnd: /_(?!_)/g
1250
+ },
1251
+ link: edit(/^!?\[(label)\]\((.*?)\)/)
1252
+ .replace('label', inline._label)
1253
+ .getRegex(),
1254
+ reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
1255
+ .replace('label', inline._label)
1256
+ .getRegex()
1026
1257
  };
1258
+ /**
1259
+ * GFM Inline Grammar
1260
+ */
1027
1261
  inline.gfm = {
1028
- ...inline.normal,
1029
- escape: edit(inline.escape).replace("])", "~|])").getRegex(),
1030
- _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
1031
- url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
1032
- _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
1033
- del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
1034
- text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1262
+ ...inline.normal,
1263
+ escape: edit(inline.escape).replace('])', '~|])').getRegex(),
1264
+ _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
1265
+ url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
1266
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
1267
+ del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
1268
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1035
1269
  };
1036
- inline.gfm.url = edit(inline.gfm.url, "i").replace("email", inline.gfm._extended_email).getRegex();
1270
+ inline.gfm.url = edit(inline.gfm.url, 'i')
1271
+ .replace('email', inline.gfm._extended_email)
1272
+ .getRegex();
1273
+ /**
1274
+ * GFM + Line Breaks Inline Grammar
1275
+ */
1037
1276
  inline.breaks = {
1038
- ...inline.gfm,
1039
- br: edit(inline.br).replace("{2,}", "*").getRegex(),
1040
- text: edit(inline.gfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
1277
+ ...inline.gfm,
1278
+ br: edit(inline.br).replace('{2,}', '*').getRegex(),
1279
+ text: edit(inline.gfm.text)
1280
+ .replace('\\b_', '\\b_| {2,}\\n')
1281
+ .replace(/\{2,\}/g, '*')
1282
+ .getRegex()
1041
1283
  };
1042
1284
 
1043
- // src/Lexer.ts
1285
+ /**
1286
+ * smartypants text replacement
1287
+ */
1044
1288
  function smartypants(text) {
1045
- return text.replace(/---/g, "\u2014").replace(/--/g, "\u2013").replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018").replace(/'/g, "\u2019").replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C").replace(/"/g, "\u201D").replace(/\.{3}/g, "\u2026");
1289
+ return text
1290
+ // em-dashes
1291
+ .replace(/---/g, '\u2014')
1292
+ // en-dashes
1293
+ .replace(/--/g, '\u2013')
1294
+ // opening singles
1295
+ .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
1296
+ // closing singles & apostrophes
1297
+ .replace(/'/g, '\u2019')
1298
+ // opening doubles
1299
+ .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
1300
+ // closing doubles
1301
+ .replace(/"/g, '\u201d')
1302
+ // ellipses
1303
+ .replace(/\.{3}/g, '\u2026');
1046
1304
  }
1305
+ /**
1306
+ * mangle email addresses
1307
+ */
1047
1308
  function mangle(text) {
1048
- let out = "", i, ch;
1049
- const l = text.length;
1050
- for (i = 0; i < l; i++) {
1051
- ch = text.charCodeAt(i);
1052
- if (Math.random() > 0.5) {
1053
- ch = "x" + ch.toString(16);
1054
- }
1055
- out += "&#" + ch + ";";
1056
- }
1057
- return out;
1058
- }
1059
- var _Lexer2 = class __Lexer {
1060
- constructor(options2) {
1061
- this.tokens = [];
1062
- this.tokens.links = /* @__PURE__ */ Object.create(null);
1063
- this.options = options2 || _defaults;
1064
- this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
1065
- this.tokenizer = this.options.tokenizer;
1066
- this.tokenizer.options = this.options;
1067
- this.tokenizer.lexer = this;
1068
- this.inlineQueue = [];
1069
- this.state = {
1070
- inLink: false,
1071
- inRawBlock: false,
1072
- top: true
1073
- };
1074
- const rules = {
1075
- block: block.normal,
1076
- inline: inline.normal
1077
- };
1078
- if (this.options.pedantic) {
1079
- rules.block = block.pedantic;
1080
- rules.inline = inline.pedantic;
1081
- } else if (this.options.gfm) {
1082
- rules.block = block.gfm;
1083
- if (this.options.breaks) {
1084
- rules.inline = inline.breaks;
1085
- } else {
1086
- rules.inline = inline.gfm;
1087
- }
1088
- }
1089
- this.tokenizer.rules = rules;
1090
- }
1091
- /**
1092
- * Expose Rules
1093
- */
1094
- static get rules() {
1095
- return {
1096
- block,
1097
- inline
1098
- };
1099
- }
1100
- /**
1101
- * Static Lex Method
1102
- */
1103
- static lex(src, options2) {
1104
- const lexer2 = new __Lexer(options2);
1105
- return lexer2.lex(src);
1106
- }
1107
- /**
1108
- * Static Lex Inline Method
1109
- */
1110
- static lexInline(src, options2) {
1111
- const lexer2 = new __Lexer(options2);
1112
- return lexer2.inlineTokens(src);
1113
- }
1114
- /**
1115
- * Preprocessing
1116
- */
1117
- lex(src) {
1118
- src = src.replace(/\r\n|\r/g, "\n");
1119
- this.blockTokens(src, this.tokens);
1120
- let next;
1121
- while (next = this.inlineQueue.shift()) {
1122
- this.inlineTokens(next.src, next.tokens);
1123
- }
1124
- return this.tokens;
1125
- }
1126
- blockTokens(src, tokens = []) {
1127
- if (this.options.pedantic) {
1128
- src = src.replace(/\t/g, " ").replace(/^ +$/gm, "");
1129
- } else {
1130
- src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
1131
- return leading + " ".repeat(tabs.length);
1132
- });
1133
- }
1134
- let token, lastToken, cutSrc, lastParagraphClipped;
1135
- while (src) {
1136
- if (this.options.extensions && this.options.extensions.block && this.options.extensions.block.some((extTokenizer) => {
1137
- if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1138
- src = src.substring(token.raw.length);
1139
- tokens.push(token);
1140
- return true;
1141
- }
1142
- return false;
1143
- })) {
1144
- continue;
1145
- }
1146
- if (token = this.tokenizer.space(src)) {
1147
- src = src.substring(token.raw.length);
1148
- if (token.raw.length === 1 && tokens.length > 0) {
1149
- tokens[tokens.length - 1].raw += "\n";
1150
- } else {
1151
- tokens.push(token);
1152
- }
1153
- continue;
1154
- }
1155
- if (token = this.tokenizer.code(src)) {
1156
- src = src.substring(token.raw.length);
1157
- lastToken = tokens[tokens.length - 1];
1158
- if (lastToken && (lastToken.type === "paragraph" || lastToken.type === "text")) {
1159
- lastToken.raw += "\n" + token.raw;
1160
- lastToken.text += "\n" + token.text;
1161
- this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1162
- } else {
1163
- tokens.push(token);
1164
- }
1165
- continue;
1166
- }
1167
- if (token = this.tokenizer.fences(src)) {
1168
- src = src.substring(token.raw.length);
1169
- tokens.push(token);
1170
- continue;
1171
- }
1172
- if (token = this.tokenizer.heading(src)) {
1173
- src = src.substring(token.raw.length);
1174
- tokens.push(token);
1175
- continue;
1176
- }
1177
- if (token = this.tokenizer.hr(src)) {
1178
- src = src.substring(token.raw.length);
1179
- tokens.push(token);
1180
- continue;
1181
- }
1182
- if (token = this.tokenizer.blockquote(src)) {
1183
- src = src.substring(token.raw.length);
1184
- tokens.push(token);
1185
- continue;
1186
- }
1187
- if (token = this.tokenizer.list(src)) {
1188
- src = src.substring(token.raw.length);
1189
- tokens.push(token);
1190
- continue;
1191
- }
1192
- if (token = this.tokenizer.html(src)) {
1193
- src = src.substring(token.raw.length);
1194
- tokens.push(token);
1195
- continue;
1196
- }
1197
- if (token = this.tokenizer.def(src)) {
1198
- src = src.substring(token.raw.length);
1199
- lastToken = tokens[tokens.length - 1];
1200
- if (lastToken && (lastToken.type === "paragraph" || lastToken.type === "text")) {
1201
- lastToken.raw += "\n" + token.raw;
1202
- lastToken.text += "\n" + token.raw;
1203
- this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1204
- } else if (!this.tokens.links[token.tag]) {
1205
- this.tokens.links[token.tag] = {
1206
- href: token.href,
1207
- title: token.title
1208
- };
1209
- }
1210
- continue;
1211
- }
1212
- if (token = this.tokenizer.table(src)) {
1213
- src = src.substring(token.raw.length);
1214
- tokens.push(token);
1215
- continue;
1216
- }
1217
- if (token = this.tokenizer.lheading(src)) {
1218
- src = src.substring(token.raw.length);
1219
- tokens.push(token);
1220
- continue;
1221
- }
1222
- cutSrc = src;
1223
- if (this.options.extensions && this.options.extensions.startBlock) {
1224
- let startIndex = Infinity;
1225
- const tempSrc = src.slice(1);
1226
- let tempStart;
1227
- this.options.extensions.startBlock.forEach((getStartIndex) => {
1228
- tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1229
- if (typeof tempStart === "number" && tempStart >= 0) {
1230
- startIndex = Math.min(startIndex, tempStart);
1231
- }
1232
- });
1233
- if (startIndex < Infinity && startIndex >= 0) {
1234
- cutSrc = src.substring(0, startIndex + 1);
1235
- }
1236
- }
1237
- if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1238
- lastToken = tokens[tokens.length - 1];
1239
- if (lastParagraphClipped && lastToken.type === "paragraph") {
1240
- lastToken.raw += "\n" + token.raw;
1241
- lastToken.text += "\n" + token.text;
1242
- this.inlineQueue.pop();
1243
- this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1244
- } else {
1245
- tokens.push(token);
1246
- }
1247
- lastParagraphClipped = cutSrc.length !== src.length;
1248
- src = src.substring(token.raw.length);
1249
- continue;
1250
- }
1251
- if (token = this.tokenizer.text(src)) {
1252
- src = src.substring(token.raw.length);
1253
- lastToken = tokens[tokens.length - 1];
1254
- if (lastToken && lastToken.type === "text") {
1255
- lastToken.raw += "\n" + token.raw;
1256
- lastToken.text += "\n" + token.text;
1257
- this.inlineQueue.pop();
1258
- this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1259
- } else {
1260
- tokens.push(token);
1261
- }
1262
- continue;
1263
- }
1264
- if (src) {
1265
- const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
1266
- if (this.options.silent) {
1267
- console.error(errMsg);
1268
- break;
1269
- } else {
1270
- throw new Error(errMsg);
1271
- }
1272
- }
1273
- }
1274
- this.state.top = true;
1275
- return tokens;
1276
- }
1277
- inline(src, tokens = []) {
1278
- this.inlineQueue.push({ src, tokens });
1279
- return tokens;
1280
- }
1281
- /**
1282
- * Lexing/Compiling
1283
- */
1284
- inlineTokens(src, tokens = []) {
1285
- let token, lastToken, cutSrc;
1286
- let maskedSrc = src;
1287
- let match;
1288
- let keepPrevChar, prevChar;
1289
- if (this.tokens.links) {
1290
- const links = Object.keys(this.tokens.links);
1291
- if (links.length > 0) {
1292
- while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1293
- if (links.includes(match[0].slice(match[0].lastIndexOf("[") + 1, -1))) {
1294
- maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1295
- }
1296
- }
1297
- }
1298
- }
1299
- while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1300
- maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1301
- }
1302
- while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
1303
- maskedSrc = maskedSrc.slice(0, match.index) + "++" + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
1304
- }
1305
- while (src) {
1306
- if (!keepPrevChar) {
1307
- prevChar = "";
1308
- }
1309
- keepPrevChar = false;
1310
- if (this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some((extTokenizer) => {
1311
- if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1312
- src = src.substring(token.raw.length);
1313
- tokens.push(token);
1314
- return true;
1315
- }
1316
- return false;
1317
- })) {
1318
- continue;
1319
- }
1320
- if (token = this.tokenizer.escape(src)) {
1321
- src = src.substring(token.raw.length);
1322
- tokens.push(token);
1323
- continue;
1324
- }
1325
- if (token = this.tokenizer.tag(src)) {
1326
- src = src.substring(token.raw.length);
1327
- lastToken = tokens[tokens.length - 1];
1328
- if (lastToken && token.type === "text" && lastToken.type === "text") {
1329
- lastToken.raw += token.raw;
1330
- lastToken.text += token.text;
1331
- } else {
1332
- tokens.push(token);
1333
- }
1334
- continue;
1335
- }
1336
- if (token = this.tokenizer.link(src)) {
1337
- src = src.substring(token.raw.length);
1338
- tokens.push(token);
1339
- continue;
1340
- }
1341
- if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1342
- src = src.substring(token.raw.length);
1343
- lastToken = tokens[tokens.length - 1];
1344
- if (lastToken && token.type === "text" && lastToken.type === "text") {
1345
- lastToken.raw += token.raw;
1346
- lastToken.text += token.text;
1347
- } else {
1348
- tokens.push(token);
1349
- }
1350
- continue;
1351
- }
1352
- if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1353
- src = src.substring(token.raw.length);
1354
- tokens.push(token);
1355
- continue;
1356
- }
1357
- if (token = this.tokenizer.codespan(src)) {
1358
- src = src.substring(token.raw.length);
1359
- tokens.push(token);
1360
- continue;
1361
- }
1362
- if (token = this.tokenizer.br(src)) {
1363
- src = src.substring(token.raw.length);
1364
- tokens.push(token);
1365
- continue;
1366
- }
1367
- if (token = this.tokenizer.del(src)) {
1368
- src = src.substring(token.raw.length);
1369
- tokens.push(token);
1370
- continue;
1371
- }
1372
- if (token = this.tokenizer.autolink(src, mangle)) {
1373
- src = src.substring(token.raw.length);
1374
- tokens.push(token);
1375
- continue;
1376
- }
1377
- if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
1378
- src = src.substring(token.raw.length);
1379
- tokens.push(token);
1380
- continue;
1381
- }
1382
- cutSrc = src;
1383
- if (this.options.extensions && this.options.extensions.startInline) {
1384
- let startIndex = Infinity;
1385
- const tempSrc = src.slice(1);
1386
- let tempStart;
1387
- this.options.extensions.startInline.forEach((getStartIndex) => {
1388
- tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1389
- if (typeof tempStart === "number" && tempStart >= 0) {
1390
- startIndex = Math.min(startIndex, tempStart);
1391
- }
1392
- });
1393
- if (startIndex < Infinity && startIndex >= 0) {
1394
- cutSrc = src.substring(0, startIndex + 1);
1395
- }
1396
- }
1397
- if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
1398
- src = src.substring(token.raw.length);
1399
- if (token.raw.slice(-1) !== "_") {
1400
- prevChar = token.raw.slice(-1);
1401
- }
1402
- keepPrevChar = true;
1403
- lastToken = tokens[tokens.length - 1];
1404
- if (lastToken && lastToken.type === "text") {
1405
- lastToken.raw += token.raw;
1406
- lastToken.text += token.text;
1407
- } else {
1408
- tokens.push(token);
1409
- }
1410
- continue;
1411
- }
1412
- if (src) {
1413
- const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
1414
- if (this.options.silent) {
1415
- console.error(errMsg);
1416
- break;
1417
- } else {
1418
- throw new Error(errMsg);
1419
- }
1420
- }
1421
- }
1422
- return tokens;
1423
- }
1424
- };
1425
-
1426
- // src/Renderer.ts
1427
- var _Renderer = class {
1428
- constructor(options2) {
1429
- this.options = options2 || _defaults;
1430
- }
1431
- code(code, infostring, escaped) {
1432
- const lang = (infostring || "").match(/\S*/)[0];
1433
- if (this.options.highlight) {
1434
- const out = this.options.highlight(code, lang);
1435
- if (out != null && out !== code) {
1436
- escaped = true;
1437
- code = out;
1438
- }
1439
- }
1440
- code = code.replace(/\n$/, "") + "\n";
1441
- if (!lang) {
1442
- return "<pre><code>" + (escaped ? code : escape(code, true)) + "</code></pre>\n";
1443
- }
1444
- return '<pre><code class="' + this.options.langPrefix + escape(lang) + '">' + (escaped ? code : escape(code, true)) + "</code></pre>\n";
1445
- }
1446
- blockquote(quote) {
1447
- return `<blockquote>
1448
- ${quote}</blockquote>
1449
- `;
1450
- }
1451
- html(html, block2) {
1452
- return html;
1453
- }
1454
- heading(text, level, raw, slugger) {
1455
- if (this.options.headerIds) {
1456
- const id = this.options.headerPrefix + slugger.slug(raw);
1457
- return `<h${level} id="${id}">${text}</h${level}>
1458
- `;
1459
- }
1460
- return `<h${level}>${text}</h${level}>
1461
- `;
1462
- }
1463
- hr() {
1464
- return this.options.xhtml ? "<hr/>\n" : "<hr>\n";
1465
- }
1466
- list(body, ordered, start) {
1467
- const type = ordered ? "ol" : "ul", startatt = ordered && start !== 1 ? ' start="' + start + '"' : "";
1468
- return "<" + type + startatt + ">\n" + body + "</" + type + ">\n";
1469
- }
1470
- listitem(text, task, checked) {
1471
- return `<li>${text}</li>
1472
- `;
1473
- }
1474
- checkbox(checked) {
1475
- return "<input " + (checked ? 'checked="" ' : "") + 'disabled="" type="checkbox"' + (this.options.xhtml ? " /" : "") + "> ";
1476
- }
1477
- paragraph(text) {
1478
- return `<p>${text}</p>
1479
- `;
1480
- }
1481
- table(header, body) {
1482
- if (body)
1483
- body = `<tbody>${body}</tbody>`;
1484
- return "<table>\n<thead>\n" + header + "</thead>\n" + body + "</table>\n";
1485
- }
1486
- tablerow(content) {
1487
- return `<tr>
1488
- ${content}</tr>
1489
- `;
1490
- }
1491
- tablecell(content, flags) {
1492
- const type = flags.header ? "th" : "td";
1493
- const tag = flags.align ? `<${type} align="${flags.align}">` : `<${type}>`;
1494
- return tag + content + `</${type}>
1495
- `;
1496
- }
1497
- /**
1498
- * span level renderer
1499
- */
1500
- strong(text) {
1501
- return `<strong>${text}</strong>`;
1502
- }
1503
- em(text) {
1504
- return `<em>${text}</em>`;
1505
- }
1506
- codespan(text) {
1507
- return `<code>${text}</code>`;
1508
- }
1509
- br() {
1510
- return this.options.xhtml ? "<br/>" : "<br>";
1511
- }
1512
- del(text) {
1513
- return `<del>${text}</del>`;
1514
- }
1515
- link(href, title, text) {
1516
- href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1517
- if (href === null) {
1518
- return text;
1519
- }
1520
- let out = '<a href="' + href + '"';
1521
- if (title) {
1522
- out += ' title="' + title + '"';
1523
- }
1524
- out += ">" + text + "</a>";
1309
+ let out = '', i, ch;
1310
+ const l = text.length;
1311
+ for (i = 0; i < l; i++) {
1312
+ ch = text.charCodeAt(i);
1313
+ if (Math.random() > 0.5) {
1314
+ ch = 'x' + ch.toString(16);
1315
+ }
1316
+ out += '&#' + ch + ';';
1317
+ }
1525
1318
  return out;
1526
- }
1527
- image(href, title, text) {
1528
- href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1529
- if (href === null) {
1530
- return text;
1319
+ }
1320
+ /**
1321
+ * Block Lexer
1322
+ */
1323
+ class _Lexer {
1324
+ tokens;
1325
+ options;
1326
+ state;
1327
+ tokenizer;
1328
+ inlineQueue;
1329
+ constructor(options) {
1330
+ // TokenList cannot be created in one go
1331
+ // @ts-expect-error
1332
+ this.tokens = [];
1333
+ this.tokens.links = Object.create(null);
1334
+ this.options = options || _defaults;
1335
+ this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
1336
+ this.tokenizer = this.options.tokenizer;
1337
+ this.tokenizer.options = this.options;
1338
+ this.tokenizer.lexer = this;
1339
+ this.inlineQueue = [];
1340
+ this.state = {
1341
+ inLink: false,
1342
+ inRawBlock: false,
1343
+ top: true
1344
+ };
1345
+ const rules = {
1346
+ block: block.normal,
1347
+ inline: inline.normal
1348
+ };
1349
+ if (this.options.pedantic) {
1350
+ rules.block = block.pedantic;
1351
+ rules.inline = inline.pedantic;
1352
+ }
1353
+ else if (this.options.gfm) {
1354
+ rules.block = block.gfm;
1355
+ if (this.options.breaks) {
1356
+ rules.inline = inline.breaks;
1357
+ }
1358
+ else {
1359
+ rules.inline = inline.gfm;
1360
+ }
1361
+ }
1362
+ this.tokenizer.rules = rules;
1531
1363
  }
1532
- let out = `<img src="${href}" alt="${text}"`;
1533
- if (title) {
1534
- out += ` title="${title}"`;
1364
+ /**
1365
+ * Expose Rules
1366
+ */
1367
+ static get rules() {
1368
+ return {
1369
+ block,
1370
+ inline
1371
+ };
1535
1372
  }
1536
- out += this.options.xhtml ? "/>" : ">";
1537
- return out;
1538
- }
1539
- text(text) {
1540
- return text;
1541
- }
1542
- };
1543
-
1544
- // src/TextRenderer.ts
1545
- var _TextRenderer = class {
1546
- // no need for block level renderers
1547
- strong(text) {
1548
- return text;
1549
- }
1550
- em(text) {
1551
- return text;
1552
- }
1553
- codespan(text) {
1554
- return text;
1555
- }
1556
- del(text) {
1557
- return text;
1558
- }
1559
- html(text) {
1560
- return text;
1561
- }
1562
- text(text) {
1563
- return text;
1564
- }
1565
- link(href, title, text) {
1566
- return "" + text;
1567
- }
1568
- image(href, title, text) {
1569
- return "" + text;
1570
- }
1571
- br() {
1572
- return "";
1573
- }
1574
- };
1373
+ /**
1374
+ * Static Lex Method
1375
+ */
1376
+ static lex(src, options) {
1377
+ const lexer = new _Lexer(options);
1378
+ return lexer.lex(src);
1379
+ }
1380
+ /**
1381
+ * Static Lex Inline Method
1382
+ */
1383
+ static lexInline(src, options) {
1384
+ const lexer = new _Lexer(options);
1385
+ return lexer.inlineTokens(src);
1386
+ }
1387
+ /**
1388
+ * Preprocessing
1389
+ */
1390
+ lex(src) {
1391
+ src = src
1392
+ .replace(/\r\n|\r/g, '\n');
1393
+ this.blockTokens(src, this.tokens);
1394
+ let next;
1395
+ while (next = this.inlineQueue.shift()) {
1396
+ this.inlineTokens(next.src, next.tokens);
1397
+ }
1398
+ return this.tokens;
1399
+ }
1400
+ blockTokens(src, tokens = []) {
1401
+ if (this.options.pedantic) {
1402
+ src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
1403
+ }
1404
+ else {
1405
+ src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
1406
+ return leading + ' '.repeat(tabs.length);
1407
+ });
1408
+ }
1409
+ let token;
1410
+ let lastToken;
1411
+ let cutSrc;
1412
+ let lastParagraphClipped;
1413
+ while (src) {
1414
+ if (this.options.extensions
1415
+ && this.options.extensions.block
1416
+ && this.options.extensions.block.some((extTokenizer) => {
1417
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1418
+ src = src.substring(token.raw.length);
1419
+ tokens.push(token);
1420
+ return true;
1421
+ }
1422
+ return false;
1423
+ })) {
1424
+ continue;
1425
+ }
1426
+ // newline
1427
+ if (token = this.tokenizer.space(src)) {
1428
+ src = src.substring(token.raw.length);
1429
+ if (token.raw.length === 1 && tokens.length > 0) {
1430
+ // if there's a single \n as a spacer, it's terminating the last line,
1431
+ // so move it there so that we don't get unecessary paragraph tags
1432
+ tokens[tokens.length - 1].raw += '\n';
1433
+ }
1434
+ else {
1435
+ tokens.push(token);
1436
+ }
1437
+ continue;
1438
+ }
1439
+ // code
1440
+ if (token = this.tokenizer.code(src)) {
1441
+ src = src.substring(token.raw.length);
1442
+ lastToken = tokens[tokens.length - 1];
1443
+ // An indented code block cannot interrupt a paragraph.
1444
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1445
+ lastToken.raw += '\n' + token.raw;
1446
+ lastToken.text += '\n' + token.text;
1447
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1448
+ }
1449
+ else {
1450
+ tokens.push(token);
1451
+ }
1452
+ continue;
1453
+ }
1454
+ // fences
1455
+ if (token = this.tokenizer.fences(src)) {
1456
+ src = src.substring(token.raw.length);
1457
+ tokens.push(token);
1458
+ continue;
1459
+ }
1460
+ // heading
1461
+ if (token = this.tokenizer.heading(src)) {
1462
+ src = src.substring(token.raw.length);
1463
+ tokens.push(token);
1464
+ continue;
1465
+ }
1466
+ // hr
1467
+ if (token = this.tokenizer.hr(src)) {
1468
+ src = src.substring(token.raw.length);
1469
+ tokens.push(token);
1470
+ continue;
1471
+ }
1472
+ // blockquote
1473
+ if (token = this.tokenizer.blockquote(src)) {
1474
+ src = src.substring(token.raw.length);
1475
+ tokens.push(token);
1476
+ continue;
1477
+ }
1478
+ // list
1479
+ if (token = this.tokenizer.list(src)) {
1480
+ src = src.substring(token.raw.length);
1481
+ tokens.push(token);
1482
+ continue;
1483
+ }
1484
+ // html
1485
+ if (token = this.tokenizer.html(src)) {
1486
+ src = src.substring(token.raw.length);
1487
+ tokens.push(token);
1488
+ continue;
1489
+ }
1490
+ // def
1491
+ if (token = this.tokenizer.def(src)) {
1492
+ src = src.substring(token.raw.length);
1493
+ lastToken = tokens[tokens.length - 1];
1494
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1495
+ lastToken.raw += '\n' + token.raw;
1496
+ lastToken.text += '\n' + token.raw;
1497
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1498
+ }
1499
+ else if (!this.tokens.links[token.tag]) {
1500
+ this.tokens.links[token.tag] = {
1501
+ href: token.href,
1502
+ title: token.title
1503
+ };
1504
+ }
1505
+ continue;
1506
+ }
1507
+ // table (gfm)
1508
+ if (token = this.tokenizer.table(src)) {
1509
+ src = src.substring(token.raw.length);
1510
+ tokens.push(token);
1511
+ continue;
1512
+ }
1513
+ // lheading
1514
+ if (token = this.tokenizer.lheading(src)) {
1515
+ src = src.substring(token.raw.length);
1516
+ tokens.push(token);
1517
+ continue;
1518
+ }
1519
+ // top-level paragraph
1520
+ // prevent paragraph consuming extensions by clipping 'src' to extension start
1521
+ cutSrc = src;
1522
+ if (this.options.extensions && this.options.extensions.startBlock) {
1523
+ let startIndex = Infinity;
1524
+ const tempSrc = src.slice(1);
1525
+ let tempStart;
1526
+ this.options.extensions.startBlock.forEach((getStartIndex) => {
1527
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1528
+ if (typeof tempStart === 'number' && tempStart >= 0) {
1529
+ startIndex = Math.min(startIndex, tempStart);
1530
+ }
1531
+ });
1532
+ if (startIndex < Infinity && startIndex >= 0) {
1533
+ cutSrc = src.substring(0, startIndex + 1);
1534
+ }
1535
+ }
1536
+ if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1537
+ lastToken = tokens[tokens.length - 1];
1538
+ if (lastParagraphClipped && lastToken.type === 'paragraph') {
1539
+ lastToken.raw += '\n' + token.raw;
1540
+ lastToken.text += '\n' + token.text;
1541
+ this.inlineQueue.pop();
1542
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1543
+ }
1544
+ else {
1545
+ tokens.push(token);
1546
+ }
1547
+ lastParagraphClipped = (cutSrc.length !== src.length);
1548
+ src = src.substring(token.raw.length);
1549
+ continue;
1550
+ }
1551
+ // text
1552
+ if (token = this.tokenizer.text(src)) {
1553
+ src = src.substring(token.raw.length);
1554
+ lastToken = tokens[tokens.length - 1];
1555
+ if (lastToken && lastToken.type === 'text') {
1556
+ lastToken.raw += '\n' + token.raw;
1557
+ lastToken.text += '\n' + token.text;
1558
+ this.inlineQueue.pop();
1559
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1560
+ }
1561
+ else {
1562
+ tokens.push(token);
1563
+ }
1564
+ continue;
1565
+ }
1566
+ if (src) {
1567
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1568
+ if (this.options.silent) {
1569
+ console.error(errMsg);
1570
+ break;
1571
+ }
1572
+ else {
1573
+ throw new Error(errMsg);
1574
+ }
1575
+ }
1576
+ }
1577
+ this.state.top = true;
1578
+ return tokens;
1579
+ }
1580
+ inline(src, tokens = []) {
1581
+ this.inlineQueue.push({ src, tokens });
1582
+ return tokens;
1583
+ }
1584
+ /**
1585
+ * Lexing/Compiling
1586
+ */
1587
+ inlineTokens(src, tokens = []) {
1588
+ let token, lastToken, cutSrc;
1589
+ // String with links masked to avoid interference with em and strong
1590
+ let maskedSrc = src;
1591
+ let match;
1592
+ let keepPrevChar, prevChar;
1593
+ // Mask out reflinks
1594
+ if (this.tokens.links) {
1595
+ const links = Object.keys(this.tokens.links);
1596
+ if (links.length > 0) {
1597
+ while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1598
+ if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
1599
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1600
+ }
1601
+ }
1602
+ }
1603
+ }
1604
+ // Mask out other blocks
1605
+ while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1606
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1607
+ }
1608
+ // Mask out escaped characters
1609
+ while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
1610
+ maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
1611
+ }
1612
+ while (src) {
1613
+ if (!keepPrevChar) {
1614
+ prevChar = '';
1615
+ }
1616
+ keepPrevChar = false;
1617
+ // extensions
1618
+ if (this.options.extensions
1619
+ && this.options.extensions.inline
1620
+ && this.options.extensions.inline.some((extTokenizer) => {
1621
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1622
+ src = src.substring(token.raw.length);
1623
+ tokens.push(token);
1624
+ return true;
1625
+ }
1626
+ return false;
1627
+ })) {
1628
+ continue;
1629
+ }
1630
+ // escape
1631
+ if (token = this.tokenizer.escape(src)) {
1632
+ src = src.substring(token.raw.length);
1633
+ tokens.push(token);
1634
+ continue;
1635
+ }
1636
+ // tag
1637
+ if (token = this.tokenizer.tag(src)) {
1638
+ src = src.substring(token.raw.length);
1639
+ lastToken = tokens[tokens.length - 1];
1640
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1641
+ lastToken.raw += token.raw;
1642
+ lastToken.text += token.text;
1643
+ }
1644
+ else {
1645
+ tokens.push(token);
1646
+ }
1647
+ continue;
1648
+ }
1649
+ // link
1650
+ if (token = this.tokenizer.link(src)) {
1651
+ src = src.substring(token.raw.length);
1652
+ tokens.push(token);
1653
+ continue;
1654
+ }
1655
+ // reflink, nolink
1656
+ if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1657
+ src = src.substring(token.raw.length);
1658
+ lastToken = tokens[tokens.length - 1];
1659
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1660
+ lastToken.raw += token.raw;
1661
+ lastToken.text += token.text;
1662
+ }
1663
+ else {
1664
+ tokens.push(token);
1665
+ }
1666
+ continue;
1667
+ }
1668
+ // em & strong
1669
+ if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1670
+ src = src.substring(token.raw.length);
1671
+ tokens.push(token);
1672
+ continue;
1673
+ }
1674
+ // code
1675
+ if (token = this.tokenizer.codespan(src)) {
1676
+ src = src.substring(token.raw.length);
1677
+ tokens.push(token);
1678
+ continue;
1679
+ }
1680
+ // br
1681
+ if (token = this.tokenizer.br(src)) {
1682
+ src = src.substring(token.raw.length);
1683
+ tokens.push(token);
1684
+ continue;
1685
+ }
1686
+ // del (gfm)
1687
+ if (token = this.tokenizer.del(src)) {
1688
+ src = src.substring(token.raw.length);
1689
+ tokens.push(token);
1690
+ continue;
1691
+ }
1692
+ // autolink
1693
+ if (token = this.tokenizer.autolink(src, mangle)) {
1694
+ src = src.substring(token.raw.length);
1695
+ tokens.push(token);
1696
+ continue;
1697
+ }
1698
+ // url (gfm)
1699
+ if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
1700
+ src = src.substring(token.raw.length);
1701
+ tokens.push(token);
1702
+ continue;
1703
+ }
1704
+ // text
1705
+ // prevent inlineText consuming extensions by clipping 'src' to extension start
1706
+ cutSrc = src;
1707
+ if (this.options.extensions && this.options.extensions.startInline) {
1708
+ let startIndex = Infinity;
1709
+ const tempSrc = src.slice(1);
1710
+ let tempStart;
1711
+ this.options.extensions.startInline.forEach((getStartIndex) => {
1712
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1713
+ if (typeof tempStart === 'number' && tempStart >= 0) {
1714
+ startIndex = Math.min(startIndex, tempStart);
1715
+ }
1716
+ });
1717
+ if (startIndex < Infinity && startIndex >= 0) {
1718
+ cutSrc = src.substring(0, startIndex + 1);
1719
+ }
1720
+ }
1721
+ if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
1722
+ src = src.substring(token.raw.length);
1723
+ if (token.raw.slice(-1) !== '_') { // Track prevChar before string of ____ started
1724
+ prevChar = token.raw.slice(-1);
1725
+ }
1726
+ keepPrevChar = true;
1727
+ lastToken = tokens[tokens.length - 1];
1728
+ if (lastToken && lastToken.type === 'text') {
1729
+ lastToken.raw += token.raw;
1730
+ lastToken.text += token.text;
1731
+ }
1732
+ else {
1733
+ tokens.push(token);
1734
+ }
1735
+ continue;
1736
+ }
1737
+ if (src) {
1738
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1739
+ if (this.options.silent) {
1740
+ console.error(errMsg);
1741
+ break;
1742
+ }
1743
+ else {
1744
+ throw new Error(errMsg);
1745
+ }
1746
+ }
1747
+ }
1748
+ return tokens;
1749
+ }
1750
+ }
1575
1751
 
1576
- // src/Slugger.ts
1577
- var _Slugger = class {
1578
- constructor() {
1579
- this.seen = {};
1580
- }
1581
- serialize(value) {
1582
- return value.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig, "").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, "").replace(/\s/g, "-");
1583
- }
1584
- /**
1585
- * Finds the next safe (unique) slug to use
1586
- */
1587
- getNextSafeSlug(originalSlug, isDryRun) {
1588
- let slug = originalSlug;
1589
- let occurenceAccumulator = 0;
1590
- if (this.seen.hasOwnProperty(slug)) {
1591
- occurenceAccumulator = this.seen[originalSlug];
1592
- do {
1593
- occurenceAccumulator++;
1594
- slug = originalSlug + "-" + occurenceAccumulator;
1595
- } while (this.seen.hasOwnProperty(slug));
1596
- }
1597
- if (!isDryRun) {
1598
- this.seen[originalSlug] = occurenceAccumulator;
1599
- this.seen[slug] = 0;
1600
- }
1601
- return slug;
1602
- }
1603
- /**
1604
- * Convert string to unique id
1605
- */
1606
- slug(value, options2 = {}) {
1607
- const slug = this.serialize(value);
1608
- return this.getNextSafeSlug(slug, options2.dryrun);
1609
- }
1610
- };
1752
+ /**
1753
+ * Renderer
1754
+ */
1755
+ class _Renderer {
1756
+ options;
1757
+ constructor(options) {
1758
+ this.options = options || _defaults;
1759
+ }
1760
+ code(code, infostring, escaped) {
1761
+ const lang = (infostring || '').match(/\S*/)[0];
1762
+ if (this.options.highlight) {
1763
+ const out = this.options.highlight(code, lang);
1764
+ if (out != null && out !== code) {
1765
+ escaped = true;
1766
+ code = out;
1767
+ }
1768
+ }
1769
+ code = code.replace(/\n$/, '') + '\n';
1770
+ if (!lang) {
1771
+ return '<pre><code>'
1772
+ + (escaped ? code : escape(code, true))
1773
+ + '</code></pre>\n';
1774
+ }
1775
+ return '<pre><code class="'
1776
+ + this.options.langPrefix
1777
+ + escape(lang)
1778
+ + '">'
1779
+ + (escaped ? code : escape(code, true))
1780
+ + '</code></pre>\n';
1781
+ }
1782
+ blockquote(quote) {
1783
+ return `<blockquote>\n${quote}</blockquote>\n`;
1784
+ }
1785
+ html(html, block) {
1786
+ return html;
1787
+ }
1788
+ heading(text, level, raw, slugger) {
1789
+ if (this.options.headerIds) {
1790
+ const id = this.options.headerPrefix + slugger.slug(raw);
1791
+ return `<h${level} id="${id}">${text}</h${level}>\n`;
1792
+ }
1793
+ // ignore IDs
1794
+ return `<h${level}>${text}</h${level}>\n`;
1795
+ }
1796
+ hr() {
1797
+ return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
1798
+ }
1799
+ list(body, ordered, start) {
1800
+ const type = ordered ? 'ol' : 'ul', startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
1801
+ return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1802
+ }
1803
+ listitem(text, task, checked) {
1804
+ return `<li>${text}</li>\n`;
1805
+ }
1806
+ checkbox(checked) {
1807
+ return '<input '
1808
+ + (checked ? 'checked="" ' : '')
1809
+ + 'disabled="" type="checkbox"'
1810
+ + (this.options.xhtml ? ' /' : '')
1811
+ + '> ';
1812
+ }
1813
+ paragraph(text) {
1814
+ return `<p>${text}</p>\n`;
1815
+ }
1816
+ table(header, body) {
1817
+ if (body)
1818
+ body = `<tbody>${body}</tbody>`;
1819
+ return '<table>\n'
1820
+ + '<thead>\n'
1821
+ + header
1822
+ + '</thead>\n'
1823
+ + body
1824
+ + '</table>\n';
1825
+ }
1826
+ tablerow(content) {
1827
+ return `<tr>\n${content}</tr>\n`;
1828
+ }
1829
+ tablecell(content, flags) {
1830
+ const type = flags.header ? 'th' : 'td';
1831
+ const tag = flags.align
1832
+ ? `<${type} align="${flags.align}">`
1833
+ : `<${type}>`;
1834
+ return tag + content + `</${type}>\n`;
1835
+ }
1836
+ /**
1837
+ * span level renderer
1838
+ */
1839
+ strong(text) {
1840
+ return `<strong>${text}</strong>`;
1841
+ }
1842
+ em(text) {
1843
+ return `<em>${text}</em>`;
1844
+ }
1845
+ codespan(text) {
1846
+ return `<code>${text}</code>`;
1847
+ }
1848
+ br() {
1849
+ return this.options.xhtml ? '<br/>' : '<br>';
1850
+ }
1851
+ del(text) {
1852
+ return `<del>${text}</del>`;
1853
+ }
1854
+ link(href, title, text) {
1855
+ href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1856
+ if (href === null) {
1857
+ return text;
1858
+ }
1859
+ let out = '<a href="' + href + '"';
1860
+ if (title) {
1861
+ out += ' title="' + title + '"';
1862
+ }
1863
+ out += '>' + text + '</a>';
1864
+ return out;
1865
+ }
1866
+ image(href, title, text) {
1867
+ href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1868
+ if (href === null) {
1869
+ return text;
1870
+ }
1871
+ let out = `<img src="${href}" alt="${text}"`;
1872
+ if (title) {
1873
+ out += ` title="${title}"`;
1874
+ }
1875
+ out += this.options.xhtml ? '/>' : '>';
1876
+ return out;
1877
+ }
1878
+ text(text) {
1879
+ return text;
1880
+ }
1881
+ }
1611
1882
 
1612
- // src/Parser.ts
1613
- var _Parser = class __Parser {
1614
- constructor(options2) {
1615
- this.options = options2 || _defaults;
1616
- this.options.renderer = this.options.renderer || new _Renderer();
1617
- this.renderer = this.options.renderer;
1618
- this.renderer.options = this.options;
1619
- this.textRenderer = new _TextRenderer();
1620
- this.slugger = new _Slugger();
1621
- }
1622
- /**
1623
- * Static Parse Method
1624
- */
1625
- static parse(tokens, options2) {
1626
- const parser2 = new __Parser(options2);
1627
- return parser2.parse(tokens);
1628
- }
1629
- /**
1630
- * Static Parse Inline Method
1631
- */
1632
- static parseInline(tokens, options2) {
1633
- const parser2 = new __Parser(options2);
1634
- return parser2.parseInline(tokens);
1635
- }
1636
- /**
1637
- * Parse Loop
1638
- */
1639
- parse(tokens, top = true) {
1640
- let out = "", i, j, k, l2, l3, row, cell, header, body, token, ordered, start, loose, itemBody, item, checked, task, checkbox, ret;
1641
- const l = tokens.length;
1642
- for (i = 0; i < l; i++) {
1643
- token = tokens[i];
1644
- if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
1645
- ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
1646
- if (ret !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(token.type)) {
1647
- out += ret || "";
1648
- continue;
1649
- }
1650
- }
1651
- switch (token.type) {
1652
- case "space": {
1653
- continue;
1654
- }
1655
- case "hr": {
1656
- out += this.renderer.hr();
1657
- continue;
1658
- }
1659
- case "heading": {
1660
- out += this.renderer.heading(
1661
- this.parseInline(token.tokens),
1662
- token.depth,
1663
- unescape(this.parseInline(token.tokens, this.textRenderer)),
1664
- this.slugger
1665
- );
1666
- continue;
1667
- }
1668
- case "code": {
1669
- out += this.renderer.code(
1670
- token.text,
1671
- token.lang,
1672
- !!token.escaped
1673
- );
1674
- continue;
1675
- }
1676
- case "table": {
1677
- header = "";
1678
- cell = "";
1679
- l2 = token.header.length;
1680
- for (j = 0; j < l2; j++) {
1681
- cell += this.renderer.tablecell(
1682
- this.parseInline(token.header[j].tokens),
1683
- { header: true, align: token.align[j] }
1684
- );
1685
- }
1686
- header += this.renderer.tablerow(cell);
1687
- body = "";
1688
- l2 = token.rows.length;
1689
- for (j = 0; j < l2; j++) {
1690
- row = token.rows[j];
1691
- cell = "";
1692
- l3 = row.length;
1693
- for (k = 0; k < l3; k++) {
1694
- cell += this.renderer.tablecell(
1695
- this.parseInline(row[k].tokens),
1696
- { header: false, align: token.align[k] }
1697
- );
1698
- }
1699
- body += this.renderer.tablerow(cell);
1700
- }
1701
- out += this.renderer.table(header, body);
1702
- continue;
1703
- }
1704
- case "blockquote": {
1705
- body = this.parse(token.tokens);
1706
- out += this.renderer.blockquote(body);
1707
- continue;
1708
- }
1709
- case "list": {
1710
- ordered = token.ordered;
1711
- start = token.start;
1712
- loose = token.loose;
1713
- l2 = token.items.length;
1714
- body = "";
1715
- for (j = 0; j < l2; j++) {
1716
- item = token.items[j];
1717
- checked = item.checked;
1718
- task = item.task;
1719
- itemBody = "";
1720
- if (item.task) {
1721
- checkbox = this.renderer.checkbox(!!checked);
1722
- if (loose) {
1723
- if (item.tokens.length > 0 && item.tokens[0].type === "paragraph") {
1724
- item.tokens[0].text = checkbox + " " + item.tokens[0].text;
1725
- if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === "text") {
1726
- item.tokens[0].tokens[0].text = checkbox + " " + item.tokens[0].tokens[0].text;
1727
- }
1728
- } else {
1729
- item.tokens.unshift({
1730
- type: "text",
1731
- text: checkbox
1732
- });
1733
- }
1734
- } else {
1735
- itemBody += checkbox;
1736
- }
1737
- }
1738
- itemBody += this.parse(item.tokens, loose);
1739
- body += this.renderer.listitem(itemBody, task, !!checked);
1740
- }
1741
- out += this.renderer.list(body, ordered, start);
1742
- continue;
1743
- }
1744
- case "html": {
1745
- out += this.renderer.html(token.text, token.block);
1746
- continue;
1747
- }
1748
- case "paragraph": {
1749
- out += this.renderer.paragraph(this.parseInline(token.tokens));
1750
- continue;
1751
- }
1752
- case "text": {
1753
- body = token.tokens ? this.parseInline(token.tokens) : token.text;
1754
- while (i + 1 < l && tokens[i + 1].type === "text") {
1755
- token = tokens[++i];
1756
- body += "\n" + (token.tokens ? this.parseInline(token.tokens) : token.text);
1757
- }
1758
- out += top ? this.renderer.paragraph(body) : body;
1759
- continue;
1760
- }
1761
- default: {
1762
- const errMsg = 'Token with "' + token.type + '" type was not found.';
1763
- if (this.options.silent) {
1764
- console.error(errMsg);
1765
- return "";
1766
- } else {
1767
- throw new Error(errMsg);
1768
- }
1769
- }
1770
- }
1883
+ /**
1884
+ * TextRenderer
1885
+ * returns only the textual part of the token
1886
+ */
1887
+ class _TextRenderer {
1888
+ // no need for block level renderers
1889
+ strong(text) {
1890
+ return text;
1771
1891
  }
1772
- return out;
1773
- }
1774
- /**
1775
- * Parse Inline Tokens
1776
- */
1777
- parseInline(tokens, renderer) {
1778
- renderer = renderer || this.renderer;
1779
- let out = "", i, token, ret;
1780
- const l = tokens.length;
1781
- for (i = 0; i < l; i++) {
1782
- token = tokens[i];
1783
- if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
1784
- ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
1785
- if (ret !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(token.type)) {
1786
- out += ret || "";
1787
- continue;
1788
- }
1789
- }
1790
- switch (token.type) {
1791
- case "escape": {
1792
- out += renderer.text(token.text);
1793
- break;
1794
- }
1795
- case "html": {
1796
- out += renderer.html(token.text);
1797
- break;
1798
- }
1799
- case "link": {
1800
- out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
1801
- break;
1802
- }
1803
- case "image": {
1804
- out += renderer.image(token.href, token.title, token.text);
1805
- break;
1806
- }
1807
- case "strong": {
1808
- out += renderer.strong(this.parseInline(token.tokens, renderer));
1809
- break;
1810
- }
1811
- case "em": {
1812
- out += renderer.em(this.parseInline(token.tokens, renderer));
1813
- break;
1814
- }
1815
- case "codespan": {
1816
- out += renderer.codespan(token.text);
1817
- break;
1818
- }
1819
- case "br": {
1820
- out += renderer.br();
1821
- break;
1822
- }
1823
- case "del": {
1824
- out += renderer.del(this.parseInline(token.tokens, renderer));
1825
- break;
1826
- }
1827
- case "text": {
1828
- out += renderer.text(token.text);
1829
- break;
1830
- }
1831
- default: {
1832
- const errMsg = 'Token with "' + token.type + '" type was not found.';
1833
- if (this.options.silent) {
1834
- console.error(errMsg);
1835
- return "";
1836
- } else {
1837
- throw new Error(errMsg);
1838
- }
1839
- }
1840
- }
1892
+ em(text) {
1893
+ return text;
1841
1894
  }
1842
- return out;
1843
- }
1844
- };
1895
+ codespan(text) {
1896
+ return text;
1897
+ }
1898
+ del(text) {
1899
+ return text;
1900
+ }
1901
+ html(text) {
1902
+ return text;
1903
+ }
1904
+ text(text) {
1905
+ return text;
1906
+ }
1907
+ link(href, title, text) {
1908
+ return '' + text;
1909
+ }
1910
+ image(href, title, text) {
1911
+ return '' + text;
1912
+ }
1913
+ br() {
1914
+ return '';
1915
+ }
1916
+ }
1845
1917
 
1846
- // src/Hooks.ts
1847
- var _Hooks = class {
1848
- constructor(options2) {
1849
- this.options = options2 || _defaults;
1850
- }
1851
- /**
1852
- * Process markdown before marked
1853
- */
1854
- preprocess(markdown) {
1855
- return markdown;
1856
- }
1857
- /**
1858
- * Process HTML after marked is finished
1859
- */
1860
- postprocess(html) {
1861
- return html;
1862
- }
1863
- };
1864
- _Hooks.passThroughHooks = /* @__PURE__ */ new Set([
1865
- "preprocess",
1866
- "postprocess"
1867
- ]);
1918
+ /**
1919
+ * Slugger generates header id
1920
+ */
1921
+ class _Slugger {
1922
+ seen;
1923
+ constructor() {
1924
+ this.seen = {};
1925
+ }
1926
+ serialize(value) {
1927
+ return value
1928
+ .toLowerCase()
1929
+ .trim()
1930
+ // remove html tags
1931
+ .replace(/<[!\/a-z].*?>/ig, '')
1932
+ // remove unwanted chars
1933
+ .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
1934
+ .replace(/\s/g, '-');
1935
+ }
1936
+ /**
1937
+ * Finds the next safe (unique) slug to use
1938
+ */
1939
+ getNextSafeSlug(originalSlug, isDryRun) {
1940
+ let slug = originalSlug;
1941
+ let occurenceAccumulator = 0;
1942
+ if (this.seen.hasOwnProperty(slug)) {
1943
+ occurenceAccumulator = this.seen[originalSlug];
1944
+ do {
1945
+ occurenceAccumulator++;
1946
+ slug = originalSlug + '-' + occurenceAccumulator;
1947
+ } while (this.seen.hasOwnProperty(slug));
1948
+ }
1949
+ if (!isDryRun) {
1950
+ this.seen[originalSlug] = occurenceAccumulator;
1951
+ this.seen[slug] = 0;
1952
+ }
1953
+ return slug;
1954
+ }
1955
+ /**
1956
+ * Convert string to unique id
1957
+ */
1958
+ slug(value, options = {}) {
1959
+ const slug = this.serialize(value);
1960
+ return this.getNextSafeSlug(slug, options.dryrun);
1961
+ }
1962
+ }
1868
1963
 
1869
- // src/Instance.ts
1870
- var _parseMarkdown, parseMarkdown_fn, _onError, onError_fn;
1871
- var Marked = class {
1872
- constructor(...args) {
1873
- __privateAdd(this, _parseMarkdown);
1874
- __privateAdd(this, _onError);
1875
- this.defaults = _getDefaults();
1876
- this.options = this.setOptions;
1877
- this.parse = __privateMethod(this, _parseMarkdown, parseMarkdown_fn).call(this, _Lexer2.lex, _Parser.parse);
1878
- this.parseInline = __privateMethod(this, _parseMarkdown, parseMarkdown_fn).call(this, _Lexer2.lexInline, _Parser.parseInline);
1879
- this.Parser = _Parser;
1880
- this.parser = _Parser.parse;
1881
- this.Renderer = _Renderer;
1882
- this.TextRenderer = _TextRenderer;
1883
- this.Lexer = _Lexer2;
1884
- this.lexer = _Lexer2.lex;
1885
- this.Tokenizer = _Tokenizer;
1886
- this.Slugger = _Slugger;
1887
- this.Hooks = _Hooks;
1888
- this.use(...args);
1889
- }
1890
- /**
1891
- * Run callback for every token
1892
- */
1893
- walkTokens(tokens, callback) {
1894
- let values = [];
1895
- for (const token of tokens) {
1896
- values = values.concat(callback.call(this, token));
1897
- switch (token.type) {
1898
- case "table": {
1899
- for (const cell of token.header) {
1900
- values = values.concat(this.walkTokens(cell.tokens, callback));
1901
- }
1902
- for (const row of token.rows) {
1903
- for (const cell of row) {
1904
- values = values.concat(this.walkTokens(cell.tokens, callback));
1905
- }
1906
- }
1907
- break;
1908
- }
1909
- case "list": {
1910
- values = values.concat(this.walkTokens(token.items, callback));
1911
- break;
1912
- }
1913
- default: {
1914
- if (this.defaults.extensions && this.defaults.extensions.childTokens && this.defaults.extensions.childTokens[token.type]) {
1915
- this.defaults.extensions.childTokens[token.type].forEach((childTokens) => {
1916
- values = values.concat(this.walkTokens(token[childTokens], callback));
1917
- });
1918
- } else if (token.tokens) {
1919
- values = values.concat(this.walkTokens(token.tokens, callback));
1920
- }
1921
- }
1922
- }
1923
- }
1924
- return values;
1925
- }
1926
- use(...args) {
1927
- const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
1928
- args.forEach((pack) => {
1929
- const opts = { ...pack };
1930
- opts.async = this.defaults.async || opts.async || false;
1931
- if (pack.extensions) {
1932
- pack.extensions.forEach((ext) => {
1933
- if (!ext.name) {
1934
- throw new Error("extension name required");
1935
- }
1936
- if ("renderer" in ext) {
1937
- const prevRenderer = extensions.renderers[ext.name];
1938
- if (prevRenderer) {
1939
- extensions.renderers[ext.name] = function(...args2) {
1940
- let ret = ext.renderer.apply(this, args2);
1941
- if (ret === false) {
1942
- ret = prevRenderer.apply(this, args2);
1943
- }
1944
- return ret;
1945
- };
1946
- } else {
1947
- extensions.renderers[ext.name] = ext.renderer;
1948
- }
1949
- }
1950
- if ("tokenizer" in ext) {
1951
- if (!ext.level || ext.level !== "block" && ext.level !== "inline") {
1952
- throw new Error("extension level must be 'block' or 'inline'");
1953
- }
1954
- if (extensions[ext.level]) {
1955
- extensions[ext.level].unshift(ext.tokenizer);
1956
- } else {
1957
- extensions[ext.level] = [ext.tokenizer];
1958
- }
1959
- if (ext.start) {
1960
- if (ext.level === "block") {
1961
- if (extensions.startBlock) {
1962
- extensions.startBlock.push(ext.start);
1963
- } else {
1964
- extensions.startBlock = [ext.start];
1965
- }
1966
- } else if (ext.level === "inline") {
1967
- if (extensions.startInline) {
1968
- extensions.startInline.push(ext.start);
1969
- } else {
1970
- extensions.startInline = [ext.start];
1971
- }
1972
- }
1973
- }
1974
- }
1975
- if ("childTokens" in ext && ext.childTokens) {
1976
- extensions.childTokens[ext.name] = ext.childTokens;
1977
- }
1978
- });
1979
- opts.extensions = extensions;
1980
- }
1981
- if (pack.renderer) {
1982
- const renderer = this.defaults.renderer || new _Renderer(this.defaults);
1983
- for (const prop in pack.renderer) {
1984
- const prevRenderer = renderer[prop];
1985
- renderer[prop] = (...args2) => {
1986
- let ret = pack.renderer[prop].apply(renderer, args2);
1987
- if (ret === false) {
1988
- ret = prevRenderer.apply(renderer, args2);
1989
- }
1990
- return ret;
1991
- };
1992
- }
1993
- opts.renderer = renderer;
1994
- }
1995
- if (pack.tokenizer) {
1996
- const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
1997
- for (const prop in pack.tokenizer) {
1998
- const prevTokenizer = tokenizer[prop];
1999
- tokenizer[prop] = (...args2) => {
2000
- let ret = pack.tokenizer[prop].apply(tokenizer, args2);
2001
- if (ret === false) {
2002
- ret = prevTokenizer.apply(tokenizer, args2);
2003
- }
2004
- return ret;
2005
- };
2006
- }
2007
- opts.tokenizer = tokenizer;
2008
- }
2009
- if (pack.hooks) {
2010
- const hooks = this.defaults.hooks || new _Hooks();
2011
- for (const prop in pack.hooks) {
2012
- const prevHook = hooks[prop];
2013
- if (_Hooks.passThroughHooks.has(prop)) {
2014
- hooks[prop] = (arg) => {
2015
- if (this.defaults.async) {
2016
- return Promise.resolve(pack.hooks[prop].call(hooks, arg)).then((ret2) => {
2017
- return prevHook.call(hooks, ret2);
2018
- });
2019
- }
2020
- const ret = pack.hooks[prop].call(hooks, arg);
2021
- return prevHook.call(hooks, ret);
2022
- };
2023
- } else {
2024
- hooks[prop] = (...args2) => {
2025
- let ret = pack.hooks[prop].apply(hooks, args2);
2026
- if (ret === false) {
2027
- ret = prevHook.apply(hooks, args2);
2028
- }
2029
- return ret;
2030
- };
2031
- }
2032
- }
2033
- opts.hooks = hooks;
2034
- }
2035
- if (pack.walkTokens) {
2036
- const walkTokens2 = this.defaults.walkTokens;
2037
- opts.walkTokens = function(token) {
2038
- let values = [];
2039
- values.push(pack.walkTokens.call(this, token));
2040
- if (walkTokens2) {
2041
- values = values.concat(walkTokens2.call(this, token));
2042
- }
2043
- return values;
2044
- };
2045
- }
2046
- this.defaults = { ...this.defaults, ...opts };
2047
- });
2048
- return this;
2049
- }
2050
- setOptions(opt) {
2051
- this.defaults = { ...this.defaults, ...opt };
2052
- return this;
2053
- }
2054
- };
2055
- _parseMarkdown = new WeakSet();
2056
- parseMarkdown_fn = function(lexer2, parser2) {
2057
- return (src, optOrCallback, callback) => {
2058
- if (typeof optOrCallback === "function") {
2059
- callback = optOrCallback;
2060
- optOrCallback = null;
2061
- }
2062
- const origOpt = { ...optOrCallback };
2063
- const opt = { ...this.defaults, ...origOpt };
2064
- const throwError = __privateMethod(this, _onError, onError_fn).call(this, !!opt.silent, !!opt.async, callback);
2065
- if (typeof src === "undefined" || src === null) {
2066
- return throwError(new Error("marked(): input parameter is undefined or null"));
2067
- }
2068
- if (typeof src !== "string") {
2069
- return throwError(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected"));
2070
- }
2071
- checkDeprecations(opt, callback);
2072
- if (opt.hooks) {
2073
- opt.hooks.options = opt;
1964
+ /**
1965
+ * Parsing & Compiling
1966
+ */
1967
+ class _Parser {
1968
+ options;
1969
+ renderer;
1970
+ textRenderer;
1971
+ slugger;
1972
+ constructor(options) {
1973
+ this.options = options || _defaults;
1974
+ this.options.renderer = this.options.renderer || new _Renderer();
1975
+ this.renderer = this.options.renderer;
1976
+ this.renderer.options = this.options;
1977
+ this.textRenderer = new _TextRenderer();
1978
+ this.slugger = new _Slugger();
1979
+ }
1980
+ /**
1981
+ * Static Parse Method
1982
+ */
1983
+ static parse(tokens, options) {
1984
+ const parser = new _Parser(options);
1985
+ return parser.parse(tokens);
1986
+ }
1987
+ /**
1988
+ * Static Parse Inline Method
1989
+ */
1990
+ static parseInline(tokens, options) {
1991
+ const parser = new _Parser(options);
1992
+ return parser.parseInline(tokens);
1993
+ }
1994
+ /**
1995
+ * Parse Loop
1996
+ */
1997
+ parse(tokens, top = true) {
1998
+ let out = '', i, j, k, l2, l3, row, cell, header, body, token, ordered, start, loose, itemBody, item, checked, task, checkbox, ret;
1999
+ const l = tokens.length;
2000
+ for (i = 0; i < l; i++) {
2001
+ token = tokens[i];
2002
+ // Run any renderer extensions
2003
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2004
+ ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
2005
+ if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(token.type)) {
2006
+ out += ret || '';
2007
+ continue;
2008
+ }
2009
+ }
2010
+ switch (token.type) {
2011
+ case 'space': {
2012
+ continue;
2013
+ }
2014
+ case 'hr': {
2015
+ out += this.renderer.hr();
2016
+ continue;
2017
+ }
2018
+ case 'heading': {
2019
+ out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
2020
+ continue;
2021
+ }
2022
+ case 'code': {
2023
+ out += this.renderer.code(token.text, token.lang, !!token.escaped);
2024
+ continue;
2025
+ }
2026
+ case 'table': {
2027
+ header = '';
2028
+ // header
2029
+ cell = '';
2030
+ l2 = token.header.length;
2031
+ for (j = 0; j < l2; j++) {
2032
+ cell += this.renderer.tablecell(this.parseInline(token.header[j].tokens), { header: true, align: token.align[j] });
2033
+ }
2034
+ header += this.renderer.tablerow(cell);
2035
+ body = '';
2036
+ l2 = token.rows.length;
2037
+ for (j = 0; j < l2; j++) {
2038
+ row = token.rows[j];
2039
+ cell = '';
2040
+ l3 = row.length;
2041
+ for (k = 0; k < l3; k++) {
2042
+ cell += this.renderer.tablecell(this.parseInline(row[k].tokens), { header: false, align: token.align[k] });
2043
+ }
2044
+ body += this.renderer.tablerow(cell);
2045
+ }
2046
+ out += this.renderer.table(header, body);
2047
+ continue;
2048
+ }
2049
+ case 'blockquote': {
2050
+ body = this.parse(token.tokens);
2051
+ out += this.renderer.blockquote(body);
2052
+ continue;
2053
+ }
2054
+ case 'list': {
2055
+ ordered = token.ordered;
2056
+ start = token.start;
2057
+ loose = token.loose;
2058
+ l2 = token.items.length;
2059
+ body = '';
2060
+ for (j = 0; j < l2; j++) {
2061
+ item = token.items[j];
2062
+ checked = item.checked;
2063
+ task = item.task;
2064
+ itemBody = '';
2065
+ if (item.task) {
2066
+ checkbox = this.renderer.checkbox(!!checked);
2067
+ if (loose) {
2068
+ if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
2069
+ item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
2070
+ if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
2071
+ item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
2072
+ }
2073
+ }
2074
+ else {
2075
+ item.tokens.unshift({
2076
+ type: 'text',
2077
+ text: checkbox
2078
+ });
2079
+ }
2080
+ }
2081
+ else {
2082
+ itemBody += checkbox;
2083
+ }
2084
+ }
2085
+ itemBody += this.parse(item.tokens, loose);
2086
+ body += this.renderer.listitem(itemBody, task, !!checked);
2087
+ }
2088
+ out += this.renderer.list(body, ordered, start);
2089
+ continue;
2090
+ }
2091
+ case 'html': {
2092
+ out += this.renderer.html(token.text, token.block);
2093
+ continue;
2094
+ }
2095
+ case 'paragraph': {
2096
+ out += this.renderer.paragraph(this.parseInline(token.tokens));
2097
+ continue;
2098
+ }
2099
+ case 'text': {
2100
+ body = token.tokens ? this.parseInline(token.tokens) : token.text;
2101
+ while (i + 1 < l && tokens[i + 1].type === 'text') {
2102
+ token = tokens[++i];
2103
+ body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
2104
+ }
2105
+ out += top ? this.renderer.paragraph(body) : body;
2106
+ continue;
2107
+ }
2108
+ default: {
2109
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
2110
+ if (this.options.silent) {
2111
+ console.error(errMsg);
2112
+ return '';
2113
+ }
2114
+ else {
2115
+ throw new Error(errMsg);
2116
+ }
2117
+ }
2118
+ }
2119
+ }
2120
+ return out;
2074
2121
  }
2075
- if (callback) {
2076
- const highlight = opt.highlight;
2077
- let tokens;
2078
- try {
2079
- if (opt.hooks) {
2080
- src = opt.hooks.preprocess(src);
2081
- }
2082
- tokens = lexer2(src, opt);
2083
- } catch (e) {
2084
- return throwError(e);
2085
- }
2086
- const done = (err) => {
2087
- let out;
2088
- if (!err) {
2089
- try {
2090
- if (opt.walkTokens) {
2091
- this.walkTokens(tokens, opt.walkTokens);
2092
- }
2093
- out = parser2(tokens, opt);
2094
- if (opt.hooks) {
2095
- out = opt.hooks.postprocess(out);
2096
- }
2097
- } catch (e) {
2098
- err = e;
2099
- }
2100
- }
2101
- opt.highlight = highlight;
2102
- return err ? throwError(err) : callback(null, out);
2103
- };
2104
- if (!highlight || highlight.length < 3) {
2105
- return done();
2106
- }
2107
- delete opt.highlight;
2108
- if (!tokens.length)
2109
- return done();
2110
- let pending = 0;
2111
- this.walkTokens(tokens, (token) => {
2112
- if (token.type === "code") {
2113
- pending++;
2114
- setTimeout(() => {
2115
- highlight(token.text, token.lang, (err, code) => {
2116
- if (err) {
2117
- return done(err);
2118
- }
2119
- if (code != null && code !== token.text) {
2120
- token.text = code;
2121
- token.escaped = true;
2122
- }
2123
- pending--;
2124
- if (pending === 0) {
2125
- done();
2126
- }
2127
- });
2128
- }, 0);
2122
+ /**
2123
+ * Parse Inline Tokens
2124
+ */
2125
+ parseInline(tokens, renderer) {
2126
+ renderer = renderer || this.renderer;
2127
+ let out = '', i, token, ret;
2128
+ const l = tokens.length;
2129
+ for (i = 0; i < l; i++) {
2130
+ token = tokens[i];
2131
+ // Run any renderer extensions
2132
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2133
+ ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
2134
+ if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
2135
+ out += ret || '';
2136
+ continue;
2137
+ }
2138
+ }
2139
+ switch (token.type) {
2140
+ case 'escape': {
2141
+ out += renderer.text(token.text);
2142
+ break;
2143
+ }
2144
+ case 'html': {
2145
+ out += renderer.html(token.text);
2146
+ break;
2147
+ }
2148
+ case 'link': {
2149
+ out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
2150
+ break;
2151
+ }
2152
+ case 'image': {
2153
+ out += renderer.image(token.href, token.title, token.text);
2154
+ break;
2155
+ }
2156
+ case 'strong': {
2157
+ out += renderer.strong(this.parseInline(token.tokens, renderer));
2158
+ break;
2159
+ }
2160
+ case 'em': {
2161
+ out += renderer.em(this.parseInline(token.tokens, renderer));
2162
+ break;
2163
+ }
2164
+ case 'codespan': {
2165
+ out += renderer.codespan(token.text);
2166
+ break;
2167
+ }
2168
+ case 'br': {
2169
+ out += renderer.br();
2170
+ break;
2171
+ }
2172
+ case 'del': {
2173
+ out += renderer.del(this.parseInline(token.tokens, renderer));
2174
+ break;
2175
+ }
2176
+ case 'text': {
2177
+ out += renderer.text(token.text);
2178
+ break;
2179
+ }
2180
+ default: {
2181
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
2182
+ if (this.options.silent) {
2183
+ console.error(errMsg);
2184
+ return '';
2185
+ }
2186
+ else {
2187
+ throw new Error(errMsg);
2188
+ }
2189
+ }
2190
+ }
2129
2191
  }
2130
- });
2131
- if (pending === 0) {
2132
- done();
2133
- }
2134
- return;
2192
+ return out;
2135
2193
  }
2136
- if (opt.async) {
2137
- return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src).then((src2) => lexer2(src2, opt)).then((tokens) => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens).then((tokens) => parser2(tokens, opt)).then((html) => opt.hooks ? opt.hooks.postprocess(html) : html).catch(throwError);
2194
+ }
2195
+
2196
+ class _Hooks {
2197
+ options;
2198
+ constructor(options) {
2199
+ this.options = options || _defaults;
2200
+ }
2201
+ static passThroughHooks = new Set([
2202
+ 'preprocess',
2203
+ 'postprocess'
2204
+ ]);
2205
+ /**
2206
+ * Process markdown before marked
2207
+ */
2208
+ preprocess(markdown) {
2209
+ return markdown;
2210
+ }
2211
+ /**
2212
+ * Process HTML after marked is finished
2213
+ */
2214
+ postprocess(html) {
2215
+ return html;
2138
2216
  }
2139
- try {
2140
- if (opt.hooks) {
2141
- src = opt.hooks.preprocess(src);
2142
- }
2143
- const tokens = lexer2(src, opt);
2144
- if (opt.walkTokens) {
2145
- this.walkTokens(tokens, opt.walkTokens);
2146
- }
2147
- let html = parser2(tokens, opt);
2148
- if (opt.hooks) {
2149
- html = opt.hooks.postprocess(html);
2150
- }
2151
- return html;
2152
- } catch (e) {
2153
- return throwError(e);
2154
- }
2155
- };
2156
- };
2157
- _onError = new WeakSet();
2158
- onError_fn = function(silent, async, callback) {
2159
- return (e) => {
2160
- e.message += "\nPlease report this to https://github.com/markedjs/marked.";
2161
- if (silent) {
2162
- const msg = "<p>An error occurred:</p><pre>" + escape(e.message + "", true) + "</pre>";
2163
- if (async) {
2164
- return Promise.resolve(msg);
2165
- }
2166
- if (callback) {
2167
- callback(null, msg);
2168
- return;
2169
- }
2170
- return msg;
2217
+ }
2218
+
2219
+ class Marked {
2220
+ defaults = _getDefaults();
2221
+ options = this.setOptions;
2222
+ parse = this.#parseMarkdown(_Lexer.lex, _Parser.parse);
2223
+ parseInline = this.#parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
2224
+ Parser = _Parser;
2225
+ parser = _Parser.parse;
2226
+ Renderer = _Renderer;
2227
+ TextRenderer = _TextRenderer;
2228
+ Lexer = _Lexer;
2229
+ lexer = _Lexer.lex;
2230
+ Tokenizer = _Tokenizer;
2231
+ Slugger = _Slugger;
2232
+ Hooks = _Hooks;
2233
+ constructor(...args) {
2234
+ this.use(...args);
2235
+ }
2236
+ /**
2237
+ * Run callback for every token
2238
+ */
2239
+ walkTokens(tokens, callback) {
2240
+ let values = [];
2241
+ for (const token of tokens) {
2242
+ values = values.concat(callback.call(this, token));
2243
+ switch (token.type) {
2244
+ case 'table': {
2245
+ for (const cell of token.header) {
2246
+ values = values.concat(this.walkTokens(cell.tokens, callback));
2247
+ }
2248
+ for (const row of token.rows) {
2249
+ for (const cell of row) {
2250
+ values = values.concat(this.walkTokens(cell.tokens, callback));
2251
+ }
2252
+ }
2253
+ break;
2254
+ }
2255
+ case 'list': {
2256
+ values = values.concat(this.walkTokens(token.items, callback));
2257
+ break;
2258
+ }
2259
+ default: {
2260
+ if (this.defaults.extensions && this.defaults.extensions.childTokens && this.defaults.extensions.childTokens[token.type]) { // Walk any extensions
2261
+ this.defaults.extensions.childTokens[token.type].forEach((childTokens) => {
2262
+ // @ts-expect-error we assume token[childToken] is an array of tokens but we can't be sure
2263
+ values = values.concat(this.walkTokens(token[childTokens], callback));
2264
+ });
2265
+ }
2266
+ else if (token.tokens) {
2267
+ values = values.concat(this.walkTokens(token.tokens, callback));
2268
+ }
2269
+ }
2270
+ }
2271
+ }
2272
+ return values;
2273
+ }
2274
+ use(...args) {
2275
+ const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
2276
+ args.forEach((pack) => {
2277
+ // copy options to new object
2278
+ const opts = { ...pack };
2279
+ // set async to true if it was set to true before
2280
+ opts.async = this.defaults.async || opts.async || false;
2281
+ // ==-- Parse "addon" extensions --== //
2282
+ if (pack.extensions) {
2283
+ pack.extensions.forEach((ext) => {
2284
+ if (!ext.name) {
2285
+ throw new Error('extension name required');
2286
+ }
2287
+ if ('renderer' in ext) { // Renderer extensions
2288
+ const prevRenderer = extensions.renderers[ext.name];
2289
+ if (prevRenderer) {
2290
+ // Replace extension with func to run new extension but fall back if false
2291
+ extensions.renderers[ext.name] = function (...args) {
2292
+ let ret = ext.renderer.apply(this, args);
2293
+ if (ret === false) {
2294
+ ret = prevRenderer.apply(this, args);
2295
+ }
2296
+ return ret;
2297
+ };
2298
+ }
2299
+ else {
2300
+ extensions.renderers[ext.name] = ext.renderer;
2301
+ }
2302
+ }
2303
+ if ('tokenizer' in ext) { // Tokenizer Extensions
2304
+ if (!ext.level || (ext.level !== 'block' && ext.level !== 'inline')) {
2305
+ throw new Error("extension level must be 'block' or 'inline'");
2306
+ }
2307
+ if (extensions[ext.level]) {
2308
+ extensions[ext.level].unshift(ext.tokenizer);
2309
+ }
2310
+ else {
2311
+ extensions[ext.level] = [ext.tokenizer];
2312
+ }
2313
+ if (ext.start) { // Function to check for start of token
2314
+ if (ext.level === 'block') {
2315
+ if (extensions.startBlock) {
2316
+ extensions.startBlock.push(ext.start);
2317
+ }
2318
+ else {
2319
+ extensions.startBlock = [ext.start];
2320
+ }
2321
+ }
2322
+ else if (ext.level === 'inline') {
2323
+ if (extensions.startInline) {
2324
+ extensions.startInline.push(ext.start);
2325
+ }
2326
+ else {
2327
+ extensions.startInline = [ext.start];
2328
+ }
2329
+ }
2330
+ }
2331
+ }
2332
+ if ('childTokens' in ext && ext.childTokens) { // Child tokens to be visited by walkTokens
2333
+ extensions.childTokens[ext.name] = ext.childTokens;
2334
+ }
2335
+ });
2336
+ opts.extensions = extensions;
2337
+ }
2338
+ // ==-- Parse "overwrite" extensions --== //
2339
+ if (pack.renderer) {
2340
+ const renderer = this.defaults.renderer || new _Renderer(this.defaults);
2341
+ for (const prop in pack.renderer) {
2342
+ const rendererFunc = pack.renderer[prop];
2343
+ const rendererKey = prop;
2344
+ const prevRenderer = renderer[rendererKey];
2345
+ // Replace renderer with func to run extension, but fall back if false
2346
+ renderer[rendererKey] = (...args) => {
2347
+ let ret = rendererFunc.apply(renderer, args);
2348
+ if (ret === false) {
2349
+ ret = prevRenderer.apply(renderer, args);
2350
+ }
2351
+ return ret || '';
2352
+ };
2353
+ }
2354
+ opts.renderer = renderer;
2355
+ }
2356
+ if (pack.tokenizer) {
2357
+ const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
2358
+ for (const prop in pack.tokenizer) {
2359
+ const tokenizerFunc = pack.tokenizer[prop];
2360
+ const tokenizerKey = prop;
2361
+ const prevTokenizer = tokenizer[tokenizerKey];
2362
+ // Replace tokenizer with func to run extension, but fall back if false
2363
+ tokenizer[tokenizerKey] = (...args) => {
2364
+ let ret = tokenizerFunc.apply(tokenizer, args);
2365
+ if (ret === false) {
2366
+ ret = prevTokenizer.apply(tokenizer, args);
2367
+ }
2368
+ return ret;
2369
+ };
2370
+ }
2371
+ opts.tokenizer = tokenizer;
2372
+ }
2373
+ // ==-- Parse Hooks extensions --== //
2374
+ if (pack.hooks) {
2375
+ const hooks = this.defaults.hooks || new _Hooks();
2376
+ for (const prop in pack.hooks) {
2377
+ const hooksFunc = pack.hooks[prop];
2378
+ const hooksKey = prop;
2379
+ const prevHook = hooks[hooksKey];
2380
+ if (_Hooks.passThroughHooks.has(prop)) {
2381
+ hooks[hooksKey] = (arg) => {
2382
+ if (this.defaults.async) {
2383
+ return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
2384
+ return prevHook.call(hooks, ret);
2385
+ });
2386
+ }
2387
+ const ret = hooksFunc.call(hooks, arg);
2388
+ return prevHook.call(hooks, ret);
2389
+ };
2390
+ }
2391
+ else {
2392
+ hooks[hooksKey] = (...args) => {
2393
+ let ret = hooksFunc.apply(hooks, args);
2394
+ if (ret === false) {
2395
+ ret = prevHook.apply(hooks, args);
2396
+ }
2397
+ return ret;
2398
+ };
2399
+ }
2400
+ }
2401
+ opts.hooks = hooks;
2402
+ }
2403
+ // ==-- Parse WalkTokens extensions --== //
2404
+ if (pack.walkTokens) {
2405
+ const walkTokens = this.defaults.walkTokens;
2406
+ opts.walkTokens = function (token) {
2407
+ let values = [];
2408
+ values.push(pack.walkTokens.call(this, token));
2409
+ if (walkTokens) {
2410
+ values = values.concat(walkTokens.call(this, token));
2411
+ }
2412
+ return values;
2413
+ };
2414
+ }
2415
+ this.defaults = { ...this.defaults, ...opts };
2416
+ });
2417
+ return this;
2171
2418
  }
2172
- if (async) {
2173
- return Promise.reject(e);
2419
+ setOptions(opt) {
2420
+ this.defaults = { ...this.defaults, ...opt };
2421
+ return this;
2174
2422
  }
2175
- if (callback) {
2176
- callback(e);
2177
- return;
2423
+ #parseMarkdown(lexer, parser) {
2424
+ return (src, optOrCallback, callback) => {
2425
+ if (typeof optOrCallback === 'function') {
2426
+ callback = optOrCallback;
2427
+ optOrCallback = null;
2428
+ }
2429
+ const origOpt = { ...optOrCallback };
2430
+ const opt = { ...this.defaults, ...origOpt };
2431
+ const throwError = this.#onError(!!opt.silent, !!opt.async, callback);
2432
+ // throw error in case of non string input
2433
+ if (typeof src === 'undefined' || src === null) {
2434
+ return throwError(new Error('marked(): input parameter is undefined or null'));
2435
+ }
2436
+ if (typeof src !== 'string') {
2437
+ return throwError(new Error('marked(): input parameter is of type '
2438
+ + Object.prototype.toString.call(src) + ', string expected'));
2439
+ }
2440
+ checkDeprecations(opt, callback);
2441
+ if (opt.hooks) {
2442
+ opt.hooks.options = opt;
2443
+ }
2444
+ if (callback) {
2445
+ const highlight = opt.highlight;
2446
+ let tokens;
2447
+ try {
2448
+ if (opt.hooks) {
2449
+ src = opt.hooks.preprocess(src);
2450
+ }
2451
+ tokens = lexer(src, opt);
2452
+ }
2453
+ catch (e) {
2454
+ return throwError(e);
2455
+ }
2456
+ const done = (err) => {
2457
+ let out;
2458
+ if (!err) {
2459
+ try {
2460
+ if (opt.walkTokens) {
2461
+ this.walkTokens(tokens, opt.walkTokens);
2462
+ }
2463
+ out = parser(tokens, opt);
2464
+ if (opt.hooks) {
2465
+ out = opt.hooks.postprocess(out);
2466
+ }
2467
+ }
2468
+ catch (e) {
2469
+ err = e;
2470
+ }
2471
+ }
2472
+ opt.highlight = highlight;
2473
+ return err
2474
+ ? throwError(err)
2475
+ : callback(null, out);
2476
+ };
2477
+ if (!highlight || highlight.length < 3) {
2478
+ return done();
2479
+ }
2480
+ delete opt.highlight;
2481
+ if (!tokens.length)
2482
+ return done();
2483
+ let pending = 0;
2484
+ this.walkTokens(tokens, (token) => {
2485
+ if (token.type === 'code') {
2486
+ pending++;
2487
+ setTimeout(() => {
2488
+ highlight(token.text, token.lang, (err, code) => {
2489
+ if (err) {
2490
+ return done(err);
2491
+ }
2492
+ if (code != null && code !== token.text) {
2493
+ token.text = code;
2494
+ token.escaped = true;
2495
+ }
2496
+ pending--;
2497
+ if (pending === 0) {
2498
+ done();
2499
+ }
2500
+ });
2501
+ }, 0);
2502
+ }
2503
+ });
2504
+ if (pending === 0) {
2505
+ done();
2506
+ }
2507
+ return;
2508
+ }
2509
+ if (opt.async) {
2510
+ return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2511
+ .then(src => lexer(src, opt))
2512
+ .then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens)
2513
+ .then(tokens => parser(tokens, opt))
2514
+ .then(html => opt.hooks ? opt.hooks.postprocess(html) : html)
2515
+ .catch(throwError);
2516
+ }
2517
+ try {
2518
+ if (opt.hooks) {
2519
+ src = opt.hooks.preprocess(src);
2520
+ }
2521
+ const tokens = lexer(src, opt);
2522
+ if (opt.walkTokens) {
2523
+ this.walkTokens(tokens, opt.walkTokens);
2524
+ }
2525
+ let html = parser(tokens, opt);
2526
+ if (opt.hooks) {
2527
+ html = opt.hooks.postprocess(html);
2528
+ }
2529
+ return html;
2530
+ }
2531
+ catch (e) {
2532
+ return throwError(e);
2533
+ }
2534
+ };
2178
2535
  }
2179
- throw e;
2180
- };
2181
- };
2536
+ #onError(silent, async, callback) {
2537
+ return (e) => {
2538
+ e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2539
+ if (silent) {
2540
+ const msg = '<p>An error occurred:</p><pre>'
2541
+ + escape(e.message + '', true)
2542
+ + '</pre>';
2543
+ if (async) {
2544
+ return Promise.resolve(msg);
2545
+ }
2546
+ if (callback) {
2547
+ callback(null, msg);
2548
+ return;
2549
+ }
2550
+ return msg;
2551
+ }
2552
+ if (async) {
2553
+ return Promise.reject(e);
2554
+ }
2555
+ if (callback) {
2556
+ callback(e);
2557
+ return;
2558
+ }
2559
+ throw e;
2560
+ };
2561
+ }
2562
+ }
2182
2563
 
2183
- // src/marked.ts
2184
- var markedInstance = new Marked();
2564
+ const markedInstance = new Marked();
2185
2565
  function marked(src, opt, callback) {
2186
- return markedInstance.parse(src, opt, callback);
2566
+ return markedInstance.parse(src, opt, callback);
2187
2567
  }
2188
- marked.options = marked.setOptions = function(options2) {
2189
- markedInstance.setOptions(options2);
2190
- marked.defaults = markedInstance.defaults;
2191
- changeDefaults(marked.defaults);
2192
- return marked;
2193
- };
2568
+ /**
2569
+ * Sets the default options.
2570
+ *
2571
+ * @param options Hash of options
2572
+ */
2573
+ marked.options =
2574
+ marked.setOptions = function (options) {
2575
+ markedInstance.setOptions(options);
2576
+ marked.defaults = markedInstance.defaults;
2577
+ changeDefaults(marked.defaults);
2578
+ return marked;
2579
+ };
2580
+ /**
2581
+ * Gets the original marked default options.
2582
+ */
2194
2583
  marked.getDefaults = _getDefaults;
2195
2584
  marked.defaults = _defaults;
2196
- marked.use = function(...args) {
2197
- markedInstance.use(...args);
2198
- marked.defaults = markedInstance.defaults;
2199
- changeDefaults(marked.defaults);
2200
- return marked;
2585
+ /**
2586
+ * Use Extension
2587
+ */
2588
+ marked.use = function (...args) {
2589
+ markedInstance.use(...args);
2590
+ marked.defaults = markedInstance.defaults;
2591
+ changeDefaults(marked.defaults);
2592
+ return marked;
2201
2593
  };
2202
- marked.walkTokens = function(tokens, callback) {
2203
- return markedInstance.walkTokens(tokens, callback);
2594
+ /**
2595
+ * Run callback for every token
2596
+ */
2597
+ marked.walkTokens = function (tokens, callback) {
2598
+ return markedInstance.walkTokens(tokens, callback);
2204
2599
  };
2600
+ /**
2601
+ * Compiles markdown to HTML without enclosing `p` tag.
2602
+ *
2603
+ * @param src String of markdown source to be compiled
2604
+ * @param options Hash of options
2605
+ * @return String of compiled HTML
2606
+ */
2205
2607
  marked.parseInline = markedInstance.parseInline;
2608
+ /**
2609
+ * Expose
2610
+ */
2206
2611
  marked.Parser = _Parser;
2207
2612
  marked.parser = _Parser.parse;
2208
2613
  marked.Renderer = _Renderer;
2209
2614
  marked.TextRenderer = _TextRenderer;
2210
- marked.Lexer = _Lexer2;
2211
- marked.lexer = _Lexer2.lex;
2615
+ marked.Lexer = _Lexer;
2616
+ marked.lexer = _Lexer.lex;
2212
2617
  marked.Tokenizer = _Tokenizer;
2213
2618
  marked.Slugger = _Slugger;
2214
2619
  marked.Hooks = _Hooks;
2215
2620
  marked.parse = marked;
2216
- var options = marked.options;
2217
- var setOptions = marked.setOptions;
2218
- var use = marked.use;
2219
- var walkTokens = marked.walkTokens;
2220
- var parseInline = marked.parseInline;
2221
- var parse = marked;
2222
- var parser = _Parser.parse;
2223
- var lexer = _Lexer2.lex;
2224
- export {
2225
- _Hooks as Hooks,
2226
- _Lexer2 as Lexer,
2227
- Marked,
2228
- _Parser as Parser,
2229
- _Renderer as Renderer,
2230
- _Slugger as Slugger,
2231
- _TextRenderer as TextRenderer,
2232
- _Tokenizer as Tokenizer,
2233
- _defaults as defaults,
2234
- _getDefaults as getDefaults,
2235
- lexer,
2236
- marked,
2237
- options,
2238
- parse,
2239
- parseInline,
2240
- parser,
2241
- setOptions,
2242
- use,
2243
- walkTokens
2244
- };
2245
- //# sourceMappingURL=marked.esm.js.map
2621
+ const options = marked.options;
2622
+ const setOptions = marked.setOptions;
2623
+ const use = marked.use;
2624
+ const walkTokens = marked.walkTokens;
2625
+ const parseInline = marked.parseInline;
2626
+ const parse = marked;
2627
+ const parser = _Parser.parse;
2628
+ const lexer = _Lexer.lex;
2629
+
2630
+ export { _Hooks as Hooks, _Lexer as Lexer, Marked, _Parser as Parser, _Renderer as Renderer, _Slugger as Slugger, _TextRenderer as TextRenderer, _Tokenizer as Tokenizer, _defaults as defaults, _getDefaults as getDefaults, lexer, marked, options, parse, parseInline, parser, setOptions, use, walkTokens };
2631
+ //# sourceMappingURL=marked.esm.js.map