marked 7.0.0 → 7.0.1

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.1 - 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,2613 @@
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 (cells.length > count) {
193
+ cells.splice(count);
194
+ }
195
+ else {
196
+ while (cells.length < count)
197
+ cells.push('');
198
+ }
199
+ for (; i < cells.length; i++) {
200
+ // leading or trailing whitespace is ignored per the gfm spec
201
+ cells[i] = cells[i].trim().replace(/\\\|/g, '|');
202
+ }
203
+ return cells;
191
204
  }
205
+ /**
206
+ * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
207
+ * /c*$/ is vulnerable to REDOS.
208
+ *
209
+ * @param str
210
+ * @param c
211
+ * @param invert Remove suffix of non-c chars instead. Default falsey.
212
+ */
192
213
  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);
214
+ const l = str.length;
215
+ if (l === 0) {
216
+ return '';
217
+ }
218
+ // Length of suffix matching the invert condition.
219
+ let suffLen = 0;
220
+ // Step left until we fail to match the invert condition.
221
+ while (suffLen < l) {
222
+ const currChar = str.charAt(l - suffLen - 1);
223
+ if (currChar === c && !invert) {
224
+ suffLen++;
225
+ }
226
+ else if (currChar !== c && invert) {
227
+ suffLen++;
228
+ }
229
+ else {
230
+ break;
231
+ }
232
+ }
233
+ return str.slice(0, l - suffLen);
209
234
  }
210
235
  function findClosingBracket(str, b) {
211
- if (str.indexOf(b[1]) === -1) {
236
+ if (str.indexOf(b[1]) === -1) {
237
+ return -1;
238
+ }
239
+ const l = str.length;
240
+ let level = 0, i = 0;
241
+ for (; i < l; i++) {
242
+ if (str[i] === '\\') {
243
+ i++;
244
+ }
245
+ else if (str[i] === b[0]) {
246
+ level++;
247
+ }
248
+ else if (str[i] === b[1]) {
249
+ level--;
250
+ if (level < 0) {
251
+ return i;
252
+ }
253
+ }
254
+ }
212
255
  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
256
  }
230
257
  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
- }
258
+ if (!opt || opt.silent) {
259
+ return;
260
+ }
261
+ if (callback) {
262
+ 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');
263
+ }
264
+ if (opt.sanitize || opt.sanitizer) {
265
+ 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');
266
+ }
267
+ if (opt.highlight || opt.langPrefix !== 'language-') {
268
+ 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.');
269
+ }
270
+ if (opt.mangle) {
271
+ 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}`.');
272
+ }
273
+ if (opt.baseUrl) {
274
+ 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.');
275
+ }
276
+ if (opt.smartypants) {
277
+ 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.');
278
+ }
279
+ if (opt.xhtml) {
280
+ 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.');
281
+ }
282
+ if (opt.headerIds || opt.headerPrefix) {
283
+ 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}`.');
284
+ }
258
285
  }
259
286
 
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)
287
+ function outputLink(cap, link, raw, lexer) {
288
+ const href = link.href;
289
+ const title = link.title ? escape(link.title) : null;
290
+ const text = cap[1].replace(/\\([\[\]])/g, '$1');
291
+ if (cap[0].charAt(0) !== '!') {
292
+ lexer.state.inLink = true;
293
+ const token = {
294
+ type: 'link',
295
+ raw,
296
+ href,
297
+ title,
298
+ text,
299
+ tokens: lexer.inlineTokens(text)
300
+ };
301
+ lexer.state.inLink = false;
302
+ return token;
303
+ }
304
+ return {
305
+ type: 'image',
306
+ raw,
307
+ href,
308
+ title,
309
+ text: escape(text)
274
310
  };
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
311
  }
286
312
  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");
