@subiz/widget-v4 4.0.75 → 4.0.77

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