@subiz/widget-v4 4.1.42 → 4.1.44

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