@vaadin/bundles 24.8.0-alpha8 → 25.0.0-alpha1

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