@subiz/widget-v4 4.1.39 → 4.1.41

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