marked 7.0.0 → 7.0.1

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