313
+ const matchIndentToCode = raw.match(/^(\s+)(?:```)/);
314
+ if (matchIndentToCode === null) {
315
+ return text;
316
+ }
317
+ const indentToCode = matchIndentToCode[1];
318
+ return text
319
+ .split('\n')
320
+ .map(node => {
321
+ const matchIndentInNode = node.match(/^\s+/);
322
+ if (matchIndentInNode === null) {
323
+ return node;
324
+ }
325
+ const [indentInNode] = matchIndentInNode;
326
+ if (indentInNode.length >= indentToCode.length) {
327
+ return node.slice(indentToCode.length);
328
+ }
329
+ return node;
330
+ })
331
+ .join('\n');
303
332
  }
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;
333
+ /**
334
+ * Tokenizer
335
+ */
336
+ class _Tokenizer {
337
+ options;
338
+ rules;
339
+ lexer;
340
+ constructor(options) {
341
+ this.options = options || _defaults;
342
+ }
343
+ space(src) {
344
+ const cap = this.rules.block.newline.exec(src);
345
+ if (cap && cap[0].length > 0) {
346
+ return {
347
+ type: 'space',
348
+ raw: cap[0]
349
+ };
350
+ }
351
+ }
352
+ code(src) {
353
+ const cap = this.rules.block.code.exec(src);
354
+ if (cap) {
355
+ const text = cap[0].replace(/^ {1,4}/gm, '');
356
+ return {
357
+ type: 'code',
358
+ raw: cap[0],
359
+ codeBlockStyle: 'indented',
360
+ text: !this.options.pedantic
361
+ ? rtrim(text, '\n')
362
+ : text
363
+ };
364
+ }
365
+ }
366
+ fences(src) {
367
+ const cap = this.rules.block.fences.exec(src);
368
+ if (cap) {
369
+ const raw = cap[0];
370
+ const text = indentCodeCompensation(raw, cap[3] || '');
371
+ return {
372
+ type: 'code',
373
+ raw,
374
+ lang: cap[2] ? cap[2].trim().replace(this.rules.inline._escapes, '$1') : cap[2],
375
+ text
376
+ };
377
+ }
378
+ }
379
+ heading(src) {
380
+ const cap = this.rules.block.heading.exec(src);
381
+ if (cap) {
382
+ let text = cap[2].trim();
383
+ // remove trailing #s
384
+ if (/#$/.test(text)) {
385
+ const trimmed = rtrim(text, '#');
386
+ if (this.options.pedantic) {
387
+ text = trimmed.trim();
388
+ }
389
+ else if (!trimmed || / $/.test(trimmed)) {
390
+ // CommonMark requires space before trailing #s
391
+ text = trimmed.trim();
392
+ }
393
+ }
394
+ return {
395
+ type: 'heading',
396
+ raw: cap[0],
397
+ depth: cap[1].length,
398
+ text,
399
+ tokens: this.lexer.inline(text)
400
+ };
401
+ }
402
+ }
403
+ hr(src) {
404
+ const cap = this.rules.block.hr.exec(src);
405
+ if (cap) {
406
+ return {
407
+ type: 'hr',
408
+ raw: cap[0]
409
+ };
410
+ }
411
+ }
412
+ blockquote(src) {
413
+ const cap = this.rules.block.blockquote.exec(src);
414
+ if (cap) {
415
+ const text = cap[0].replace(/^ *>[ \t]?/gm, '');
416
+ const top = this.lexer.state.top;
417
+ this.lexer.state.top = true;
418
+ const tokens = this.lexer.blockTokens(text);
419
+ this.lexer.state.top = top;
420
+ return {
421
+ type: 'blockquote',
422
+ raw: cap[0],
423
+ tokens,
424
+ text
425
+ };
426
+ }
427
+ }
428
+ list(src) {
429
+ let cap = this.rules.block.list.exec(src);
430
+ if (cap) {
431
+ let raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine, line, nextLine, rawLine, itemContents, endEarly;
432
+ let bull = cap[1].trim();
433
+ const isordered = bull.length > 1;
434
+ const list = {
435
+ type: 'list',
436
+ raw: '',
437
+ ordered: isordered,
438
+ start: isordered ? +bull.slice(0, -1) : '',
439
+ loose: false,
440
+ items: []
441
+ };
442
+ bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
442
443
  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
- };
444
+ bull = isordered ? bull : '[*+-]';
445
+ }
446
+ // Get next list item
447
+ const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
448
+ // Check if current bullet point can start a new List Item
449
+ while (src) {
450
+ endEarly = false;
451
+ if (!(cap = itemRegex.exec(src))) {
452
+ break;
453
+ }
454
+ if (this.rules.block.hr.test(src)) { // End list if bullet was actually HR (possibly move into itemRegex?)
455
+ break;
456
+ }
457
+ raw = cap[0];
458
+ src = src.substring(raw.length);
459
+ line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length));
460
+ nextLine = src.split('\n', 1)[0];
461
+ if (this.options.pedantic) {
462
+ indent = 2;
463
+ itemContents = line.trimLeft();
464
+ }
465
+ else {
466
+ indent = cap[2].search(/[^ ]/); // Find first non-space char
467
+ indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
468
+ itemContents = line.slice(indent);
469
+ indent += cap[1].length;
470
+ }
471
+ blankLine = false;
472
+ if (!line && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
473
+ raw += nextLine + '\n';
474
+ src = src.substring(nextLine.length + 1);
475
+ endEarly = true;
476
+ }
477
+ if (!endEarly) {
478
+ const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
479
+ const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
480
+ const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
481
+ const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
482
+ // Check if following lines should be included in List Item
483
+ while (src) {
484
+ rawLine = src.split('\n', 1)[0];
485
+ nextLine = rawLine;
486
+ // Re-align to follow commonmark nesting rules
487
+ if (this.options.pedantic) {
488
+ nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
489
+ }
490
+ // End list item if found code fences
491
+ if (fencesBeginRegex.test(nextLine)) {
492
+ break;
493
+ }
494
+ // End list item if found start of new heading
495
+ if (headingBeginRegex.test(nextLine)) {
496
+ break;
497
+ }
498
+ // End list item if found start of new bullet
499
+ if (nextBulletRegex.test(nextLine)) {
500
+ break;
501
+ }
502
+ // Horizontal rule found
503
+ if (hrRegex.test(src)) {
504
+ break;
505
+ }
506
+ if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
507
+ itemContents += '\n' + nextLine.slice(indent);
508
+ }
509
+ else {
510
+ // not enough indentation
511
+ if (blankLine) {
512
+ break;
513
+ }
514
+ // paragraph continuation unless last line was a different block level element
515
+ if (line.search(/[^ ]/) >= 4) { // indented code block
516
+ break;
517
+ }
518
+ if (fencesBeginRegex.test(line)) {
519
+ break;
520
+ }
521
+ if (headingBeginRegex.test(line)) {
522
+ break;
523
+ }
524
+ if (hrRegex.test(line)) {
525
+ break;
526
+ }
527
+ itemContents += '\n' + nextLine;
528
+ }
529
+ if (!blankLine && !nextLine.trim()) { // Check if current line is blank
530
+ blankLine = true;
531
+ }
532
+ raw += rawLine + '\n';
533
+ src = src.substring(rawLine.length + 1);
534
+ line = nextLine.slice(indent);
535
+ }
536
+ }
537
+ if (!list.loose) {
538
+ // If the previous item ended with a blank line, the list is loose
539
+ if (endsWithBlankLine) {
540
+ list.loose = true;
541
+ }
542
+ else if (/\n *\n *$/.test(raw)) {
543
+ endsWithBlankLine = true;
544
+ }
545
+ }
546
+ // Check for task list items
547
+ if (this.options.gfm) {
548
+ istask = /^\[[ xX]\] /.exec(itemContents);
549
+ if (istask) {
550
+ ischecked = istask[0] !== '[ ] ';
551
+ itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
552
+ }
553
+ }
554
+ list.items.push({
555
+ type: 'list_item',
556
+ raw,
557
+ task: !!istask,
558
+ checked: ischecked,
559
+ loose: false,
560
+ text: itemContents
561
+ });
562
+ list.raw += raw;
563
+ }
564
+ // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
565
+ list.items[list.items.length - 1].raw = raw.trimRight();
566
+ list.items[list.items.length - 1].text = itemContents.trimRight();
567
+ list.raw = list.raw.trimRight();
568
+ const l = list.items.length;
569
+ // Item child tokens handled here at end because we needed to have the final item to trim it first
570
+ for (i = 0; i < l; i++) {
571
+ this.lexer.state.top = false;
572
+ list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
573
+ if (!list.loose) {
574
+ // Check if list should be loose
575
+ const spacers = list.items[i].tokens.filter(t => t.type === 'space');
576
+ const hasMultipleLineBreaks = spacers.length > 0 && spacers.some(t => /\n.*\n/.test(t.raw));
577
+ list.loose = hasMultipleLineBreaks;
578
+ }
579
+ }
580
+ // Set all items to loose if list is loose
581
+ if (list.loose) {
582
+ for (i = 0; i < l; i++) {
583
+ list.items[i].loose = true;
584
+ }
585
+ }
586
+ return list;
587
+ }
588
+ }
589
+ html(src) {
590
+ const cap = this.rules.block.html.exec(src);
591
+ if (cap) {
592
+ const token = {
593
+ type: 'html',
594
+ block: true,
595
+ raw: cap[0],
596
+ pre: !this.options.sanitizer
597
+ && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
598
+ text: cap[0]
599
+ };
600
+ if (this.options.sanitize) {
601
+ const text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
602
+ const paragraph = token;
603
+ paragraph.type = 'paragraph';
604
+ paragraph.text = text;
605
+ paragraph.tokens = this.lexer.inline(text);
606
+ }
607
+ return token;
608
+ }
609
+ }
610
+ def(src) {
611
+ const cap = this.rules.block.def.exec(src);
612
+ if (cap) {
613
+ const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
614
+ const href = cap[2] ? cap[2].replace(/^<(.*)>$/, '$1').replace(this.rules.inline._escapes, '$1') : '';
615
+ const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline._escapes, '$1') : cap[3];
616
+ return {
617
+ type: 'def',
618
+ tag,
619
+ raw: cap[0],
620
+ href,
621
+ title
622
+ };
785
623
  }
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
- };
624
+ }
625
+ table(src) {
626
+ const cap = this.rules.block.table.exec(src);
627
+ if (cap) {
628
+ const item = {
629
+ type: 'table',
630
+ // splitCells expects a number as second argument
631
+ // @ts-expect-error
632
+ header: splitCells(cap[1]).map(c => {
633
+ return { text: c };
634
+ }),
635
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
636
+ rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
637
+ };
638
+ if (item.header.length === item.align.length) {
639
+ item.raw = cap[0];
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, lastToken, cutSrc, lastParagraphClipped;
1410
+ while (src) {
1411
+ if (this.options.extensions
1412
+ && this.options.extensions.block
1413
+ && this.options.extensions.block.some((extTokenizer) => {
1414
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1415
+ src = src.substring(token.raw.length);
1416
+ tokens.push(token);
1417
+ return true;
1418
+ }
1419
+ return false;
1420
+ })) {
1421
+ continue;
1422
+ }
1423
+ // newline
1424
+ if (token = this.tokenizer.space(src)) {
1425
+ src = src.substring(token.raw.length);
1426
+ if (token.raw.length === 1 && tokens.length > 0) {
1427
+ // if there's a single \n as a spacer, it's terminating the last line,
1428
+ // so move it there so that we don't get unecessary paragraph tags
1429
+ tokens[tokens.length - 1].raw += '\n';
1430
+ }
1431
+ else {
1432
+ tokens.push(token);
1433
+ }
1434
+ continue;
1435
+ }
1436
+ // code
1437
+ if (token = this.tokenizer.code(src)) {
1438
+ src = src.substring(token.raw.length);
1439
+ lastToken = tokens[tokens.length - 1];
1440
+ // An indented code block cannot interrupt a paragraph.
1441
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1442
+ lastToken.raw += '\n' + token.raw;
1443
+ lastToken.text += '\n' + token.text;
1444
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1445
+ }
1446
+ else {
1447
+ tokens.push(token);
1448
+ }
1449
+ continue;
1450
+ }
1451
+ // fences
1452
+ if (token = this.tokenizer.fences(src)) {
1453
+ src = src.substring(token.raw.length);
1454
+ tokens.push(token);
1455
+ continue;
1456
+ }
1457
+ // heading
1458
+ if (token = this.tokenizer.heading(src)) {
1459
+ src = src.substring(token.raw.length);
1460
+ tokens.push(token);
1461
+ continue;
1462
+ }
1463
+ // hr
1464
+ if (token = this.tokenizer.hr(src)) {
1465
+ src = src.substring(token.raw.length);
1466
+ tokens.push(token);
1467
+ continue;
1468
+ }
1469
+ // blockquote
1470
+ if (token = this.tokenizer.blockquote(src)) {
1471
+ src = src.substring(token.raw.length);
1472
+ tokens.push(token);
1473
+ continue;
1474
+ }
1475
+ // list
1476
+ if (token = this.tokenizer.list(src)) {
1477
+ src = src.substring(token.raw.length);
1478
+ tokens.push(token);
1479
+ continue;
1480
+ }
1481
+ // html
1482
+ if (token = this.tokenizer.html(src)) {
1483
+ src = src.substring(token.raw.length);
1484
+ tokens.push(token);
1485
+ continue;
1486
+ }
1487
+ // def
1488
+ if (token = this.tokenizer.def(src)) {
1489
+ src = src.substring(token.raw.length);
1490
+ lastToken = tokens[tokens.length - 1];
1491
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1492
+ lastToken.raw += '\n' + token.raw;
1493
+ lastToken.text += '\n' + token.raw;
1494
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1495
+ }
1496
+ else if (!this.tokens.links[token.tag]) {
1497
+ this.tokens.links[token.tag] = {
1498
+ href: token.href,
1499
+ title: token.title
1500
+ };
1501
+ }
1502
+ continue;
1503
+ }
1504
+ // table (gfm)
1505
+ if (token = this.tokenizer.table(src)) {
1506
+ src = src.substring(token.raw.length);
1507
+ tokens.push(token);
1508
+ continue;
1509
+ }
1510
+ // lheading
1511
+ if (token = this.tokenizer.lheading(src)) {
1512
+ src = src.substring(token.raw.length);
1513
+ tokens.push(token);
1514
+ continue;
1515
+ }
1516
+ // top-level paragraph
1517
+ // prevent paragraph consuming extensions by clipping 'src' to extension start
1518
+ cutSrc = src;
1519
+ if (this.options.extensions && this.options.extensions.startBlock) {
1520
+ let startIndex = Infinity;
1521
+ const tempSrc = src.slice(1);
1522
+ let tempStart;
1523
+ this.options.extensions.startBlock.forEach((getStartIndex) => {
1524
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1525
+ if (typeof tempStart === 'number' && tempStart >= 0) {
1526
+ startIndex = Math.min(startIndex, tempStart);
1527
+ }
1528
+ });
1529
+ if (startIndex < Infinity && startIndex >= 0) {
1530
+ cutSrc = src.substring(0, startIndex + 1);
1531
+ }
1532
+ }
1533
+ if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1534
+ lastToken = tokens[tokens.length - 1];
1535
+ if (lastParagraphClipped && lastToken.type === 'paragraph') {
1536
+ lastToken.raw += '\n' + token.raw;
1537
+ lastToken.text += '\n' + token.text;
1538
+ this.inlineQueue.pop();
1539
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1540
+ }
1541
+ else {
1542
+ tokens.push(token);
1543
+ }
1544
+ lastParagraphClipped = (cutSrc.length !== src.length);
1545
+ src = src.substring(token.raw.length);
1546
+ continue;
1547
+ }
1548
+ // text
1549
+ if (token = this.tokenizer.text(src)) {
1550
+ src = src.substring(token.raw.length);
1551
+ lastToken = tokens[tokens.length - 1];
1552
+ if (lastToken && lastToken.type === 'text') {
1553
+ lastToken.raw += '\n' + token.raw;
1554
+ lastToken.text += '\n' + token.text;
1555
+ this.inlineQueue.pop();
1556
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1557
+ }
1558
+ else {
1559
+ tokens.push(token);
1560
+ }
1561
+ continue;
1562
+ }
1563
+ if (src) {
1564
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1565
+ if (this.options.silent) {
1566
+ console.error(errMsg);
1567
+ break;
1568
+ }
1569
+ else {
1570
+ throw new Error(errMsg);
1571
+ }
1572
+ }
1573
+ }
1574
+ this.state.top = true;
1575
+ return tokens;
1576
+ }
1577
+ inline(src, tokens = []) {
1578
+ this.inlineQueue.push({ src, tokens });
1579
+ return tokens;
1580
+ }
1581
+ /**
1582
+ * Lexing/Compiling
1583
+ */
1584
+ inlineTokens(src, tokens = []) {
1585
+ let token, lastToken, cutSrc;
1586
+ // String with links masked to avoid interference with em and strong
1587
+ let maskedSrc = src;
1588
+ let match;
1589
+ let keepPrevChar, prevChar;
1590
+ // Mask out reflinks
1591
+ if (this.tokens.links) {
1592
+ const links = Object.keys(this.tokens.links);
1593
+ if (links.length > 0) {
1594
+ while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1595
+ if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
1596
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1597
+ }
1598
+ }
1599
+ }
1600
+ }
1601
+ // Mask out other blocks
1602
+ while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1603
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1604
+ }
1605
+ // Mask out escaped characters
1606
+ while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
1607
+ maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
1608
+ }
1609
+ while (src) {
1610
+ if (!keepPrevChar) {
1611
+ prevChar = '';
1612
+ }
1613
+ keepPrevChar = false;
1614
+ // extensions
1615
+ if (this.options.extensions
1616
+ && this.options.extensions.inline
1617
+ && this.options.extensions.inline.some((extTokenizer) => {
1618
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1619
+ src = src.substring(token.raw.length);
1620
+ tokens.push(token);
1621
+ return true;
1622
+ }
1623
+ return false;
1624
+ })) {
1625
+ continue;
1626
+ }
1627
+ // escape
1628
+ if (token = this.tokenizer.escape(src)) {
1629
+ src = src.substring(token.raw.length);
1630
+ tokens.push(token);
1631
+ continue;
1632
+ }
1633
+ // tag
1634
+ if (token = this.tokenizer.tag(src)) {
1635
+ src = src.substring(token.raw.length);
1636
+ lastToken = tokens[tokens.length - 1];
1637
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1638
+ lastToken.raw += token.raw;
1639
+ lastToken.text += token.text;
1640
+ }
1641
+ else {
1642
+ tokens.push(token);
1643
+ }
1644
+ continue;
1645
+ }
1646
+ // link
1647
+ if (token = this.tokenizer.link(src)) {
1648
+ src = src.substring(token.raw.length);
1649
+ tokens.push(token);
1650
+ continue;
1651
+ }
1652
+ // reflink, nolink
1653
+ if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1654
+ src = src.substring(token.raw.length);
1655
+ lastToken = tokens[tokens.length - 1];
1656
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1657
+ lastToken.raw += token.raw;
1658
+ lastToken.text += token.text;
1659
+ }
1660
+ else {
1661
+ tokens.push(token);
1662
+ }
1663
+ continue;
1664
+ }
1665
+ // em & strong
1666
+ if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1667
+ src = src.substring(token.raw.length);
1668
+ tokens.push(token);
1669
+ continue;
1670
+ }
1671
+ // code
1672
+ if (token = this.tokenizer.codespan(src)) {
1673
+ src = src.substring(token.raw.length);
1674
+ tokens.push(token);
1675
+ continue;
1676
+ }
1677
+ // br
1678
+ if (token = this.tokenizer.br(src)) {
1679
+ src = src.substring(token.raw.length);
1680
+ tokens.push(token);
1681
+ continue;
1682
+ }
1683
+ // del (gfm)
1684
+ if (token = this.tokenizer.del(src)) {
1685
+ src = src.substring(token.raw.length);
1686
+ tokens.push(token);
1687
+ continue;
1688
+ }
1689
+ // autolink
1690
+ if (token = this.tokenizer.autolink(src, mangle)) {
1691
+ src = src.substring(token.raw.length);
1692
+ tokens.push(token);
1693
+ continue;
1694
+ }
1695
+ // url (gfm)
1696
+ if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
1697
+ src = src.substring(token.raw.length);
1698
+ tokens.push(token);
1699
+ continue;
1700
+ }
1701
+ // text
1702
+ // prevent inlineText consuming extensions by clipping 'src' to extension start
1703
+ cutSrc = src;
1704
+ if (this.options.extensions && this.options.extensions.startInline) {
1705
+ let startIndex = Infinity;
1706
+ const tempSrc = src.slice(1);
1707
+ let tempStart;
1708
+ this.options.extensions.startInline.forEach((getStartIndex) => {
1709
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1710
+ if (typeof tempStart === 'number' && tempStart >= 0) {
1711
+ startIndex = Math.min(startIndex, tempStart);
1712
+ }
1713
+ });
1714
+ if (startIndex < Infinity && startIndex >= 0) {
1715
+ cutSrc = src.substring(0, startIndex + 1);
1716
+ }
1717
+ }
1718
+ if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
1719
+ src = src.substring(token.raw.length);
1720
+ if (token.raw.slice(-1) !== '_') { // Track prevChar before string of ____ started
1721
+ prevChar = token.raw.slice(-1);
1722
+ }
1723
+ keepPrevChar = true;
1724
+ lastToken = tokens[tokens.length - 1];
1725
+ if (lastToken && lastToken.type === 'text') {
1726
+ lastToken.raw += token.raw;
1727
+ lastToken.text += token.text;
1728
+ }
1729
+ else {
1730
+ tokens.push(token);
1731
+ }
1732
+ continue;
1733
+ }
1734
+ if (src) {
1735
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1736
+ if (this.options.silent) {
1737
+ console.error(errMsg);
1738
+ break;
1739
+ }
1740
+ else {
1741
+ throw new Error(errMsg);
1742
+ }
1743
+ }
1744
+ }
1745
+ return tokens;
1746
+ }
1747
+ }
1575
1748
 
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
- };
1749
+ /**
1750
+ * Renderer
1751
+ */
1752
+ class _Renderer {
1753
+ options;
1754
+ constructor(options) {
1755
+ this.options = options || _defaults;
1756
+ }
1757
+ code(code, infostring, escaped) {
1758
+ const lang = (infostring || '').match(/\S*/)[0];
1759
+ if (this.options.highlight) {
1760
+ const out = this.options.highlight(code, lang);
1761
+ if (out != null && out !== code) {
1762
+ escaped = true;
1763
+ code = out;
1764
+ }
1765
+ }
1766
+ code = code.replace(/\n$/, '') + '\n';
1767
+ if (!lang) {
1768
+ return '<pre><code>'
1769
+ + (escaped ? code : escape(code, true))
1770
+ + '</code></pre>\n';
1771
+ }
1772
+ return '<pre><code class="'
1773
+ + this.options.langPrefix
1774
+ + escape(lang)
1775
+ + '">'
1776
+ + (escaped ? code : escape(code, true))
1777
+ + '</code></pre>\n';
1778
+ }
1779
+ blockquote(quote) {
1780
+ return `<blockquote>\n${quote}</blockquote>\n`;
1781
+ }
1782
+ html(html, block) {
1783
+ return html;
1784
+ }
1785
+ heading(text, level, raw, slugger) {
1786
+ if (this.options.headerIds) {
1787
+ const id = this.options.headerPrefix + slugger.slug(raw);
1788
+ return `<h${level} id="${id}">${text}</h${level}>\n`;
1789
+ }
1790
+ // ignore IDs
1791
+ return `<h${level}>${text}</h${level}>\n`;
1792
+ }
1793
+ hr() {
1794
+ return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
1795
+ }
1796
+ list(body, ordered, start) {
1797
+ const type = ordered ? 'ol' : 'ul', startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
1798
+ return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1799
+ }
1800
+ listitem(text, task, checked) {
1801
+ return `<li>${text}</li>\n`;
1802
+ }
1803
+ checkbox(checked) {
1804
+ return '<input '
1805
+ + (checked ? 'checked="" ' : '')
1806
+ + 'disabled="" type="checkbox"'
1807
+ + (this.options.xhtml ? ' /' : '')
1808
+ + '> ';
1809
+ }
1810
+ paragraph(text) {
1811
+ return `<p>${text}</p>\n`;
1812
+ }
1813
+ table(header, body) {
1814
+ if (body)
1815
+ body = `<tbody>${body}</tbody>`;
1816
+ return '<table>\n'
1817
+ + '<thead>\n'
1818
+ + header
1819
+ + '</thead>\n'
1820
+ + body
1821
+ + '</table>\n';
1822
+ }
1823
+ tablerow(content) {
1824
+ return `<tr>\n${content}</tr>\n`;
1825
+ }
1826
+ tablecell(content, flags) {
1827
+ const type = flags.header ? 'th' : 'td';
1828
+ const tag = flags.align
1829
+ ? `<${type} align="${flags.align}">`
1830
+ : `<${type}>`;
1831
+ return tag + content + `</${type}>\n`;
1832
+ }
1833
+ /**
1834
+ * span level renderer
1835
+ */
1836
+ strong(text) {
1837
+ return `<strong>${text}</strong>`;
1838
+ }
1839
+ em(text) {
1840
+ return `<em>${text}</em>`;
1841
+ }
1842
+ codespan(text) {
1843
+ return `<code>${text}</code>`;
1844
+ }
1845
+ br() {
1846
+ return this.options.xhtml ? '<br/>' : '<br>';
1847
+ }
1848
+ del(text) {
1849
+ return `<del>${text}</del>`;
1850
+ }
1851
+ link(href, title, text) {
1852
+ href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1853
+ if (href === null) {
1854
+ return text;
1855
+ }
1856
+ let out = '<a href="' + href + '"';
1857
+ if (title) {
1858
+ out += ' title="' + title + '"';
1859
+ }
1860
+ out += '>' + text + '</a>';
1861
+ return out;
1862
+ }
1863
+ image(href, title, text) {
1864
+ href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1865
+ if (href === null) {
1866
+ return text;
1867
+ }
1868
+ let out = `<img src="${href}" alt="${text}"`;
1869
+ if (title) {
1870
+ out += ` title="${title}"`;
1871
+ }
1872
+ out += this.options.xhtml ? '/>' : '>';
1873
+ return out;
1874
+ }
1875
+ text(text) {
1876
+ return text;
1877
+ }
1878
+ }
1611
1879
 
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
- }
1880
+ /**
1881
+ * TextRenderer
1882
+ * returns only the textual part of the token
1883
+ */
1884
+ class _TextRenderer {
1885
+ // no need for block level renderers
1886
+ strong(text) {
1887
+ return text;
1771
1888
  }
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
- }
1889
+ em(text) {
1890
+ return text;
1841
1891
  }
1842
- return out;
1843
- }
1844
- };
1892
+ codespan(text) {
1893
+ return text;
1894
+ }
1895
+ del(text) {
1896
+ return text;
1897
+ }
1898
+ html(text) {
1899
+ return text;
1900
+ }
1901
+ text(text) {
1902
+ return text;
1903
+ }
1904
+ link(href, title, text) {
1905
+ return '' + text;
1906
+ }
1907
+ image(href, title, text) {
1908
+ return '' + text;
1909
+ }
1910
+ br() {
1911
+ return '';
1912
+ }
1913
+ }
1845
1914
 
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
- ]);
1915
+ /**
1916
+ * Slugger generates header id
1917
+ */
1918
+ class _Slugger {
1919
+ seen;
1920
+ constructor() {
1921
+ this.seen = {};
1922
+ }
1923
+ serialize(value) {
1924
+ return value
1925
+ .toLowerCase()
1926
+ .trim()
1927
+ // remove html tags
1928
+ .replace(/<[!\/a-z].*?>/ig, '')
1929
+ // remove unwanted chars
1930
+ .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
1931
+ .replace(/\s/g, '-');
1932
+ }
1933
+ /**
1934
+ * Finds the next safe (unique) slug to use
1935
+ */
1936
+ getNextSafeSlug(originalSlug, isDryRun) {
1937
+ let slug = originalSlug;
1938
+ let occurenceAccumulator = 0;
1939
+ if (this.seen.hasOwnProperty(slug)) {
1940
+ occurenceAccumulator = this.seen[originalSlug];
1941
+ do {
1942
+ occurenceAccumulator++;
1943
+ slug = originalSlug + '-' + occurenceAccumulator;
1944
+ } while (this.seen.hasOwnProperty(slug));
1945
+ }
1946
+ if (!isDryRun) {
1947
+ this.seen[originalSlug] = occurenceAccumulator;
1948
+ this.seen[slug] = 0;
1949
+ }
1950
+ return slug;
1951
+ }
1952
+ /**
1953
+ * Convert string to unique id
1954
+ */
1955
+ slug(value, options = {}) {
1956
+ const slug = this.serialize(value);
1957
+ return this.getNextSafeSlug(slug, options.dryrun);
1958
+ }
1959
+ }
1868
1960
 
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;
1961
+ /**
1962
+ * Parsing & Compiling
1963
+ */
1964
+ class _Parser {
1965
+ options;
1966
+ renderer;
1967
+ textRenderer;
1968
+ slugger;
1969
+ constructor(options) {
1970
+ this.options = options || _defaults;
1971
+ this.options.renderer = this.options.renderer || new _Renderer();
1972
+ this.renderer = this.options.renderer;
1973
+ this.renderer.options = this.options;
1974
+ this.textRenderer = new _TextRenderer();
1975
+ this.slugger = new _Slugger();
1976
+ }
1977
+ /**
1978
+ * Static Parse Method
1979
+ */
1980
+ static parse(tokens, options) {
1981
+ const parser = new _Parser(options);
1982
+ return parser.parse(tokens);
1983
+ }
1984
+ /**
1985
+ * Static Parse Inline Method
1986
+ */
1987
+ static parseInline(tokens, options) {
1988
+ const parser = new _Parser(options);
1989
+ return parser.parseInline(tokens);
1990
+ }
1991
+ /**
1992
+ * Parse Loop
1993
+ */
1994
+ parse(tokens, top = true) {
1995
+ let out = '', i, j, k, l2, l3, row, cell, header, body, token, ordered, start, loose, itemBody, item, checked, task, checkbox, ret;
1996
+ const l = tokens.length;
1997
+ for (i = 0; i < l; i++) {
1998
+ token = tokens[i];
1999
+ // Run any renderer extensions
2000
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2001
+ ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
2002
+ if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(token.type)) {
2003
+ out += ret || '';
2004
+ continue;
2005
+ }
2006
+ }
2007
+ switch (token.type) {
2008
+ case 'space': {
2009
+ continue;
2010
+ }
2011
+ case 'hr': {
2012
+ out += this.renderer.hr();
2013
+ continue;
2014
+ }
2015
+ case 'heading': {
2016
+ out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
2017
+ continue;
2018
+ }
2019
+ case 'code': {
2020
+ out += this.renderer.code(token.text, token.lang, !!token.escaped);
2021
+ continue;
2022
+ }
2023
+ case 'table': {
2024
+ header = '';
2025
+ // header
2026
+ cell = '';
2027
+ l2 = token.header.length;
2028
+ for (j = 0; j < l2; j++) {
2029
+ cell += this.renderer.tablecell(this.parseInline(token.header[j].tokens), { header: true, align: token.align[j] });
2030
+ }
2031
+ header += this.renderer.tablerow(cell);
2032
+ body = '';
2033
+ l2 = token.rows.length;
2034
+ for (j = 0; j < l2; j++) {
2035
+ row = token.rows[j];
2036
+ cell = '';
2037
+ l3 = row.length;
2038
+ for (k = 0; k < l3; k++) {
2039
+ cell += this.renderer.tablecell(this.parseInline(row[k].tokens), { header: false, align: token.align[k] });
2040
+ }
2041
+ body += this.renderer.tablerow(cell);
2042
+ }
2043
+ out += this.renderer.table(header, body);
2044
+ continue;
2045
+ }
2046
+ case 'blockquote': {
2047
+ body = this.parse(token.tokens);
2048
+ out += this.renderer.blockquote(body);
2049
+ continue;
2050
+ }
2051
+ case 'list': {
2052
+ ordered = token.ordered;
2053
+ start = token.start;
2054
+ loose = token.loose;
2055
+ l2 = token.items.length;
2056
+ body = '';
2057
+ for (j = 0; j < l2; j++) {
2058
+ item = token.items[j];
2059
+ checked = item.checked;
2060
+ task = item.task;
2061
+ itemBody = '';
2062
+ if (item.task) {
2063
+ checkbox = this.renderer.checkbox(!!checked);
2064
+ if (loose) {
2065
+ if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
2066
+ item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
2067
+ if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
2068
+ item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
2069
+ }
2070
+ }
2071
+ else {
2072
+ item.tokens.unshift({
2073
+ type: 'text',
2074
+ text: checkbox
2075
+ });
2076
+ }
2077
+ }
2078
+ else {
2079
+ itemBody += checkbox;
2080
+ }
2081
+ }
2082
+ itemBody += this.parse(item.tokens, loose);
2083
+ body += this.renderer.listitem(itemBody, task, !!checked);
2084
+ }
2085
+ out += this.renderer.list(body, ordered, start);
2086
+ continue;
2087
+ }
2088
+ case 'html': {
2089
+ out += this.renderer.html(token.text, token.block);
2090
+ continue;
2091
+ }
2092
+ case 'paragraph': {
2093
+ out += this.renderer.paragraph(this.parseInline(token.tokens));
2094
+ continue;
2095
+ }
2096
+ case 'text': {
2097
+ body = token.tokens ? this.parseInline(token.tokens) : token.text;
2098
+ while (i + 1 < l && tokens[i + 1].type === 'text') {
2099
+ token = tokens[++i];
2100
+ body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
2101
+ }
2102
+ out += top ? this.renderer.paragraph(body) : body;
2103
+ continue;
2104
+ }
2105
+ default: {
2106
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
2107
+ if (this.options.silent) {
2108
+ console.error(errMsg);
2109
+ return '';
2110
+ }
2111
+ else {
2112
+ throw new Error(errMsg);
2113
+ }
2114
+ }
2115
+ }
2116
+ }
2117
+ return out;
2074
2118
  }
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);
2119
+ /**
2120
+ * Parse Inline Tokens
2121
+ */
2122
+ parseInline(tokens, renderer) {
2123
+ renderer = renderer || this.renderer;
2124
+ let out = '', i, token, ret;
2125
+ const l = tokens.length;
2126
+ for (i = 0; i < l; i++) {
2127
+ token = tokens[i];
2128
+ // Run any renderer extensions
2129
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
2130
+ ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
2131
+ if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
2132
+ out += ret || '';
2133
+ continue;
2134
+ }
2135
+ }
2136
+ switch (token.type) {
2137
+ case 'escape': {
2138
+ out += renderer.text(token.text);
2139
+ break;
2140
+ }
2141
+ case 'html': {
2142
+ out += renderer.html(token.text);
2143
+ break;
2144
+ }
2145
+ case 'link': {
2146
+ out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
2147
+ break;
2148
+ }
2149
+ case 'image': {
2150
+ out += renderer.image(token.href, token.title, token.text);
2151
+ break;
2152
+ }
2153
+ case 'strong': {
2154
+ out += renderer.strong(this.parseInline(token.tokens, renderer));
2155
+ break;
2156
+ }
2157
+ case 'em': {
2158
+ out += renderer.em(this.parseInline(token.tokens, renderer));
2159
+ break;
2160
+ }
2161
+ case 'codespan': {
2162
+ out += renderer.codespan(token.text);
2163
+ break;
2164
+ }
2165
+ case 'br': {
2166
+ out += renderer.br();
2167
+ break;
2168
+ }
2169
+ case 'del': {
2170
+ out += renderer.del(this.parseInline(token.tokens, renderer));
2171
+ break;
2172
+ }
2173
+ case 'text': {
2174
+ out += renderer.text(token.text);
2175
+ break;
2176
+ }
2177
+ default: {
2178
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
2179
+ if (this.options.silent) {
2180
+ console.error(errMsg);
2181
+ return '';
2182
+ }
2183
+ else {
2184
+ throw new Error(errMsg);
2185
+ }
2186
+ }
2187
+ }
2129
2188
  }
2130
- });
2131
- if (pending === 0) {
2132
- done();
2133
- }
2134
- return;
2189
+ return out;
2135
2190
  }
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);
2191
+ }
2192
+
2193
+ class _Hooks {
2194
+ options;
2195
+ constructor(options) {
2196
+ this.options = options || _defaults;
2197
+ }
2198
+ static passThroughHooks = new Set([
2199
+ 'preprocess',
2200
+ 'postprocess'
2201
+ ]);
2202
+ /**
2203
+ * Process markdown before marked
2204
+ */
2205
+ preprocess(markdown) {
2206
+ return markdown;
2207
+ }
2208
+ /**
2209
+ * Process HTML after marked is finished
2210
+ */
2211
+ postprocess(html) {
2212
+ return html;
2138
2213
  }
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;
2214
+ }
2215
+
2216
+ class Marked {
2217
+ defaults = _getDefaults();
2218
+ options = this.setOptions;
2219
+ parse = this.#parseMarkdown(_Lexer.lex, _Parser.parse);
2220
+ parseInline = this.#parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
2221
+ Parser = _Parser;
2222
+ parser = _Parser.parse;
2223
+ Renderer = _Renderer;
2224
+ TextRenderer = _TextRenderer;
2225
+ Lexer = _Lexer;
2226
+ lexer = _Lexer.lex;
2227
+ Tokenizer = _Tokenizer;
2228
+ Slugger = _Slugger;
2229
+ Hooks = _Hooks;
2230
+ constructor(...args) {
2231
+ this.use(...args);
2232
+ }
2233
+ /**
2234
+ * Run callback for every token
2235
+ */
2236
+ walkTokens(tokens, callback) {
2237
+ let values = [];
2238
+ for (const token of tokens) {
2239
+ values = values.concat(callback.call(this, token));
2240
+ switch (token.type) {
2241
+ case 'table': {
2242
+ for (const cell of token.header) {
2243
+ values = values.concat(this.walkTokens(cell.tokens, callback));
2244
+ }
2245
+ for (const row of token.rows) {
2246
+ for (const cell of row) {
2247
+ values = values.concat(this.walkTokens(cell.tokens, callback));
2248
+ }
2249
+ }
2250
+ break;
2251
+ }
2252
+ case 'list': {
2253
+ values = values.concat(this.walkTokens(token.items, callback));
2254
+ break;
2255
+ }
2256
+ default: {
2257
+ if (this.defaults.extensions && this.defaults.extensions.childTokens && this.defaults.extensions.childTokens[token.type]) { // Walk any extensions
2258
+ this.defaults.extensions.childTokens[token.type].forEach((childTokens) => {
2259
+ values = values.concat(this.walkTokens(token[childTokens], callback));
2260
+ });
2261
+ }
2262
+ else if (token.tokens) {
2263
+ values = values.concat(this.walkTokens(token.tokens, callback));
2264
+ }
2265
+ }
2266
+ }
2267
+ }
2268
+ return values;
2269
+ }
2270
+ use(...args) {
2271
+ const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
2272
+ args.forEach((pack) => {
2273
+ // copy options to new object
2274
+ const opts = { ...pack };
2275
+ // set async to true if it was set to true before
2276
+ opts.async = this.defaults.async || opts.async || false;
2277
+ // ==-- Parse "addon" extensions --== //
2278
+ if (pack.extensions) {
2279
+ pack.extensions.forEach((ext) => {
2280
+ if (!ext.name) {
2281
+ throw new Error('extension name required');
2282
+ }
2283
+ if ('renderer' in ext) { // Renderer extensions
2284
+ const prevRenderer = extensions.renderers[ext.name];
2285
+ if (prevRenderer) {
2286
+ // Replace extension with func to run new extension but fall back if false
2287
+ extensions.renderers[ext.name] = function (...args) {
2288
+ let ret = ext.renderer.apply(this, args);
2289
+ if (ret === false) {
2290
+ ret = prevRenderer.apply(this, args);
2291
+ }
2292
+ return ret;
2293
+ };
2294
+ }
2295
+ else {
2296
+ extensions.renderers[ext.name] = ext.renderer;
2297
+ }
2298
+ }
2299
+ if ('tokenizer' in ext) { // Tokenizer Extensions
2300
+ if (!ext.level || (ext.level !== 'block' && ext.level !== 'inline')) {
2301
+ throw new Error("extension level must be 'block' or 'inline'");
2302
+ }
2303
+ if (extensions[ext.level]) {
2304
+ extensions[ext.level].unshift(ext.tokenizer);
2305
+ }
2306
+ else {
2307
+ extensions[ext.level] = [ext.tokenizer];
2308
+ }
2309
+ if (ext.start) { // Function to check for start of token
2310
+ if (ext.level === 'block') {
2311
+ if (extensions.startBlock) {
2312
+ extensions.startBlock.push(ext.start);
2313
+ }
2314
+ else {
2315
+ extensions.startBlock = [ext.start];
2316
+ }
2317
+ }
2318
+ else if (ext.level === 'inline') {
2319
+ if (extensions.startInline) {
2320
+ extensions.startInline.push(ext.start);
2321
+ }
2322
+ else {
2323
+ extensions.startInline = [ext.start];
2324
+ }
2325
+ }
2326
+ }
2327
+ }
2328
+ if ('childTokens' in ext && ext.childTokens) { // Child tokens to be visited by walkTokens
2329
+ extensions.childTokens[ext.name] = ext.childTokens;
2330
+ }
2331
+ });
2332
+ opts.extensions = extensions;
2333
+ }
2334
+ // ==-- Parse "overwrite" extensions --== //
2335
+ if (pack.renderer) {
2336
+ const renderer = this.defaults.renderer || new _Renderer(this.defaults);
2337
+ for (const prop in pack.renderer) {
2338
+ const prevRenderer = renderer[prop];
2339
+ // Replace renderer with func to run extension, but fall back if false
2340
+ renderer[prop] = (...args) => {
2341
+ let ret = pack.renderer[prop].apply(renderer, args);
2342
+ if (ret === false) {
2343
+ ret = prevRenderer.apply(renderer, args);
2344
+ }
2345
+ return ret;
2346
+ };
2347
+ }
2348
+ opts.renderer = renderer;
2349
+ }
2350
+ if (pack.tokenizer) {
2351
+ const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
2352
+ for (const prop in pack.tokenizer) {
2353
+ const prevTokenizer = tokenizer[prop];
2354
+ // Replace tokenizer with func to run extension, but fall back if false
2355
+ tokenizer[prop] = (...args) => {
2356
+ let ret = pack.tokenizer[prop].apply(tokenizer, args);
2357
+ if (ret === false) {
2358
+ ret = prevTokenizer.apply(tokenizer, args);
2359
+ }
2360
+ return ret;
2361
+ };
2362
+ }
2363
+ opts.tokenizer = tokenizer;
2364
+ }
2365
+ // ==-- Parse Hooks extensions --== //
2366
+ if (pack.hooks) {
2367
+ const hooks = this.defaults.hooks || new _Hooks();
2368
+ for (const prop in pack.hooks) {
2369
+ const prevHook = hooks[prop];
2370
+ if (_Hooks.passThroughHooks.has(prop)) {
2371
+ hooks[prop] = (arg) => {
2372
+ if (this.defaults.async) {
2373
+ return Promise.resolve(pack.hooks[prop].call(hooks, arg)).then(ret => {
2374
+ return prevHook.call(hooks, ret);
2375
+ });
2376
+ }
2377
+ const ret = pack.hooks[prop].call(hooks, arg);
2378
+ return prevHook.call(hooks, ret);
2379
+ };
2380
+ }
2381
+ else {
2382
+ hooks[prop] = (...args) => {
2383
+ let ret = pack.hooks[prop].apply(hooks, args);
2384
+ if (ret === false) {
2385
+ ret = prevHook.apply(hooks, args);
2386
+ }
2387
+ return ret;
2388
+ };
2389
+ }
2390
+ }
2391
+ opts.hooks = hooks;
2392
+ }
2393
+ // ==-- Parse WalkTokens extensions --== //
2394
+ if (pack.walkTokens) {
2395
+ const walkTokens = this.defaults.walkTokens;
2396
+ opts.walkTokens = function (token) {
2397
+ let values = [];
2398
+ values.push(pack.walkTokens.call(this, token));
2399
+ if (walkTokens) {
2400
+ values = values.concat(walkTokens.call(this, token));
2401
+ }
2402
+ return values;
2403
+ };
2404
+ }
2405
+ this.defaults = { ...this.defaults, ...opts };
2406
+ });
2407
+ return this;
2171
2408
  }
2172
- if (async) {
2173
- return Promise.reject(e);
2409
+ setOptions(opt) {
2410
+ this.defaults = { ...this.defaults, ...opt };
2411
+ return this;
2174
2412
  }
2175
- if (callback) {
2176
- callback(e);
2177
- return;
2413
+ #parseMarkdown(lexer, parser) {
2414
+ return (src, optOrCallback, callback) => {
2415
+ if (typeof optOrCallback === 'function') {
2416
+ callback = optOrCallback;
2417
+ optOrCallback = null;
2418
+ }
2419
+ const origOpt = { ...optOrCallback };
2420
+ const opt = { ...this.defaults, ...origOpt };
2421
+ const throwError = this.#onError(!!opt.silent, !!opt.async, callback);
2422
+ // throw error in case of non string input
2423
+ if (typeof src === 'undefined' || src === null) {
2424
+ return throwError(new Error('marked(): input parameter is undefined or null'));
2425
+ }
2426
+ if (typeof src !== 'string') {
2427
+ return throwError(new Error('marked(): input parameter is of type '
2428
+ + Object.prototype.toString.call(src) + ', string expected'));
2429
+ }
2430
+ checkDeprecations(opt, callback);
2431
+ if (opt.hooks) {
2432
+ opt.hooks.options = opt;
2433
+ }
2434
+ if (callback) {
2435
+ const highlight = opt.highlight;
2436
+ let tokens;
2437
+ try {
2438
+ if (opt.hooks) {
2439
+ src = opt.hooks.preprocess(src);
2440
+ }
2441
+ tokens = lexer(src, opt);
2442
+ }
2443
+ catch (e) {
2444
+ return throwError(e);
2445
+ }
2446
+ const done = (err) => {
2447
+ let out;
2448
+ if (!err) {
2449
+ try {
2450
+ if (opt.walkTokens) {
2451
+ this.walkTokens(tokens, opt.walkTokens);
2452
+ }
2453
+ out = parser(tokens, opt);
2454
+ if (opt.hooks) {
2455
+ out = opt.hooks.postprocess(out);
2456
+ }
2457
+ }
2458
+ catch (e) {
2459
+ err = e;
2460
+ }
2461
+ }
2462
+ opt.highlight = highlight;
2463
+ return err
2464
+ ? throwError(err)
2465
+ : callback(null, out);
2466
+ };
2467
+ if (!highlight || highlight.length < 3) {
2468
+ return done();
2469
+ }
2470
+ delete opt.highlight;
2471
+ if (!tokens.length)
2472
+ return done();
2473
+ let pending = 0;
2474
+ this.walkTokens(tokens, (token) => {
2475
+ if (token.type === 'code') {
2476
+ pending++;
2477
+ setTimeout(() => {
2478
+ highlight(token.text, token.lang, (err, code) => {
2479
+ if (err) {
2480
+ return done(err);
2481
+ }
2482
+ if (code != null && code !== token.text) {
2483
+ token.text = code;
2484
+ token.escaped = true;
2485
+ }
2486
+ pending--;
2487
+ if (pending === 0) {
2488
+ done();
2489
+ }
2490
+ });
2491
+ }, 0);
2492
+ }
2493
+ });
2494
+ if (pending === 0) {
2495
+ done();
2496
+ }
2497
+ return;
2498
+ }
2499
+ if (opt.async) {
2500
+ return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2501
+ .then(src => lexer(src, opt))
2502
+ .then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens)
2503
+ .then(tokens => parser(tokens, opt))
2504
+ .then(html => opt.hooks ? opt.hooks.postprocess(html) : html)
2505
+ .catch(throwError);
2506
+ }
2507
+ try {
2508
+ if (opt.hooks) {
2509
+ src = opt.hooks.preprocess(src);
2510
+ }
2511
+ const tokens = lexer(src, opt);
2512
+ if (opt.walkTokens) {
2513
+ this.walkTokens(tokens, opt.walkTokens);
2514
+ }
2515
+ let html = parser(tokens, opt);
2516
+ if (opt.hooks) {
2517
+ html = opt.hooks.postprocess(html);
2518
+ }
2519
+ return html;
2520
+ }
2521
+ catch (e) {
2522
+ return throwError(e);
2523
+ }
2524
+ };
2178
2525
  }
2179
- throw e;
2180
- };
2181
- };
2526
+ #onError(silent, async, callback) {
2527
+ return (e) => {
2528
+ e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2529
+ if (silent) {
2530
+ const msg = '<p>An error occurred:</p><pre>'
2531
+ + escape(e.message + '', true)
2532
+ + '</pre>';
2533
+ if (async) {
2534
+ return Promise.resolve(msg);
2535
+ }
2536
+ if (callback) {
2537
+ callback(null, msg);
2538
+ return;
2539
+ }
2540
+ return msg;
2541
+ }
2542
+ if (async) {
2543
+ return Promise.reject(e);
2544
+ }
2545
+ if (callback) {
2546
+ callback(e);
2547
+ return;
2548
+ }
2549
+ throw e;
2550
+ };
2551
+ }
2552
+ }
2182
2553
 
2183
- // src/marked.ts
2184
- var markedInstance = new Marked();
2554
+ const markedInstance = new Marked();
2185
2555
  function marked(src, opt, callback) {
2186
- return markedInstance.parse(src, opt, callback);
2556
+ return markedInstance.parse(src, opt, callback);
2187
2557
  }
2188
- marked.options = marked.setOptions = function(options2) {
2189
- markedInstance.setOptions(options2);
2190
- marked.defaults = markedInstance.defaults;
2191
- changeDefaults(marked.defaults);
2192
- return marked;
2193
- };
2558
+ /**
2559
+ * Sets the default options.
2560
+ *
2561
+ * @param options Hash of options
2562
+ */
2563
+ marked.options =
2564
+ marked.setOptions = function (options) {
2565
+ markedInstance.setOptions(options);
2566
+ marked.defaults = markedInstance.defaults;
2567
+ changeDefaults(marked.defaults);
2568
+ return marked;
2569
+ };
2570
+ /**
2571
+ * Gets the original marked default options.
2572
+ */
2194
2573
  marked.getDefaults = _getDefaults;
2195
2574
  marked.defaults = _defaults;
2196
- marked.use = function(...args) {
2197
- markedInstance.use(...args);
2198
- marked.defaults = markedInstance.defaults;
2199
- changeDefaults(marked.defaults);
2200
- return marked;
2575
+ /**
2576
+ * Use Extension
2577
+ */
2578
+ marked.use = function (...args) {
2579
+ markedInstance.use(...args);
2580
+ marked.defaults = markedInstance.defaults;
2581
+ changeDefaults(marked.defaults);
2582
+ return marked;
2201
2583
  };
2202
- marked.walkTokens = function(tokens, callback) {
2203
- return markedInstance.walkTokens(tokens, callback);
2584
+ /**
2585
+ * Run callback for every token
2586
+ */
2587
+ marked.walkTokens = function (tokens, callback) {
2588
+ return markedInstance.walkTokens(tokens, callback);
2204
2589
  };
2590
+ /**
2591
+ * Compiles markdown to HTML without enclosing `p` tag.
2592
+ *
2593
+ * @param src String of markdown source to be compiled
2594
+ * @param options Hash of options
2595
+ * @return String of compiled HTML
2596
+ */
2205
2597
  marked.parseInline = markedInstance.parseInline;
2598
+ /**
2599
+ * Expose
2600
+ */
2206
2601
  marked.Parser = _Parser;
2207
2602
  marked.parser = _Parser.parse;
2208
2603
  marked.Renderer = _Renderer;
2209
2604
  marked.TextRenderer = _TextRenderer;
2210
- marked.Lexer = _Lexer2;
2211
- marked.lexer = _Lexer2.lex;
2605
+ marked.Lexer = _Lexer;
2606
+ marked.lexer = _Lexer.lex;
2212
2607
  marked.Tokenizer = _Tokenizer;
2213
2608
  marked.Slugger = _Slugger;
2214
2609
  marked.Hooks = _Hooks;
2215
2610
  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
2611
+ const options = marked.options;
2612
+ const setOptions = marked.setOptions;
2613
+ const use = marked.use;
2614
+ const walkTokens = marked.walkTokens;
2615
+ const parseInline = marked.parseInline;
2616
+ const parse = marked;
2617
+ const parser = _Parser.parse;
2618
+ const lexer = _Lexer.lex;
2619
+
2620
+ 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 };
2621
+ //# sourceMappingURL=marked.esm.js.map