@knapsack/plugin-changelog-md 4.69.5 → 4.69.6--canary.de6a636.0

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