marked 7.0.0 → 7.0.2

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