@vaadin/bundles 24.8.0-alpha2 → 24.8.0-alpha20

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