marked 0.7.0 → 1.0.0

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.
package/lib/marked.js CHANGED
@@ -1,1704 +1,2344 @@
1
1
  /**
2
2
  * marked - a markdown parser
3
- * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed)
3
+ * Copyright (c) 2011-2020, Christopher Jeffrey. (MIT Licensed)
4
4
  * https://github.com/markedjs/marked
5
5
  */
6
6
 
7
- ;(function(root) {
8
- 'use strict';
9
-
10
7
  /**
11
- * Block-Level Grammar
8
+ * DO NOT EDIT THIS FILE
9
+ * The code in this file is generated from files in ./src/
12
10
  */
13
11
 
14
- var block = {
15
- newline: /^\n+/,
16
- code: /^( {4}[^\n]+\n*)+/,
17
- fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
18
- hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
19
- heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
20
- blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
21
- list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
22
- html: '^ {0,3}(?:' // optional indentation
23
- + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
24
- + '|comment[^\\n]*(\\n+|$)' // (2)
25
- + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
26
- + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
27
- + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
28
- + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
29
- + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
30
- + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
31
- + ')',
32
- def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
33
- nptable: noop,
34
- table: noop,
35
- lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
36
- // regex template, placeholders will be replaced according to different paragraph
37
- // interruption rules of commonmark and the original markdown spec:
38
- _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
39
- text: /^[^\n]+/
40
- };
41
-
42
- block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
43
- block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
44
- block.def = edit(block.def)
45
- .replace('label', block._label)
46
- .replace('title', block._title)
47
- .getRegex();
12
+ (function (global, factory) {
13
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
14
+ typeof define === 'function' && define.amd ? define(factory) :
15
+ (global = global || self, global.marked = factory());
16
+ }(this, (function () { 'use strict';
17
+
18
+ function _defineProperties(target, props) {
19
+ for (var i = 0; i < props.length; i++) {
20
+ var descriptor = props[i];
21
+ descriptor.enumerable = descriptor.enumerable || false;
22
+ descriptor.configurable = true;
23
+ if ("value" in descriptor) descriptor.writable = true;
24
+ Object.defineProperty(target, descriptor.key, descriptor);
25
+ }
26
+ }
48
27
 
49
- block.bullet = /(?:[*+-]|\d{1,9}\.)/;
50
- block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
51
- block.item = edit(block.item, 'gm')
52
- .replace(/bull/g, block.bullet)
53
- .getRegex();
28
+ function _createClass(Constructor, protoProps, staticProps) {
29
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
30
+ if (staticProps) _defineProperties(Constructor, staticProps);
31
+ return Constructor;
32
+ }
54
33
 
55
- block.list = edit(block.list)
56
- .replace(/bull/g, block.bullet)
57
- .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
58
- .replace('def', '\\n+(?=' + block.def.source + ')')
59
- .getRegex();
34
+ function createCommonjsModule(fn, module) {
35
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
36
+ }
60
37
 
61
- block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
62
- + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
63
- + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
64
- + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
65
- + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
66
- + '|track|ul';
67
- block._comment = /<!--(?!-?>)[\s\S]*?-->/;
68
- block.html = edit(block.html, 'i')
69
- .replace('comment', block._comment)
70
- .replace('tag', block._tag)
71
- .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
72
- .getRegex();
38
+ var defaults = createCommonjsModule(function (module) {
39
+ function getDefaults() {
40
+ return {
41
+ baseUrl: null,
42
+ breaks: false,
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
+ xhtml: false
58
+ };
59
+ }
73
60
 
74
- block.paragraph = edit(block._paragraph)
75
- .replace('hr', block.hr)
76
- .replace('heading', ' {0,3}#{1,6} +')
77
- .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
78
- .replace('blockquote', ' {0,3}>')
79
- .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n')
80
- .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
81
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)')
82
- .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
83
- .getRegex();
61
+ function changeDefaults(newDefaults) {
62
+ module.exports.defaults = newDefaults;
63
+ }
84
64
 
85
- block.blockquote = edit(block.blockquote)
86
- .replace('paragraph', block.paragraph)
87
- .getRegex();
65
+ module.exports = {
66
+ defaults: getDefaults(),
67
+ getDefaults: getDefaults,
68
+ changeDefaults: changeDefaults
69
+ };
70
+ });
71
+ var defaults_1 = defaults.defaults;
72
+ var defaults_2 = defaults.getDefaults;
73
+ var defaults_3 = defaults.changeDefaults;
74
+
75
+ /**
76
+ * Helpers
77
+ */
78
+ var escapeTest = /[&<>"']/;
79
+ var escapeReplace = /[&<>"']/g;
80
+ var escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
81
+ var escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
82
+ var escapeReplacements = {
83
+ '&': '&amp;',
84
+ '<': '&lt;',
85
+ '>': '&gt;',
86
+ '"': '&quot;',
87
+ "'": '&#39;'
88
+ };
88
89
 
89
- /**
90
- * Normal Block Grammar
91
- */
90
+ var getEscapeReplacement = function getEscapeReplacement(ch) {
91
+ return escapeReplacements[ch];
92
+ };
92
93
 
93
- block.normal = merge({}, block);
94
+ function escape(html, encode) {
95
+ if (encode) {
96
+ if (escapeTest.test(html)) {
97
+ return html.replace(escapeReplace, getEscapeReplacement);
98
+ }
99
+ } else {
100
+ if (escapeTestNoEncode.test(html)) {
101
+ return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
102
+ }
103
+ }
94
104
 
95
- /**
96
- * GFM Block Grammar
97
- */
105
+ return html;
106
+ }
98
107
 
99
- block.gfm = merge({}, block.normal, {
100
- nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,
101
- table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/
102
- });
108
+ var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
103
109
 
104
- /**
105
- * Pedantic grammar (original John Gruber's loose markdown specification)
106
- */
110
+ function unescape(html) {
111
+ // explicitly match decimal, hex, and named HTML entities
112
+ return html.replace(unescapeTest, function (_, n) {
113
+ n = n.toLowerCase();
114
+ if (n === 'colon') return ':';
107
115
 
108
- block.pedantic = merge({}, block.normal, {
109
- html: edit(
110
- '^ *(?:comment *(?:\\n|\\s*$)'
111
- + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
112
- + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
113
- .replace('comment', block._comment)
114
- .replace(/tag/g, '(?!(?:'
115
- + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
116
- + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
117
- + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
118
- .getRegex(),
119
- def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
120
- heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
121
- fences: noop, // fences not supported
122
- paragraph: edit(block.normal._paragraph)
123
- .replace('hr', block.hr)
124
- .replace('heading', ' *#{1,6} *[^\n]')
125
- .replace('lheading', block.lheading)
126
- .replace('blockquote', ' {0,3}>')
127
- .replace('|fences', '')
128
- .replace('|list', '')
129
- .replace('|html', '')
130
- .getRegex()
131
- });
116
+ if (n.charAt(0) === '#') {
117
+ return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
118
+ }
132
119
 
133
- /**
134
- * Block Lexer
135
- */
120
+ return '';
121
+ });
122
+ }
123
+
124
+ var caret = /(^|[^\[])\^/g;
125
+
126
+ function edit(regex, opt) {
127
+ regex = regex.source || regex;
128
+ opt = opt || '';
129
+ var obj = {
130
+ replace: function replace(name, val) {
131
+ val = val.source || val;
132
+ val = val.replace(caret, '$1');
133
+ regex = regex.replace(name, val);
134
+ return obj;
135
+ },
136
+ getRegex: function getRegex() {
137
+ return new RegExp(regex, opt);
138
+ }
139
+ };
140
+ return obj;
141
+ }
142
+
143
+ var nonWordAndColonTest = /[^\w:]/g;
144
+ var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
136
145
 
137
- function Lexer(options) {
138
- this.tokens = [];
139
- this.tokens.links = Object.create(null);
140
- this.options = options || marked.defaults;
141
- this.rules = block.normal;
146
+ function cleanUrl(sanitize, base, href) {
147
+ if (sanitize) {
148
+ var prot;
142
149
 
143
- if (this.options.pedantic) {
144
- this.rules = block.pedantic;
145
- } else if (this.options.gfm) {
146
- this.rules = block.gfm;
150
+ try {
151
+ prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, '').toLowerCase();
152
+ } catch (e) {
153
+ return null;
154
+ }
155
+
156
+ if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
157
+ return null;
158
+ }
159
+ }
160
+
161
+ if (base && !originIndependentUrl.test(href)) {
162
+ href = resolveUrl(base, href);
163
+ }
164
+
165
+ try {
166
+ href = encodeURI(href).replace(/%25/g, '%');
167
+ } catch (e) {
168
+ return null;
169
+ }
170
+
171
+ return href;
147
172
  }
148
- }
149
173
 
150
- /**
151
- * Expose Block Rules
152
- */
174
+ var baseUrls = {};
175
+ var justDomain = /^[^:]+:\/*[^/]*$/;
176
+ var protocol = /^([^:]+:)[\s\S]*$/;
177
+ var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
178
+
179
+ function resolveUrl(base, href) {
180
+ if (!baseUrls[' ' + base]) {
181
+ // we can ignore everything in base after the last slash of its path component,
182
+ // but we might need to add _that_
183
+ // https://tools.ietf.org/html/rfc3986#section-3
184
+ if (justDomain.test(base)) {
185
+ baseUrls[' ' + base] = base + '/';
186
+ } else {
187
+ baseUrls[' ' + base] = rtrim(base, '/', true);
188
+ }
189
+ }
153
190
 
154
- Lexer.rules = block;
191
+ base = baseUrls[' ' + base];
192
+ var relativeBase = base.indexOf(':') === -1;
155
193
 
156
- /**
157
- * Static Lex Method
158
- */
194
+ if (href.substring(0, 2) === '//') {
195
+ if (relativeBase) {
196
+ return href;
197
+ }
159
198
 
160
- Lexer.lex = function(src, options) {
161
- var lexer = new Lexer(options);
162
- return lexer.lex(src);
163
- };
199
+ return base.replace(protocol, '$1') + href;
200
+ } else if (href.charAt(0) === '/') {
201
+ if (relativeBase) {
202
+ return href;
203
+ }
164
204
 
165
- /**
166
- * Preprocessing
167
- */
205
+ return base.replace(domain, '$1') + href;
206
+ } else {
207
+ return base + href;
208
+ }
209
+ }
168
210
 
169
- Lexer.prototype.lex = function(src) {
170
- src = src
171
- .replace(/\r\n|\r/g, '\n')
172
- .replace(/\t/g, ' ')
173
- .replace(/\u00a0/g, ' ')
174
- .replace(/\u2424/g, '\n');
211
+ var noopTest = {
212
+ exec: function noopTest() {}
213
+ };
175
214
 
176
- return this.token(src, true);
177
- };
215
+ function merge(obj) {
216
+ var i = 1,
217
+ target,
218
+ key;
178
219
 
179
- /**
180
- * Lexing
181
- */
220
+ for (; i < arguments.length; i++) {
221
+ target = arguments[i];
182
222
 
183
- Lexer.prototype.token = function(src, top) {
184
- src = src.replace(/^ +$/gm, '');
185
- var next,
186
- loose,
187
- cap,
188
- bull,
189
- b,
190
- item,
191
- listStart,
192
- listItems,
193
- t,
194
- space,
195
- i,
196
- tag,
197
- l,
198
- isordered,
199
- istask,
200
- ischecked;
201
-
202
- while (src) {
203
- // newline
204
- if (cap = this.rules.newline.exec(src)) {
205
- src = src.substring(cap[0].length);
206
- if (cap[0].length > 1) {
207
- this.tokens.push({
208
- type: 'space'
209
- });
223
+ for (key in target) {
224
+ if (Object.prototype.hasOwnProperty.call(target, key)) {
225
+ obj[key] = target[key];
226
+ }
210
227
  }
211
228
  }
212
229
 
213
- // code
214
- if (cap = this.rules.code.exec(src)) {
215
- var lastToken = this.tokens[this.tokens.length - 1];
216
- src = src.substring(cap[0].length);
217
- // An indented code block cannot interrupt a paragraph.
218
- if (lastToken && lastToken.type === 'paragraph') {
219
- lastToken.text += '\n' + cap[0].trimRight();
230
+ return obj;
231
+ }
232
+
233
+ function splitCells(tableRow, count) {
234
+ // ensure that every cell-delimiting pipe has a space
235
+ // before it to distinguish it from an escaped pipe
236
+ var row = tableRow.replace(/\|/g, function (match, offset, str) {
237
+ var escaped = false,
238
+ curr = offset;
239
+
240
+ while (--curr >= 0 && str[curr] === '\\') {
241
+ escaped = !escaped;
242
+ }
243
+
244
+ if (escaped) {
245
+ // odd number of slashes means | is escaped
246
+ // so we leave it alone
247
+ return '|';
220
248
  } else {
221
- cap = cap[0].replace(/^ {4}/gm, '');
222
- this.tokens.push({
223
- type: 'code',
224
- codeBlockStyle: 'indented',
225
- text: !this.options.pedantic
226
- ? rtrim(cap, '\n')
227
- : cap
228
- });
249
+ // add space before unescaped |
250
+ return ' |';
229
251
  }
230
- continue;
231
- }
252
+ }),
253
+ cells = row.split(/ \|/);
254
+ var i = 0;
232
255
 
233
- // fences
234
- if (cap = this.rules.fences.exec(src)) {
235
- src = src.substring(cap[0].length);
236
- this.tokens.push({
237
- type: 'code',
238
- lang: cap[2] ? cap[2].trim() : cap[2],
239
- text: cap[3] || ''
240
- });
241
- continue;
256
+ if (cells.length > count) {
257
+ cells.splice(count);
258
+ } else {
259
+ while (cells.length < count) {
260
+ cells.push('');
261
+ }
242
262
  }
243
263
 
244
- // heading
245
- if (cap = this.rules.heading.exec(src)) {
246
- src = src.substring(cap[0].length);
247
- this.tokens.push({
248
- type: 'heading',
249
- depth: cap[1].length,
250
- text: cap[2]
251
- });
252
- continue;
264
+ for (; i < cells.length; i++) {
265
+ // leading or trailing whitespace is ignored per the gfm spec
266
+ cells[i] = cells[i].trim().replace(/\\\|/g, '|');
253
267
  }
254
268
 
255
- // table no leading pipe (gfm)
256
- if (cap = this.rules.nptable.exec(src)) {
257
- item = {
258
- type: 'table',
259
- header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
260
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
261
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
262
- };
269
+ return cells;
270
+ } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
271
+ // /c*$/ is vulnerable to REDOS.
272
+ // invert: Remove suffix of non-c chars instead. Default falsey.
263
273
 
264
- if (item.header.length === item.align.length) {
265
- src = src.substring(cap[0].length);
266
274
 
267
- for (i = 0; i < item.align.length; i++) {
268
- if (/^ *-+: *$/.test(item.align[i])) {
269
- item.align[i] = 'right';
270
- } else if (/^ *:-+: *$/.test(item.align[i])) {
271
- item.align[i] = 'center';
272
- } else if (/^ *:-+ *$/.test(item.align[i])) {
273
- item.align[i] = 'left';
274
- } else {
275
- item.align[i] = null;
276
- }
277
- }
275
+ function rtrim(str, c, invert) {
276
+ var l = str.length;
278
277
 
279
- for (i = 0; i < item.cells.length; i++) {
280
- item.cells[i] = splitCells(item.cells[i], item.header.length);
281
- }
278
+ if (l === 0) {
279
+ return '';
280
+ } // Length of suffix matching the invert condition.
282
281
 
283
- this.tokens.push(item);
284
282
 
285
- continue;
283
+ var suffLen = 0; // Step left until we fail to match the invert condition.
284
+
285
+ while (suffLen < l) {
286
+ var currChar = str.charAt(l - suffLen - 1);
287
+
288
+ if (currChar === c && !invert) {
289
+ suffLen++;
290
+ } else if (currChar !== c && invert) {
291
+ suffLen++;
292
+ } else {
293
+ break;
286
294
  }
287
295
  }
288
296
 
289
- // hr
290
- if (cap = this.rules.hr.exec(src)) {
291
- src = src.substring(cap[0].length);
292
- this.tokens.push({
293
- type: 'hr'
294
- });
295
- continue;
296
- }
297
+ return str.substr(0, l - suffLen);
298
+ }
297
299
 
298
- // blockquote
299
- if (cap = this.rules.blockquote.exec(src)) {
300
- src = src.substring(cap[0].length);
300
+ function findClosingBracket(str, b) {
301
+ if (str.indexOf(b[1]) === -1) {
302
+ return -1;
303
+ }
301
304
 
302
- this.tokens.push({
303
- type: 'blockquote_start'
304
- });
305
+ var l = str.length;
306
+ var level = 0,
307
+ i = 0;
305
308
 
306
- cap = cap[0].replace(/^ *> ?/gm, '');
309
+ for (; i < l; i++) {
310
+ if (str[i] === '\\') {
311
+ i++;
312
+ } else if (str[i] === b[0]) {
313
+ level++;
314
+ } else if (str[i] === b[1]) {
315
+ level--;
307
316
 
308
- // Pass `top` to keep the current
309
- // "toplevel" state. This is exactly
310
- // how markdown.pl works.
311
- this.token(cap, top);
317
+ if (level < 0) {
318
+ return i;
319
+ }
320
+ }
321
+ }
312
322
 
313
- this.tokens.push({
314
- type: 'blockquote_end'
315
- });
323
+ return -1;
324
+ }
316
325
 
317
- continue;
326
+ function checkSanitizeDeprecation(opt) {
327
+ if (opt && opt.sanitize && !opt.silent) {
328
+ 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');
318
329
  }
330
+ }
331
+
332
+ var helpers = {
333
+ escape: escape,
334
+ unescape: unescape,
335
+ edit: edit,
336
+ cleanUrl: cleanUrl,
337
+ resolveUrl: resolveUrl,
338
+ noopTest: noopTest,
339
+ merge: merge,
340
+ splitCells: splitCells,
341
+ rtrim: rtrim,
342
+ findClosingBracket: findClosingBracket,
343
+ checkSanitizeDeprecation: checkSanitizeDeprecation
344
+ };
319
345
 
320
- // list
321
- if (cap = this.rules.list.exec(src)) {
322
- src = src.substring(cap[0].length);
323
- bull = cap[2];
324
- isordered = bull.length > 1;
325
-
326
- listStart = {
327
- type: 'list_start',
328
- ordered: isordered,
329
- start: isordered ? +bull : '',
330
- loose: false
346
+ var defaults$1 = defaults.defaults;
347
+ var rtrim$1 = helpers.rtrim,
348
+ splitCells$1 = helpers.splitCells,
349
+ _escape = helpers.escape,
350
+ findClosingBracket$1 = helpers.findClosingBracket;
351
+
352
+ function outputLink(cap, link, raw) {
353
+ var href = link.href;
354
+ var title = link.title ? _escape(link.title) : null;
355
+
356
+ if (cap[0].charAt(0) !== '!') {
357
+ return {
358
+ type: 'link',
359
+ raw: raw,
360
+ href: href,
361
+ title: title,
362
+ text: cap[1]
363
+ };
364
+ } else {
365
+ return {
366
+ type: 'image',
367
+ raw: raw,
368
+ text: _escape(cap[1]),
369
+ href: href,
370
+ title: title
331
371
  };
372
+ }
373
+ }
374
+ /**
375
+ * Tokenizer
376
+ */
377
+
378
+
379
+ var Tokenizer_1 = /*#__PURE__*/function () {
380
+ function Tokenizer(options) {
381
+ this.options = options || defaults$1;
382
+ }
383
+
384
+ var _proto = Tokenizer.prototype;
332
385
 
333
- this.tokens.push(listStart);
386
+ _proto.space = function space(src) {
387
+ var cap = this.rules.block.newline.exec(src);
334
388
 
335
- // Get each top-level item.
336
- cap = cap[0].match(this.rules.item);
389
+ if (cap) {
390
+ if (cap[0].length > 1) {
391
+ return {
392
+ type: 'space',
393
+ raw: cap[0]
394
+ };
395
+ }
337
396
 
338
- listItems = [];
339
- next = false;
340
- l = cap.length;
341
- i = 0;
397
+ return {
398
+ raw: '\n'
399
+ };
400
+ }
401
+ };
342
402
 
343
- for (; i < l; i++) {
344
- item = cap[i];
403
+ _proto.code = function code(src, tokens) {
404
+ var cap = this.rules.block.code.exec(src);
345
405
 
346
- // Remove the list item's bullet
347
- // so it is seen as the next token.
348
- space = item.length;
349
- item = item.replace(/^ *([*+-]|\d+\.) */, '');
406
+ if (cap) {
407
+ var lastToken = tokens[tokens.length - 1]; // An indented code block cannot interrupt a paragraph.
350
408
 
351
- // Outdent whatever the
352
- // list item contains. Hacky.
353
- if (~item.indexOf('\n ')) {
354
- space -= item.length;
355
- item = !this.options.pedantic
356
- ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
357
- : item.replace(/^ {1,4}/gm, '');
409
+ if (lastToken && lastToken.type === 'paragraph') {
410
+ tokens.pop();
411
+ lastToken.text += '\n' + cap[0].trimRight();
412
+ lastToken.raw += '\n' + cap[0];
413
+ return lastToken;
414
+ } else {
415
+ var text = cap[0].replace(/^ {4}/gm, '');
416
+ return {
417
+ type: 'code',
418
+ raw: cap[0],
419
+ codeBlockStyle: 'indented',
420
+ text: !this.options.pedantic ? rtrim$1(text, '\n') : text
421
+ };
358
422
  }
423
+ }
424
+ };
425
+
426
+ _proto.fences = function fences(src) {
427
+ var cap = this.rules.block.fences.exec(src);
428
+
429
+ if (cap) {
430
+ return {
431
+ type: 'code',
432
+ raw: cap[0],
433
+ lang: cap[2] ? cap[2].trim() : cap[2],
434
+ text: cap[3] || ''
435
+ };
436
+ }
437
+ };
438
+
439
+ _proto.heading = function heading(src) {
440
+ var cap = this.rules.block.heading.exec(src);
441
+
442
+ if (cap) {
443
+ return {
444
+ type: 'heading',
445
+ raw: cap[0],
446
+ depth: cap[1].length,
447
+ text: cap[2]
448
+ };
449
+ }
450
+ };
451
+
452
+ _proto.nptable = function nptable(src) {
453
+ var cap = this.rules.block.nptable.exec(src);
454
+
455
+ if (cap) {
456
+ var item = {
457
+ type: 'table',
458
+ header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
459
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
460
+ cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
461
+ raw: cap[0]
462
+ };
463
+
464
+ if (item.header.length === item.align.length) {
465
+ var l = item.align.length;
466
+ var i;
467
+
468
+ for (i = 0; i < l; i++) {
469
+ if (/^ *-+: *$/.test(item.align[i])) {
470
+ item.align[i] = 'right';
471
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
472
+ item.align[i] = 'center';
473
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
474
+ item.align[i] = 'left';
475
+ } else {
476
+ item.align[i] = null;
477
+ }
478
+ }
479
+
480
+ l = item.cells.length;
359
481
 
360
- // Determine whether the next list item belongs here.
361
- // Backpedal if it does not belong in this list.
362
- if (i !== l - 1) {
363
- b = block.bullet.exec(cap[i + 1])[0];
364
- if (bull.length > 1 ? b.length === 1
365
- : (b.length > 1 || (this.options.smartLists && b !== bull))) {
366
- src = cap.slice(i + 1).join('\n') + src;
367
- i = l - 1;
482
+ for (i = 0; i < l; i++) {
483
+ item.cells[i] = splitCells$1(item.cells[i], item.header.length);
368
484
  }
485
+
486
+ return item;
369
487
  }
488
+ }
489
+ };
490
+
491
+ _proto.hr = function hr(src) {
492
+ var cap = this.rules.block.hr.exec(src);
493
+
494
+ if (cap) {
495
+ return {
496
+ type: 'hr',
497
+ raw: cap[0]
498
+ };
499
+ }
500
+ };
501
+
502
+ _proto.blockquote = function blockquote(src) {
503
+ var cap = this.rules.block.blockquote.exec(src);
504
+
505
+ if (cap) {
506
+ var text = cap[0].replace(/^ *> ?/gm, '');
507
+ return {
508
+ type: 'blockquote',
509
+ raw: cap[0],
510
+ text: text
511
+ };
512
+ }
513
+ };
514
+
515
+ _proto.list = function list(src) {
516
+ var cap = this.rules.block.list.exec(src);
517
+
518
+ if (cap) {
519
+ var raw = cap[0];
520
+ var bull = cap[2];
521
+ var isordered = bull.length > 1;
522
+ var list = {
523
+ type: 'list',
524
+ raw: raw,
525
+ ordered: isordered,
526
+ start: isordered ? +bull : '',
527
+ loose: false,
528
+ items: []
529
+ }; // Get each top-level item.
530
+
531
+ var itemMatch = cap[0].match(this.rules.block.item);
532
+ var next = false,
533
+ item,
534
+ space,
535
+ b,
536
+ addBack,
537
+ loose,
538
+ istask,
539
+ ischecked;
540
+ var l = itemMatch.length;
541
+
542
+ for (var i = 0; i < l; i++) {
543
+ item = itemMatch[i];
544
+ raw = item; // Remove the list item's bullet
545
+ // so it is seen as the next token.
546
+
547
+ space = item.length;
548
+ item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the
549
+ // list item contains. Hacky.
550
+
551
+ if (~item.indexOf('\n ')) {
552
+ space -= item.length;
553
+ item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
554
+ } // Determine whether the next list item belongs here.
555
+ // Backpedal if it does not belong in this list.
556
+
557
+
558
+ if (i !== l - 1) {
559
+ b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
560
+
561
+ if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) {
562
+ addBack = itemMatch.slice(i + 1).join('\n');
563
+ list.raw = list.raw.substring(0, list.raw.length - addBack.length);
564
+ i = l - 1;
565
+ }
566
+ } // Determine whether item is loose or not.
567
+ // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
568
+ // for discount behavior.
569
+
570
+
571
+ loose = next || /\n\n(?!\s*$)/.test(item);
572
+
573
+ if (i !== l - 1) {
574
+ next = item.charAt(item.length - 1) === '\n';
575
+ if (!loose) loose = next;
576
+ }
577
+
578
+ if (loose) {
579
+ list.loose = true;
580
+ } // Check for task list items
581
+
582
+
583
+ istask = /^\[[ xX]\] /.test(item);
584
+ ischecked = undefined;
370
585
 
371
- // Determine whether item is loose or not.
372
- // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
373
- // for discount behavior.
374
- loose = next || /\n\n(?!\s*$)/.test(item);
375
- if (i !== l - 1) {
376
- next = item.charAt(item.length - 1) === '\n';
377
- if (!loose) loose = next;
586
+ if (istask) {
587
+ ischecked = item[1] !== ' ';
588
+ item = item.replace(/^\[[ xX]\] +/, '');
589
+ }
590
+
591
+ list.items.push({
592
+ raw: raw,
593
+ task: istask,
594
+ checked: ischecked,
595
+ loose: loose,
596
+ text: item
597
+ });
378
598
  }
379
599
 
380
- if (loose) {
381
- listStart.loose = true;
600
+ return list;
601
+ }
602
+ };
603
+
604
+ _proto.html = function html(src) {
605
+ var cap = this.rules.block.html.exec(src);
606
+
607
+ if (cap) {
608
+ return {
609
+ type: this.options.sanitize ? 'paragraph' : 'html',
610
+ raw: cap[0],
611
+ pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
612
+ text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
613
+ };
614
+ }
615
+ };
616
+
617
+ _proto.def = function def(src) {
618
+ var cap = this.rules.block.def.exec(src);
619
+
620
+ if (cap) {
621
+ if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
622
+ var tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
623
+ return {
624
+ tag: tag,
625
+ raw: cap[0],
626
+ href: cap[2],
627
+ title: cap[3]
628
+ };
629
+ }
630
+ };
631
+
632
+ _proto.table = function table(src) {
633
+ var cap = this.rules.block.table.exec(src);
634
+
635
+ if (cap) {
636
+ var item = {
637
+ type: 'table',
638
+ header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
639
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
640
+ cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
641
+ };
642
+
643
+ if (item.header.length === item.align.length) {
644
+ item.raw = cap[0];
645
+ var l = item.align.length;
646
+ var i;
647
+
648
+ for (i = 0; i < l; i++) {
649
+ if (/^ *-+: *$/.test(item.align[i])) {
650
+ item.align[i] = 'right';
651
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
652
+ item.align[i] = 'center';
653
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
654
+ item.align[i] = 'left';
655
+ } else {
656
+ item.align[i] = null;
657
+ }
658
+ }
659
+
660
+ l = item.cells.length;
661
+
662
+ for (i = 0; i < l; i++) {
663
+ item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
664
+ }
665
+
666
+ return item;
667
+ }
668
+ }
669
+ };
670
+
671
+ _proto.lheading = function lheading(src) {
672
+ var cap = this.rules.block.lheading.exec(src);
673
+
674
+ if (cap) {
675
+ return {
676
+ type: 'heading',
677
+ raw: cap[0],
678
+ depth: cap[2].charAt(0) === '=' ? 1 : 2,
679
+ text: cap[1]
680
+ };
681
+ }
682
+ };
683
+
684
+ _proto.paragraph = function paragraph(src) {
685
+ var cap = this.rules.block.paragraph.exec(src);
686
+
687
+ if (cap) {
688
+ return {
689
+ type: 'paragraph',
690
+ raw: cap[0],
691
+ text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
692
+ };
693
+ }
694
+ };
695
+
696
+ _proto.text = function text(src) {
697
+ var cap = this.rules.block.text.exec(src);
698
+
699
+ if (cap) {
700
+ return {
701
+ type: 'text',
702
+ raw: cap[0],
703
+ text: cap[0]
704
+ };
705
+ }
706
+ };
707
+
708
+ _proto.escape = function escape(src) {
709
+ var cap = this.rules.inline.escape.exec(src);
710
+
711
+ if (cap) {
712
+ return {
713
+ type: 'escape',
714
+ raw: cap[0],
715
+ text: _escape(cap[1])
716
+ };
717
+ }
718
+ };
719
+
720
+ _proto.tag = function tag(src, inLink, inRawBlock) {
721
+ var cap = this.rules.inline.tag.exec(src);
722
+
723
+ if (cap) {
724
+ if (!inLink && /^<a /i.test(cap[0])) {
725
+ inLink = true;
726
+ } else if (inLink && /^<\/a>/i.test(cap[0])) {
727
+ inLink = false;
382
728
  }
383
729
 
384
- // Check for task list items
385
- istask = /^\[[ xX]\] /.test(item);
386
- ischecked = undefined;
387
- if (istask) {
388
- ischecked = item[1] !== ' ';
389
- item = item.replace(/^\[[ xX]\] +/, '');
730
+ if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
731
+ inRawBlock = true;
732
+ } else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
733
+ inRawBlock = false;
390
734
  }
391
735
 
392
- t = {
393
- type: 'list_item_start',
394
- task: istask,
395
- checked: ischecked,
396
- loose: loose
736
+ return {
737
+ type: this.options.sanitize ? 'text' : 'html',
738
+ raw: cap[0],
739
+ inLink: inLink,
740
+ inRawBlock: inRawBlock,
741
+ text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
397
742
  };
743
+ }
744
+ };
745
+
746
+ _proto.link = function link(src) {
747
+ var cap = this.rules.inline.link.exec(src);
398
748
 
399
- listItems.push(t);
400
- this.tokens.push(t);
749
+ if (cap) {
750
+ var lastParenIndex = findClosingBracket$1(cap[2], '()');
401
751
 
402
- // Recurse.
403
- this.token(item, false);
752
+ if (lastParenIndex > -1) {
753
+ var start = cap[0].indexOf('!') === 0 ? 5 : 4;
754
+ var linkLen = start + cap[1].length + lastParenIndex;
755
+ cap[2] = cap[2].substring(0, lastParenIndex);
756
+ cap[0] = cap[0].substring(0, linkLen).trim();
757
+ cap[3] = '';
758
+ }
759
+
760
+ var href = cap[2];
761
+ var title = '';
762
+
763
+ if (this.options.pedantic) {
764
+ var link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
765
+
766
+ if (link) {
767
+ href = link[1];
768
+ title = link[3];
769
+ } else {
770
+ title = '';
771
+ }
772
+ } else {
773
+ title = cap[3] ? cap[3].slice(1, -1) : '';
774
+ }
404
775
 
405
- this.tokens.push({
406
- type: 'list_item_end'
407
- });
776
+ href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
777
+ var token = outputLink(cap, {
778
+ href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
779
+ title: title ? title.replace(this.rules.inline._escapes, '$1') : title
780
+ }, cap[0]);
781
+ return token;
408
782
  }
783
+ };
409
784
 
410
- if (listStart.loose) {
411
- l = listItems.length;
412
- i = 0;
413
- for (; i < l; i++) {
414
- listItems[i].loose = true;
785
+ _proto.reflink = function reflink(src, links) {
786
+ var cap;
787
+
788
+ if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
789
+ var link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
790
+ link = links[link.toLowerCase()];
791
+
792
+ if (!link || !link.href) {
793
+ var text = cap[0].charAt(0);
794
+ return {
795
+ type: 'text',
796
+ raw: text,
797
+ text: text
798
+ };
415
799
  }
800
+
801
+ var token = outputLink(cap, link, cap[0]);
802
+ return token;
416
803
  }
804
+ };
417
805
 
418
- this.tokens.push({
419
- type: 'list_end'
420
- });
806
+ _proto.strong = function strong(src) {
807
+ var cap = this.rules.inline.strong.exec(src);
421
808
 
422
- continue;
423
- }
809
+ if (cap) {
810
+ return {
811
+ type: 'strong',
812
+ raw: cap[0],
813
+ text: cap[4] || cap[3] || cap[2] || cap[1]
814
+ };
815
+ }
816
+ };
424
817
 
425
- // html
426
- if (cap = this.rules.html.exec(src)) {
427
- src = src.substring(cap[0].length);
428
- this.tokens.push({
429
- type: this.options.sanitize
430
- ? 'paragraph'
431
- : 'html',
432
- pre: !this.options.sanitizer
433
- && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
434
- text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0]
435
- });
436
- continue;
437
- }
818
+ _proto.em = function em(src) {
819
+ var cap = this.rules.inline.em.exec(src);
438
820
 
439
- // def
440
- if (top && (cap = this.rules.def.exec(src))) {
441
- src = src.substring(cap[0].length);
442
- if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
443
- tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
444
- if (!this.tokens.links[tag]) {
445
- this.tokens.links[tag] = {
446
- href: cap[2],
447
- title: cap[3]
821
+ if (cap) {
822
+ return {
823
+ type: 'em',
824
+ raw: cap[0],
825
+ text: cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]
448
826
  };
449
827
  }
450
- continue;
451
- }
828
+ };
452
829
 
453
- // table (gfm)
454
- if (cap = this.rules.table.exec(src)) {
455
- item = {
456
- type: 'table',
457
- header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
458
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
459
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
460
- };
830
+ _proto.codespan = function codespan(src) {
831
+ var cap = this.rules.inline.code.exec(src);
461
832
 
462
- if (item.header.length === item.align.length) {
463
- src = src.substring(cap[0].length);
833
+ if (cap) {
834
+ return {
835
+ type: 'codespan',
836
+ raw: cap[0],
837
+ text: _escape(cap[2].trim(), true)
838
+ };
839
+ }
840
+ };
841
+
842
+ _proto.br = function br(src) {
843
+ var cap = this.rules.inline.br.exec(src);
844
+
845
+ if (cap) {
846
+ return {
847
+ type: 'br',
848
+ raw: cap[0]
849
+ };
850
+ }
851
+ };
852
+
853
+ _proto.del = function del(src) {
854
+ var cap = this.rules.inline.del.exec(src);
855
+
856
+ if (cap) {
857
+ return {
858
+ type: 'del',
859
+ raw: cap[0],
860
+ text: cap[1]
861
+ };
862
+ }
863
+ };
864
+
865
+ _proto.autolink = function autolink(src, mangle) {
866
+ var cap = this.rules.inline.autolink.exec(src);
867
+
868
+ if (cap) {
869
+ var text, href;
870
+
871
+ if (cap[2] === '@') {
872
+ text = _escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
873
+ href = 'mailto:' + text;
874
+ } else {
875
+ text = _escape(cap[1]);
876
+ href = text;
877
+ }
878
+
879
+ return {
880
+ type: 'link',
881
+ raw: cap[0],
882
+ text: text,
883
+ href: href,
884
+ tokens: [{
885
+ type: 'text',
886
+ raw: text,
887
+ text: text
888
+ }]
889
+ };
890
+ }
891
+ };
892
+
893
+ _proto.url = function url(src, mangle) {
894
+ var cap;
464
895
 
465
- for (i = 0; i < item.align.length; i++) {
466
- if (/^ *-+: *$/.test(item.align[i])) {
467
- item.align[i] = 'right';
468
- } else if (/^ *:-+: *$/.test(item.align[i])) {
469
- item.align[i] = 'center';
470
- } else if (/^ *:-+ *$/.test(item.align[i])) {
471
- item.align[i] = 'left';
896
+ if (cap = this.rules.inline.url.exec(src)) {
897
+ var text, href;
898
+
899
+ if (cap[2] === '@') {
900
+ text = _escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
901
+ href = 'mailto:' + text;
902
+ } else {
903
+ // do extended autolink path validation
904
+ var prevCapZero;
905
+
906
+ do {
907
+ prevCapZero = cap[0];
908
+ cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
909
+ } while (prevCapZero !== cap[0]);
910
+
911
+ text = _escape(cap[0]);
912
+
913
+ if (cap[1] === 'www.') {
914
+ href = 'http://' + text;
472
915
  } else {
473
- item.align[i] = null;
916
+ href = text;
474
917
  }
475
918
  }
476
919
 
477
- for (i = 0; i < item.cells.length; i++) {
478
- item.cells[i] = splitCells(
479
- item.cells[i].replace(/^ *\| *| *\| *$/g, ''),
480
- item.header.length);
920
+ return {
921
+ type: 'link',
922
+ raw: cap[0],
923
+ text: text,
924
+ href: href,
925
+ tokens: [{
926
+ type: 'text',
927
+ raw: text,
928
+ text: text
929
+ }]
930
+ };
931
+ }
932
+ };
933
+
934
+ _proto.inlineText = function inlineText(src, inRawBlock, smartypants) {
935
+ var cap = this.rules.inline.text.exec(src);
936
+
937
+ if (cap) {
938
+ var text;
939
+
940
+ if (inRawBlock) {
941
+ text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0];
942
+ } else {
943
+ text = _escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
481
944
  }
482
945
 
483
- this.tokens.push(item);
946
+ return {
947
+ type: 'text',
948
+ raw: cap[0],
949
+ text: text
950
+ };
951
+ }
952
+ };
953
+
954
+ return Tokenizer;
955
+ }();
956
+
957
+ var noopTest$1 = helpers.noopTest,
958
+ edit$1 = helpers.edit,
959
+ merge$1 = helpers.merge;
960
+ /**
961
+ * Block-Level Grammar
962
+ */
963
+
964
+ var block = {
965
+ newline: /^\n+/,
966
+ code: /^( {4}[^\n]+\n*)+/,
967
+ fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
968
+ hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
969
+ heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
970
+ blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
971
+ list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
972
+ html: '^ {0,3}(?:' // optional indentation
973
+ + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
974
+ + '|comment[^\\n]*(\\n+|$)' // (2)
975
+ + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
976
+ + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
977
+ + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
978
+ + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
979
+ + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
980
+ + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
981
+ + ')',
982
+ def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
983
+ nptable: noopTest$1,
984
+ table: noopTest$1,
985
+ lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
986
+ // regex template, placeholders will be replaced according to different paragraph
987
+ // interruption rules of commonmark and the original markdown spec:
988
+ _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
989
+ text: /^[^\n]+/
990
+ };
991
+ block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
992
+ block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
993
+ block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex();
994
+ block.bullet = /(?:[*+-]|\d{1,9}\.)/;
995
+ block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
996
+ block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex();
997
+ block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex();
998
+ 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';
999
+ block._comment = /<!--(?!-?>)[\s\S]*?-->/;
1000
+ block.html = edit$1(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
1001
+ block.paragraph = edit$1(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1002
+ .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1003
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
1004
+ .getRegex();
1005
+ block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex();
1006
+ /**
1007
+ * Normal Block Grammar
1008
+ */
1009
+
1010
+ block.normal = merge$1({}, block);
1011
+ /**
1012
+ * GFM Block Grammar
1013
+ */
1014
+
1015
+ block.gfm = merge$1({}, block.normal, {
1016
+ nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
1017
+ + ' *([-:]+ *\\|[-| :]*)' // Align
1018
+ + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)',
1019
+ // Cells
1020
+ table: '^ *\\|(.+)\\n' // Header
1021
+ + ' *\\|?( *[-:]+[-| :]*)' // Align
1022
+ + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
1023
+
1024
+ });
1025
+ block.gfm.nptable = edit$1(block.gfm.nptable).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[.)]) ') // only lists starting from 1 can interrupt
1026
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1027
+ .getRegex();
1028
+ block.gfm.table = edit$1(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[.)]) ') // only lists starting from 1 can interrupt
1029
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1030
+ .getRegex();
1031
+ /**
1032
+ * Pedantic grammar (original John Gruber's loose markdown specification)
1033
+ */
1034
+
1035
+ block.pedantic = merge$1({}, block.normal, {
1036
+ html: edit$1('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
1037
+ + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))').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(),
1038
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1039
+ heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
1040
+ fences: noopTest$1,
1041
+ // fences not supported
1042
+ paragraph: edit$1(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()
1043
+ });
1044
+ /**
1045
+ * Inline-Level Grammar
1046
+ */
1047
+
1048
+ var inline = {
1049
+ escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
1050
+ autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
1051
+ url: noopTest$1,
1052
+ tag: '^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
1053
+ + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
1054
+ + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
1055
+ + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
1056
+ + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
1057
+ // CDATA section
1058
+ link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
1059
+ reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
1060
+ nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
1061
+ strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
1062
+ em: /^_([^\s_])_(?!_)|^_([^\s_<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s*<\[])\*(?!\*)|^\*([^\s<"][\s\S]*?[^\s\[\*])\*(?![\]`punctuation])|^\*([^\s*"<\[][\s\S]*[^\s])\*(?!\*)/,
1063
+ code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1064
+ br: /^( {2,}|\\)\n(?!\s*$)/,
1065
+ del: noopTest$1,
1066
+ text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
1067
+ }; // list of punctuation marks from common mark spec
1068
+ // without ` and ] to workaround Rule 17 (inline code blocks/links)
1069
+
1070
+ inline._punctuation = '!"#$%&\'()*+\\-./:;<=>?@\\[^_{|}~';
1071
+ inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
1072
+ inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
1073
+ inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
1074
+ 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])?)+(?![-_])/;
1075
+ inline.autolink = edit$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex();
1076
+ inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
1077
+ inline.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex();
1078
+ inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1079
+ inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
1080
+ inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1081
+ inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex();
1082
+ inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex();
1083
+ /**
1084
+ * Normal Inline Grammar
1085
+ */
1086
+
1087
+ inline.normal = merge$1({}, inline);
1088
+ /**
1089
+ * Pedantic Inline Grammar
1090
+ */
1091
+
1092
+ inline.pedantic = merge$1({}, inline.normal, {
1093
+ strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
1094
+ em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
1095
+ link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
1096
+ reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
1097
+ });
1098
+ /**
1099
+ * GFM Inline Grammar
1100
+ */
1101
+
1102
+ inline.gfm = merge$1({}, inline.normal, {
1103
+ escape: edit$1(inline.escape).replace('])', '~|])').getRegex(),
1104
+ _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
1105
+ url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
1106
+ _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
1107
+ del: /^~+(?=\S)([\s\S]*?\S)~+/,
1108
+ text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
1109
+ });
1110
+ inline.gfm.url = edit$1(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
1111
+ /**
1112
+ * GFM + Line Breaks Inline Grammar
1113
+ */
1114
+
1115
+ inline.breaks = merge$1({}, inline.gfm, {
1116
+ br: edit$1(inline.br).replace('{2,}', '*').getRegex(),
1117
+ text: edit$1(inline.gfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
1118
+ });
1119
+ var rules = {
1120
+ block: block,
1121
+ inline: inline
1122
+ };
1123
+
1124
+ var defaults$2 = defaults.defaults;
1125
+ var block$1 = rules.block,
1126
+ inline$1 = rules.inline;
1127
+ /**
1128
+ * smartypants text replacement
1129
+ */
1130
+
1131
+ function smartypants(text) {
1132
+ return text // em-dashes
1133
+ .replace(/---/g, "\u2014") // en-dashes
1134
+ .replace(/--/g, "\u2013") // opening singles
1135
+ .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
1136
+ .replace(/'/g, "\u2019") // opening doubles
1137
+ .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
1138
+ .replace(/"/g, "\u201D") // ellipses
1139
+ .replace(/\.{3}/g, "\u2026");
1140
+ }
1141
+ /**
1142
+ * mangle email addresses
1143
+ */
1144
+
1145
+
1146
+ function mangle(text) {
1147
+ var out = '',
1148
+ i,
1149
+ ch;
1150
+ var l = text.length;
1151
+
1152
+ for (i = 0; i < l; i++) {
1153
+ ch = text.charCodeAt(i);
484
1154
 
485
- continue;
1155
+ if (Math.random() > 0.5) {
1156
+ ch = 'x' + ch.toString(16);
486
1157
  }
487
- }
488
1158
 
489
- // lheading
490
- if (cap = this.rules.lheading.exec(src)) {
491
- src = src.substring(cap[0].length);
492
- this.tokens.push({
493
- type: 'heading',
494
- depth: cap[2].charAt(0) === '=' ? 1 : 2,
495
- text: cap[1]
496
- });
497
- continue;
1159
+ out += '&#' + ch + ';';
498
1160
  }
499
1161
 
500
- // top-level paragraph
501
- if (top && (cap = this.rules.paragraph.exec(src))) {
502
- src = src.substring(cap[0].length);
503
- this.tokens.push({
504
- type: 'paragraph',
505
- text: cap[1].charAt(cap[1].length - 1) === '\n'
506
- ? cap[1].slice(0, -1)
507
- : cap[1]
508
- });
509
- continue;
1162
+ return out;
1163
+ }
1164
+ /**
1165
+ * Block Lexer
1166
+ */
1167
+
1168
+
1169
+ var Lexer_1 = /*#__PURE__*/function () {
1170
+ function Lexer(options) {
1171
+ this.tokens = [];
1172
+ this.tokens.links = Object.create(null);
1173
+ this.options = options || defaults$2;
1174
+ this.options.tokenizer = this.options.tokenizer || new Tokenizer_1();
1175
+ this.tokenizer = this.options.tokenizer;
1176
+ this.tokenizer.options = this.options;
1177
+ var rules = {
1178
+ block: block$1.normal,
1179
+ inline: inline$1.normal
1180
+ };
1181
+
1182
+ if (this.options.pedantic) {
1183
+ rules.block = block$1.pedantic;
1184
+ rules.inline = inline$1.pedantic;
1185
+ } else if (this.options.gfm) {
1186
+ rules.block = block$1.gfm;
1187
+
1188
+ if (this.options.breaks) {
1189
+ rules.inline = inline$1.breaks;
1190
+ } else {
1191
+ rules.inline = inline$1.gfm;
1192
+ }
1193
+ }
1194
+
1195
+ this.tokenizer.rules = rules;
510
1196
  }
1197
+ /**
1198
+ * Expose Rules
1199
+ */
1200
+
511
1201
 
512
- // text
513
- if (cap = this.rules.text.exec(src)) {
514
- // Top-level should never reach here.
515
- src = src.substring(cap[0].length);
516
- this.tokens.push({
517
- type: 'text',
518
- text: cap[0]
519
- });
520
- continue;
1202
+ /**
1203
+ * Static Lex Method
1204
+ */
1205
+ Lexer.lex = function lex(src, options) {
1206
+ var lexer = new Lexer(options);
1207
+ return lexer.lex(src);
521
1208
  }
1209
+ /**
1210
+ * Preprocessing
1211
+ */
1212
+ ;
1213
+
1214
+ var _proto = Lexer.prototype;
1215
+
1216
+ _proto.lex = function lex(src) {
1217
+ src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
1218
+ this.blockTokens(src, this.tokens, true);
1219
+ this.inline(this.tokens);
1220
+ return this.tokens;
1221
+ }
1222
+ /**
1223
+ * Lexing
1224
+ */
1225
+ ;
1226
+
1227
+ _proto.blockTokens = function blockTokens(src, tokens, top) {
1228
+ if (tokens === void 0) {
1229
+ tokens = [];
1230
+ }
1231
+
1232
+ if (top === void 0) {
1233
+ top = true;
1234
+ }
1235
+
1236
+ src = src.replace(/^ +$/gm, '');
1237
+ var token, i, l;
1238
+
1239
+ while (src) {
1240
+ // newline
1241
+ if (token = this.tokenizer.space(src)) {
1242
+ src = src.substring(token.raw.length);
1243
+
1244
+ if (token.type) {
1245
+ tokens.push(token);
1246
+ }
1247
+
1248
+ continue;
1249
+ } // code
1250
+
1251
+
1252
+ if (token = this.tokenizer.code(src, tokens)) {
1253
+ src = src.substring(token.raw.length);
1254
+ tokens.push(token);
1255
+ continue;
1256
+ } // fences
1257
+
1258
+
1259
+ if (token = this.tokenizer.fences(src)) {
1260
+ src = src.substring(token.raw.length);
1261
+ tokens.push(token);
1262
+ continue;
1263
+ } // heading
1264
+
1265
+
1266
+ if (token = this.tokenizer.heading(src)) {
1267
+ src = src.substring(token.raw.length);
1268
+ tokens.push(token);
1269
+ continue;
1270
+ } // table no leading pipe (gfm)
522
1271
 
523
- if (src) {
524
- throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
1272
+
1273
+ if (token = this.tokenizer.nptable(src)) {
1274
+ src = src.substring(token.raw.length);
1275
+ tokens.push(token);
1276
+ continue;
1277
+ } // hr
1278
+
1279
+
1280
+ if (token = this.tokenizer.hr(src)) {
1281
+ src = src.substring(token.raw.length);
1282
+ tokens.push(token);
1283
+ continue;
1284
+ } // blockquote
1285
+
1286
+
1287
+ if (token = this.tokenizer.blockquote(src)) {
1288
+ src = src.substring(token.raw.length);
1289
+ token.tokens = this.blockTokens(token.text, [], top);
1290
+ tokens.push(token);
1291
+ continue;
1292
+ } // list
1293
+
1294
+
1295
+ if (token = this.tokenizer.list(src)) {
1296
+ src = src.substring(token.raw.length);
1297
+ l = token.items.length;
1298
+
1299
+ for (i = 0; i < l; i++) {
1300
+ token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
1301
+ }
1302
+
1303
+ tokens.push(token);
1304
+ continue;
1305
+ } // html
1306
+
1307
+
1308
+ if (token = this.tokenizer.html(src)) {
1309
+ src = src.substring(token.raw.length);
1310
+ tokens.push(token);
1311
+ continue;
1312
+ } // def
1313
+
1314
+
1315
+ if (top && (token = this.tokenizer.def(src))) {
1316
+ src = src.substring(token.raw.length);
1317
+
1318
+ if (!this.tokens.links[token.tag]) {
1319
+ this.tokens.links[token.tag] = {
1320
+ href: token.href,
1321
+ title: token.title
1322
+ };
1323
+ }
1324
+
1325
+ continue;
1326
+ } // table (gfm)
1327
+
1328
+
1329
+ if (token = this.tokenizer.table(src)) {
1330
+ src = src.substring(token.raw.length);
1331
+ tokens.push(token);
1332
+ continue;
1333
+ } // lheading
1334
+
1335
+
1336
+ if (token = this.tokenizer.lheading(src)) {
1337
+ src = src.substring(token.raw.length);
1338
+ tokens.push(token);
1339
+ continue;
1340
+ } // top-level paragraph
1341
+
1342
+
1343
+ if (top && (token = this.tokenizer.paragraph(src))) {
1344
+ src = src.substring(token.raw.length);
1345
+ tokens.push(token);
1346
+ continue;
1347
+ } // text
1348
+
1349
+
1350
+ if (token = this.tokenizer.text(src)) {
1351
+ src = src.substring(token.raw.length);
1352
+ tokens.push(token);
1353
+ continue;
1354
+ }
1355
+
1356
+ if (src) {
1357
+ var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1358
+
1359
+ if (this.options.silent) {
1360
+ console.error(errMsg);
1361
+ break;
1362
+ } else {
1363
+ throw new Error(errMsg);
1364
+ }
1365
+ }
1366
+ }
1367
+
1368
+ return tokens;
1369
+ };
1370
+
1371
+ _proto.inline = function inline(tokens) {
1372
+ var i, j, k, l2, row, token;
1373
+ var l = tokens.length;
1374
+
1375
+ for (i = 0; i < l; i++) {
1376
+ token = tokens[i];
1377
+
1378
+ switch (token.type) {
1379
+ case 'paragraph':
1380
+ case 'text':
1381
+ case 'heading':
1382
+ {
1383
+ token.tokens = [];
1384
+ this.inlineTokens(token.text, token.tokens);
1385
+ break;
1386
+ }
1387
+
1388
+ case 'table':
1389
+ {
1390
+ token.tokens = {
1391
+ header: [],
1392
+ cells: []
1393
+ }; // header
1394
+
1395
+ l2 = token.header.length;
1396
+
1397
+ for (j = 0; j < l2; j++) {
1398
+ token.tokens.header[j] = [];
1399
+ this.inlineTokens(token.header[j], token.tokens.header[j]);
1400
+ } // cells
1401
+
1402
+
1403
+ l2 = token.cells.length;
1404
+
1405
+ for (j = 0; j < l2; j++) {
1406
+ row = token.cells[j];
1407
+ token.tokens.cells[j] = [];
1408
+
1409
+ for (k = 0; k < row.length; k++) {
1410
+ token.tokens.cells[j][k] = [];
1411
+ this.inlineTokens(row[k], token.tokens.cells[j][k]);
1412
+ }
1413
+ }
1414
+
1415
+ break;
1416
+ }
1417
+
1418
+ case 'blockquote':
1419
+ {
1420
+ this.inline(token.tokens);
1421
+ break;
1422
+ }
1423
+
1424
+ case 'list':
1425
+ {
1426
+ l2 = token.items.length;
1427
+
1428
+ for (j = 0; j < l2; j++) {
1429
+ this.inline(token.items[j].tokens);
1430
+ }
1431
+
1432
+ break;
1433
+ }
1434
+ }
1435
+ }
1436
+
1437
+ return tokens;
525
1438
  }
526
- }
1439
+ /**
1440
+ * Lexing/Compiling
1441
+ */
1442
+ ;
1443
+
1444
+ _proto.inlineTokens = function inlineTokens(src, tokens, inLink, inRawBlock) {
1445
+ if (tokens === void 0) {
1446
+ tokens = [];
1447
+ }
527
1448
 
528
- return this.tokens;
529
- };
1449
+ if (inLink === void 0) {
1450
+ inLink = false;
1451
+ }
1452
+
1453
+ if (inRawBlock === void 0) {
1454
+ inRawBlock = false;
1455
+ }
1456
+
1457
+ var token;
1458
+
1459
+ while (src) {
1460
+ // escape
1461
+ if (token = this.tokenizer.escape(src)) {
1462
+ src = src.substring(token.raw.length);
1463
+ tokens.push(token);
1464
+ continue;
1465
+ } // tag
530
1466
 
531
- /**
532
- * Inline-Level Grammar
533
- */
534
1467
 
535
- var inline = {
536
- escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
537
- autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
538
- url: noop,
539
- tag: '^comment'
540
- + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
541
- + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
542
- + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
543
- + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
544
- + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section
545
- link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
546
- reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
547
- nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
548
- strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
549
- em: /^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
550
- code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
551
- br: /^( {2,}|\\)\n(?!\s*$)/,
552
- del: noop,
553
- text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
554
- };
555
-
556
- // list of punctuation marks from common mark spec
557
- // without ` and ] to workaround Rule 17 (inline code blocks/links)
558
- inline._punctuation = '!"#$%&\'()*+,\\-./:;<=>?@\\[^_{|}~';
559
- inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
560
-
561
- inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
562
-
563
- inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
564
- 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])?)+(?![-_])/;
565
- inline.autolink = edit(inline.autolink)
566
- .replace('scheme', inline._scheme)
567
- .replace('email', inline._email)
568
- .getRegex();
1468
+ if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
1469
+ src = src.substring(token.raw.length);
1470
+ inLink = token.inLink;
1471
+ inRawBlock = token.inRawBlock;
1472
+ tokens.push(token);
1473
+ continue;
1474
+ } // link
569
1475
 
570
- inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
571
1476
 
572
- inline.tag = edit(inline.tag)
573
- .replace('comment', block._comment)
574
- .replace('attribute', inline._attribute)
575
- .getRegex();
1477
+ if (token = this.tokenizer.link(src)) {
1478
+ src = src.substring(token.raw.length);
576
1479
 
577
- inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
578
- inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
579
- inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1480
+ if (token.type === 'link') {
1481
+ token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1482
+ }
580
1483
 
581
- inline.link = edit(inline.link)
582
- .replace('label', inline._label)
583
- .replace('href', inline._href)
584
- .replace('title', inline._title)
585
- .getRegex();
1484
+ tokens.push(token);
1485
+ continue;
1486
+ } // reflink, nolink
586
1487
 
587
- inline.reflink = edit(inline.reflink)
588
- .replace('label', inline._label)
589
- .getRegex();
590
1488
 
591
- /**
592
- * Normal Inline Grammar
593
- */
1489
+ if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1490
+ src = src.substring(token.raw.length);
594
1491
 
595
- inline.normal = merge({}, inline);
1492
+ if (token.type === 'link') {
1493
+ token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
1494
+ }
596
1495
 
597
- /**
598
- * Pedantic Inline Grammar
599
- */
1496
+ tokens.push(token);
1497
+ continue;
1498
+ } // strong
600
1499
 
601
- inline.pedantic = merge({}, inline.normal, {
602
- strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
603
- em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
604
- link: edit(/^!?\[(label)\]\((.*?)\)/)
605
- .replace('label', inline._label)
606
- .getRegex(),
607
- reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
608
- .replace('label', inline._label)
609
- .getRegex()
610
- });
611
1500
 
612
- /**
613
- * GFM Inline Grammar
614
- */
1501
+ if (token = this.tokenizer.strong(src)) {
1502
+ src = src.substring(token.raw.length);
1503
+ token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1504
+ tokens.push(token);
1505
+ continue;
1506
+ } // em
615
1507
 
616
- inline.gfm = merge({}, inline.normal, {
617
- escape: edit(inline.escape).replace('])', '~|])').getRegex(),
618
- _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
619
- url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
620
- _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
621
- del: /^~+(?=\S)([\s\S]*?\S)~+/,
622
- text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
623
- });
624
-
625
- inline.gfm.url = edit(inline.gfm.url, 'i')
626
- .replace('email', inline.gfm._extended_email)
627
- .getRegex();
628
- /**
629
- * GFM + Line Breaks Inline Grammar
630
- */
631
1508
 
632
- inline.breaks = merge({}, inline.gfm, {
633
- br: edit(inline.br).replace('{2,}', '*').getRegex(),
634
- text: edit(inline.gfm.text)
635
- .replace('\\b_', '\\b_| {2,}\\n')
636
- .replace(/\{2,\}/g, '*')
637
- .getRegex()
638
- });
1509
+ if (token = this.tokenizer.em(src)) {
1510
+ src = src.substring(token.raw.length);
1511
+ token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1512
+ tokens.push(token);
1513
+ continue;
1514
+ } // code
639
1515
 
640
- /**
641
- * Inline Lexer & Compiler
642
- */
643
1516
 
644
- function InlineLexer(links, options) {
645
- this.options = options || marked.defaults;
646
- this.links = links;
647
- this.rules = inline.normal;
648
- this.renderer = this.options.renderer || new Renderer();
649
- this.renderer.options = this.options;
1517
+ if (token = this.tokenizer.codespan(src)) {
1518
+ src = src.substring(token.raw.length);
1519
+ tokens.push(token);
1520
+ continue;
1521
+ } // br
650
1522
 
651
- if (!this.links) {
652
- throw new Error('Tokens array requires a `links` property.');
653
- }
654
1523
 
655
- if (this.options.pedantic) {
656
- this.rules = inline.pedantic;
657
- } else if (this.options.gfm) {
658
- if (this.options.breaks) {
659
- this.rules = inline.breaks;
660
- } else {
661
- this.rules = inline.gfm;
662
- }
663
- }
664
- }
1524
+ if (token = this.tokenizer.br(src)) {
1525
+ src = src.substring(token.raw.length);
1526
+ tokens.push(token);
1527
+ continue;
1528
+ } // del (gfm)
665
1529
 
666
- /**
667
- * Expose Inline Rules
668
- */
669
1530
 
670
- InlineLexer.rules = inline;
1531
+ if (token = this.tokenizer.del(src)) {
1532
+ src = src.substring(token.raw.length);
1533
+ token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
1534
+ tokens.push(token);
1535
+ continue;
1536
+ } // autolink
671
1537
 
672
- /**
673
- * Static Lexing/Compiling Method
674
- */
675
1538
 
676
- InlineLexer.output = function(src, links, options) {
677
- var inline = new InlineLexer(links, options);
678
- return inline.output(src);
679
- };
1539
+ if (token = this.tokenizer.autolink(src, mangle)) {
1540
+ src = src.substring(token.raw.length);
1541
+ tokens.push(token);
1542
+ continue;
1543
+ } // url (gfm)
680
1544
 
681
- /**
682
- * Lexing/Compiling
683
- */
684
1545
 
685
- InlineLexer.prototype.output = function(src) {
686
- var out = '',
687
- link,
688
- text,
689
- href,
690
- title,
691
- cap,
692
- prevCapZero;
693
-
694
- while (src) {
695
- // escape
696
- if (cap = this.rules.escape.exec(src)) {
697
- src = src.substring(cap[0].length);
698
- out += escape(cap[1]);
699
- continue;
700
- }
1546
+ if (!inLink && (token = this.tokenizer.url(src, mangle))) {
1547
+ src = src.substring(token.raw.length);
1548
+ tokens.push(token);
1549
+ continue;
1550
+ } // text
701
1551
 
702
- // tag
703
- if (cap = this.rules.tag.exec(src)) {
704
- if (!this.inLink && /^<a /i.test(cap[0])) {
705
- this.inLink = true;
706
- } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
707
- this.inLink = false;
708
- }
709
- if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
710
- this.inRawBlock = true;
711
- } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
712
- this.inRawBlock = false;
713
- }
714
1552
 
715
- src = src.substring(cap[0].length);
716
- out += this.options.sanitize
717
- ? this.options.sanitizer
718
- ? this.options.sanitizer(cap[0])
719
- : escape(cap[0])
720
- : cap[0];
721
- continue;
722
- }
1553
+ if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
1554
+ src = src.substring(token.raw.length);
1555
+ tokens.push(token);
1556
+ continue;
1557
+ }
723
1558
 
724
- // link
725
- if (cap = this.rules.link.exec(src)) {
726
- var lastParenIndex = findClosingBracket(cap[2], '()');
727
- if (lastParenIndex > -1) {
728
- var linkLen = 4 + cap[1].length + lastParenIndex;
729
- cap[2] = cap[2].substring(0, lastParenIndex);
730
- cap[0] = cap[0].substring(0, linkLen).trim();
731
- cap[3] = '';
732
- }
733
- src = src.substring(cap[0].length);
734
- this.inLink = true;
735
- href = cap[2];
736
- if (this.options.pedantic) {
737
- link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
1559
+ if (src) {
1560
+ var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
738
1561
 
739
- if (link) {
740
- href = link[1];
741
- title = link[3];
742
- } else {
743
- title = '';
1562
+ if (this.options.silent) {
1563
+ console.error(errMsg);
1564
+ break;
1565
+ } else {
1566
+ throw new Error(errMsg);
1567
+ }
744
1568
  }
745
- } else {
746
- title = cap[3] ? cap[3].slice(1, -1) : '';
747
1569
  }
748
- href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
749
- out += this.outputLink(cap, {
750
- href: InlineLexer.escapes(href),
751
- title: InlineLexer.escapes(title)
752
- });
753
- this.inLink = false;
754
- continue;
755
- }
756
1570
 
757
- // reflink, nolink
758
- if ((cap = this.rules.reflink.exec(src))
759
- || (cap = this.rules.nolink.exec(src))) {
760
- src = src.substring(cap[0].length);
761
- link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
762
- link = this.links[link.toLowerCase()];
763
- if (!link || !link.href) {
764
- out += cap[0].charAt(0);
765
- src = cap[0].substring(1) + src;
766
- continue;
1571
+ return tokens;
1572
+ };
1573
+
1574
+ _createClass(Lexer, null, [{
1575
+ key: "rules",
1576
+ get: function get() {
1577
+ return {
1578
+ block: block$1,
1579
+ inline: inline$1
1580
+ };
767
1581
  }
768
- this.inLink = true;
769
- out += this.outputLink(cap, link);
770
- this.inLink = false;
771
- continue;
772
- }
1582
+ }]);
773
1583
 
774
- // strong
775
- if (cap = this.rules.strong.exec(src)) {
776
- src = src.substring(cap[0].length);
777
- out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1]));
778
- continue;
779
- }
1584
+ return Lexer;
1585
+ }();
780
1586
 
781
- // em
782
- if (cap = this.rules.em.exec(src)) {
783
- src = src.substring(cap[0].length);
784
- out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]));
785
- continue;
786
- }
1587
+ var defaults$3 = defaults.defaults;
1588
+ var cleanUrl$1 = helpers.cleanUrl,
1589
+ escape$1 = helpers.escape;
1590
+ /**
1591
+ * Renderer
1592
+ */
787
1593
 
788
- // code
789
- if (cap = this.rules.code.exec(src)) {
790
- src = src.substring(cap[0].length);
791
- out += this.renderer.codespan(escape(cap[2].trim(), true));
792
- continue;
1594
+ var Renderer_1 = /*#__PURE__*/function () {
1595
+ function Renderer(options) {
1596
+ this.options = options || defaults$3;
793
1597
  }
794
1598
 
795
- // br
796
- if (cap = this.rules.br.exec(src)) {
797
- src = src.substring(cap[0].length);
798
- out += this.renderer.br();
799
- continue;
800
- }
1599
+ var _proto = Renderer.prototype;
801
1600
 
802
- // del (gfm)
803
- if (cap = this.rules.del.exec(src)) {
804
- src = src.substring(cap[0].length);
805
- out += this.renderer.del(this.output(cap[1]));
806
- continue;
807
- }
1601
+ _proto.code = function code(_code, infostring, escaped) {
1602
+ var lang = (infostring || '').match(/\S*/)[0];
808
1603
 
809
- // autolink
810
- if (cap = this.rules.autolink.exec(src)) {
811
- src = src.substring(cap[0].length);
812
- if (cap[2] === '@') {
813
- text = escape(this.mangle(cap[1]));
814
- href = 'mailto:' + text;
815
- } else {
816
- text = escape(cap[1]);
817
- href = text;
818
- }
819
- out += this.renderer.link(href, null, text);
820
- continue;
821
- }
1604
+ if (this.options.highlight) {
1605
+ var out = this.options.highlight(_code, lang);
822
1606
 
823
- // url (gfm)
824
- if (!this.inLink && (cap = this.rules.url.exec(src))) {
825
- if (cap[2] === '@') {
826
- text = escape(cap[0]);
827
- href = 'mailto:' + text;
828
- } else {
829
- // do extended autolink path validation
830
- do {
831
- prevCapZero = cap[0];
832
- cap[0] = this.rules._backpedal.exec(cap[0])[0];
833
- } while (prevCapZero !== cap[0]);
834
- text = escape(cap[0]);
835
- if (cap[1] === 'www.') {
836
- href = 'http://' + text;
837
- } else {
838
- href = text;
1607
+ if (out != null && out !== _code) {
1608
+ escaped = true;
1609
+ _code = out;
839
1610
  }
840
1611
  }
841
- src = src.substring(cap[0].length);
842
- out += this.renderer.link(href, null, text);
843
- continue;
844
- }
845
1612
 
846
- // text
847
- if (cap = this.rules.text.exec(src)) {
848
- src = src.substring(cap[0].length);
849
- if (this.inRawBlock) {
850
- out += this.renderer.text(this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0]);
851
- } else {
852
- out += this.renderer.text(escape(this.smartypants(cap[0])));
1613
+ if (!lang) {
1614
+ return '<pre><code>' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>';
853
1615
  }
854
- continue;
855
- }
856
1616
 
857
- if (src) {
858
- throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
859
- }
860
- }
1617
+ return '<pre><code class="' + this.options.langPrefix + escape$1(lang, true) + '">' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
1618
+ };
1619
+
1620
+ _proto.blockquote = function blockquote(quote) {
1621
+ return '<blockquote>\n' + quote + '</blockquote>\n';
1622
+ };
861
1623
 
862
- return out;
863
- };
1624
+ _proto.html = function html(_html) {
1625
+ return _html;
1626
+ };
864
1627
 
865
- InlineLexer.escapes = function(text) {
866
- return text ? text.replace(InlineLexer.rules._escapes, '$1') : text;
867
- };
1628
+ _proto.heading = function heading(text, level, raw, slugger) {
1629
+ if (this.options.headerIds) {
1630
+ return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n';
1631
+ } // ignore IDs
868
1632
 
869
- /**
870
- * Compile Link
871
- */
872
1633
 
873
- InlineLexer.prototype.outputLink = function(cap, link) {
874
- var href = link.href,
875
- title = link.title ? escape(link.title) : null;
1634
+ return '<h' + level + '>' + text + '</h' + level + '>\n';
1635
+ };
876
1636
 
877
- return cap[0].charAt(0) !== '!'
878
- ? this.renderer.link(href, title, this.output(cap[1]))
879
- : this.renderer.image(href, title, escape(cap[1]));
880
- };
1637
+ _proto.hr = function hr() {
1638
+ return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
1639
+ };
881
1640
 
882
- /**
883
- * Smartypants Transformations
884
- */
1641
+ _proto.list = function list(body, ordered, start) {
1642
+ var type = ordered ? 'ol' : 'ul',
1643
+ startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
1644
+ return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1645
+ };
885
1646
 
886
- InlineLexer.prototype.smartypants = function(text) {
887
- if (!this.options.smartypants) return text;
888
- return text
889
- // em-dashes
890
- .replace(/---/g, '\u2014')
891
- // en-dashes
892
- .replace(/--/g, '\u2013')
893
- // opening singles
894
- .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
895
- // closing singles & apostrophes
896
- .replace(/'/g, '\u2019')
897
- // opening doubles
898
- .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
899
- // closing doubles
900
- .replace(/"/g, '\u201d')
901
- // ellipses
902
- .replace(/\.{3}/g, '\u2026');
903
- };
1647
+ _proto.listitem = function listitem(text) {
1648
+ return '<li>' + text + '</li>\n';
1649
+ };
904
1650
 
905
- /**
906
- * Mangle Links
907
- */
1651
+ _proto.checkbox = function checkbox(checked) {
1652
+ return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
1653
+ };
908
1654
 
909
- InlineLexer.prototype.mangle = function(text) {
910
- if (!this.options.mangle) return text;
911
- var out = '',
912
- l = text.length,
913
- i = 0,
914
- ch;
915
-
916
- for (; i < l; i++) {
917
- ch = text.charCodeAt(i);
918
- if (Math.random() > 0.5) {
919
- ch = 'x' + ch.toString(16);
920
- }
921
- out += '&#' + ch + ';';
922
- }
1655
+ _proto.paragraph = function paragraph(text) {
1656
+ return '<p>' + text + '</p>\n';
1657
+ };
923
1658
 
924
- return out;
925
- };
1659
+ _proto.table = function table(header, body) {
1660
+ if (body) body = '<tbody>' + body + '</tbody>';
1661
+ return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
1662
+ };
926
1663
 
927
- /**
928
- * Renderer
929
- */
1664
+ _proto.tablerow = function tablerow(content) {
1665
+ return '<tr>\n' + content + '</tr>\n';
1666
+ };
930
1667
 
931
- function Renderer(options) {
932
- this.options = options || marked.defaults;
933
- }
934
-
935
- Renderer.prototype.code = function(code, infostring, escaped) {
936
- var lang = (infostring || '').match(/\S*/)[0];
937
- if (this.options.highlight) {
938
- var out = this.options.highlight(code, lang);
939
- if (out != null && out !== code) {
940
- escaped = true;
941
- code = out;
942
- }
943
- }
1668
+ _proto.tablecell = function tablecell(content, flags) {
1669
+ var type = flags.header ? 'th' : 'td';
1670
+ var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
1671
+ return tag + content + '</' + type + '>\n';
1672
+ } // span level renderer
1673
+ ;
944
1674
 
945
- if (!lang) {
946
- return '<pre><code>'
947
- + (escaped ? code : escape(code, true))
948
- + '</code></pre>';
949
- }
1675
+ _proto.strong = function strong(text) {
1676
+ return '<strong>' + text + '</strong>';
1677
+ };
950
1678
 
951
- return '<pre><code class="'
952
- + this.options.langPrefix
953
- + escape(lang, true)
954
- + '">'
955
- + (escaped ? code : escape(code, true))
956
- + '</code></pre>\n';
957
- };
958
-
959
- Renderer.prototype.blockquote = function(quote) {
960
- return '<blockquote>\n' + quote + '</blockquote>\n';
961
- };
962
-
963
- Renderer.prototype.html = function(html) {
964
- return html;
965
- };
966
-
967
- Renderer.prototype.heading = function(text, level, raw, slugger) {
968
- if (this.options.headerIds) {
969
- return '<h'
970
- + level
971
- + ' id="'
972
- + this.options.headerPrefix
973
- + slugger.slug(raw)
974
- + '">'
975
- + text
976
- + '</h'
977
- + level
978
- + '>\n';
979
- }
980
- // ignore IDs
981
- return '<h' + level + '>' + text + '</h' + level + '>\n';
982
- };
983
-
984
- Renderer.prototype.hr = function() {
985
- return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
986
- };
987
-
988
- Renderer.prototype.list = function(body, ordered, start) {
989
- var type = ordered ? 'ol' : 'ul',
990
- startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
991
- return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
992
- };
993
-
994
- Renderer.prototype.listitem = function(text) {
995
- return '<li>' + text + '</li>\n';
996
- };
997
-
998
- Renderer.prototype.checkbox = function(checked) {
999
- return '<input '
1000
- + (checked ? 'checked="" ' : '')
1001
- + 'disabled="" type="checkbox"'
1002
- + (this.options.xhtml ? ' /' : '')
1003
- + '> ';
1004
- };
1005
-
1006
- Renderer.prototype.paragraph = function(text) {
1007
- return '<p>' + text + '</p>\n';
1008
- };
1009
-
1010
- Renderer.prototype.table = function(header, body) {
1011
- if (body) body = '<tbody>' + body + '</tbody>';
1012
-
1013
- return '<table>\n'
1014
- + '<thead>\n'
1015
- + header
1016
- + '</thead>\n'
1017
- + body
1018
- + '</table>\n';
1019
- };
1020
-
1021
- Renderer.prototype.tablerow = function(content) {
1022
- return '<tr>\n' + content + '</tr>\n';
1023
- };
1024
-
1025
- Renderer.prototype.tablecell = function(content, flags) {
1026
- var type = flags.header ? 'th' : 'td';
1027
- var tag = flags.align
1028
- ? '<' + type + ' align="' + flags.align + '">'
1029
- : '<' + type + '>';
1030
- return tag + content + '</' + type + '>\n';
1031
- };
1032
-
1033
- // span level renderer
1034
- Renderer.prototype.strong = function(text) {
1035
- return '<strong>' + text + '</strong>';
1036
- };
1037
-
1038
- Renderer.prototype.em = function(text) {
1039
- return '<em>' + text + '</em>';
1040
- };
1041
-
1042
- Renderer.prototype.codespan = function(text) {
1043
- return '<code>' + text + '</code>';
1044
- };
1045
-
1046
- Renderer.prototype.br = function() {
1047
- return this.options.xhtml ? '<br/>' : '<br>';
1048
- };
1049
-
1050
- Renderer.prototype.del = function(text) {
1051
- return '<del>' + text + '</del>';
1052
- };
1053
-
1054
- Renderer.prototype.link = function(href, title, text) {
1055
- href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1056
- if (href === null) {
1057
- return text;
1058
- }
1059
- var out = '<a href="' + escape(href) + '"';
1060
- if (title) {
1061
- out += ' title="' + title + '"';
1062
- }
1063
- out += '>' + text + '</a>';
1064
- return out;
1065
- };
1066
-
1067
- Renderer.prototype.image = function(href, title, text) {
1068
- href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1069
- if (href === null) {
1070
- return text;
1071
- }
1679
+ _proto.em = function em(text) {
1680
+ return '<em>' + text + '</em>';
1681
+ };
1072
1682
 
1073
- var out = '<img src="' + href + '" alt="' + text + '"';
1074
- if (title) {
1075
- out += ' title="' + title + '"';
1076
- }
1077
- out += this.options.xhtml ? '/>' : '>';
1078
- return out;
1079
- };
1683
+ _proto.codespan = function codespan(text) {
1684
+ return '<code>' + text + '</code>';
1685
+ };
1080
1686
 
1081
- Renderer.prototype.text = function(text) {
1082
- return text;
1083
- };
1687
+ _proto.br = function br() {
1688
+ return this.options.xhtml ? '<br/>' : '<br>';
1689
+ };
1084
1690
 
1085
- /**
1086
- * TextRenderer
1087
- * returns only the textual part of the token
1088
- */
1691
+ _proto.del = function del(text) {
1692
+ return '<del>' + text + '</del>';
1693
+ };
1089
1694
 
1090
- function TextRenderer() {}
1695
+ _proto.link = function link(href, title, text) {
1696
+ href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1091
1697
 
1092
- // no need for block level renderers
1698
+ if (href === null) {
1699
+ return text;
1700
+ }
1093
1701
 
1094
- TextRenderer.prototype.strong =
1095
- TextRenderer.prototype.em =
1096
- TextRenderer.prototype.codespan =
1097
- TextRenderer.prototype.del =
1098
- TextRenderer.prototype.text = function(text) {
1099
- return text;
1100
- };
1702
+ var out = '<a href="' + escape$1(href) + '"';
1101
1703
 
1102
- TextRenderer.prototype.link =
1103
- TextRenderer.prototype.image = function(href, title, text) {
1104
- return '' + text;
1105
- };
1704
+ if (title) {
1705
+ out += ' title="' + title + '"';
1706
+ }
1106
1707
 
1107
- TextRenderer.prototype.br = function() {
1108
- return '';
1109
- };
1708
+ out += '>' + text + '</a>';
1709
+ return out;
1710
+ };
1110
1711
 
1111
- /**
1112
- * Parsing & Compiling
1113
- */
1712
+ _proto.image = function image(href, title, text) {
1713
+ href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
1114
1714
 
1115
- function Parser(options) {
1116
- this.tokens = [];
1117
- this.token = null;
1118
- this.options = options || marked.defaults;
1119
- this.options.renderer = this.options.renderer || new Renderer();
1120
- this.renderer = this.options.renderer;
1121
- this.renderer.options = this.options;
1122
- this.slugger = new Slugger();
1123
- }
1715
+ if (href === null) {
1716
+ return text;
1717
+ }
1124
1718
 
1125
- /**
1126
- * Static Parse Method
1127
- */
1719
+ var out = '<img src="' + href + '" alt="' + text + '"';
1128
1720
 
1129
- Parser.parse = function(src, options) {
1130
- var parser = new Parser(options);
1131
- return parser.parse(src);
1132
- };
1721
+ if (title) {
1722
+ out += ' title="' + title + '"';
1723
+ }
1133
1724
 
1134
- /**
1135
- * Parse Loop
1136
- */
1725
+ out += this.options.xhtml ? '/>' : '>';
1726
+ return out;
1727
+ };
1137
1728
 
1138
- Parser.prototype.parse = function(src) {
1139
- this.inline = new InlineLexer(src.links, this.options);
1140
- // use an InlineLexer with a TextRenderer to extract pure text
1141
- this.inlineText = new InlineLexer(
1142
- src.links,
1143
- merge({}, this.options, { renderer: new TextRenderer() })
1144
- );
1145
- this.tokens = src.reverse();
1146
-
1147
- var out = '';
1148
- while (this.next()) {
1149
- out += this.tok();
1150
- }
1729
+ _proto.text = function text(_text) {
1730
+ return _text;
1731
+ };
1151
1732
 
1152
- return out;
1153
- };
1733
+ return Renderer;
1734
+ }();
1154
1735
 
1155
- /**
1156
- * Next Token
1157
- */
1736
+ /**
1737
+ * TextRenderer
1738
+ * returns only the textual part of the token
1739
+ */
1740
+ var TextRenderer_1 = /*#__PURE__*/function () {
1741
+ function TextRenderer() {}
1158
1742
 
1159
- Parser.prototype.next = function() {
1160
- this.token = this.tokens.pop();
1161
- return this.token;
1162
- };
1743
+ var _proto = TextRenderer.prototype;
1163
1744
 
1164
- /**
1165
- * Preview Next Token
1166
- */
1745
+ // no need for block level renderers
1746
+ _proto.strong = function strong(text) {
1747
+ return text;
1748
+ };
1167
1749
 
1168
- Parser.prototype.peek = function() {
1169
- return this.tokens[this.tokens.length - 1] || 0;
1170
- };
1750
+ _proto.em = function em(text) {
1751
+ return text;
1752
+ };
1171
1753
 
1172
- /**
1173
- * Parse Text Tokens
1174
- */
1754
+ _proto.codespan = function codespan(text) {
1755
+ return text;
1756
+ };
1175
1757
 
1176
- Parser.prototype.parseText = function() {
1177
- var body = this.token.text;
1758
+ _proto.del = function del(text) {
1759
+ return text;
1760
+ };
1178
1761
 
1179
- while (this.peek().type === 'text') {
1180
- body += '\n' + this.next().text;
1181
- }
1762
+ _proto.html = function html(text) {
1763
+ return text;
1764
+ };
1182
1765
 
1183
- return this.inline.output(body);
1184
- };
1766
+ _proto.text = function text(_text) {
1767
+ return _text;
1768
+ };
1185
1769
 
1186
- /**
1187
- * Parse Current Token
1188
- */
1770
+ _proto.link = function link(href, title, text) {
1771
+ return '' + text;
1772
+ };
1773
+
1774
+ _proto.image = function image(href, title, text) {
1775
+ return '' + text;
1776
+ };
1189
1777
 
1190
- Parser.prototype.tok = function() {
1191
- switch (this.token.type) {
1192
- case 'space': {
1778
+ _proto.br = function br() {
1193
1779
  return '';
1780
+ };
1781
+
1782
+ return TextRenderer;
1783
+ }();
1784
+
1785
+ /**
1786
+ * Slugger generates header id
1787
+ */
1788
+ var Slugger_1 = /*#__PURE__*/function () {
1789
+ function Slugger() {
1790
+ this.seen = {};
1194
1791
  }
1195
- case 'hr': {
1196
- return this.renderer.hr();
1197
- }
1198
- case 'heading': {
1199
- return this.renderer.heading(
1200
- this.inline.output(this.token.text),
1201
- this.token.depth,
1202
- unescape(this.inlineText.output(this.token.text)),
1203
- this.slugger);
1204
- }
1205
- case 'code': {
1206
- return this.renderer.code(this.token.text,
1207
- this.token.lang,
1208
- this.token.escaped);
1209
- }
1210
- case 'table': {
1211
- var header = '',
1212
- body = '',
1213
- i,
1214
- row,
1215
- cell,
1216
- j;
1217
-
1218
- // header
1219
- cell = '';
1220
- for (i = 0; i < this.token.header.length; i++) {
1221
- cell += this.renderer.tablecell(
1222
- this.inline.output(this.token.header[i]),
1223
- { header: true, align: this.token.align[i] }
1224
- );
1225
- }
1226
- header += this.renderer.tablerow(cell);
1792
+ /**
1793
+ * Convert string to unique id
1794
+ */
1227
1795
 
1228
- for (i = 0; i < this.token.cells.length; i++) {
1229
- row = this.token.cells[i];
1230
1796
 
1231
- cell = '';
1232
- for (j = 0; j < row.length; j++) {
1233
- cell += this.renderer.tablecell(
1234
- this.inline.output(row[j]),
1235
- { header: false, align: this.token.align[j] }
1236
- );
1237
- }
1797
+ var _proto = Slugger.prototype;
1238
1798
 
1239
- body += this.renderer.tablerow(cell);
1240
- }
1241
- return this.renderer.table(header, body);
1242
- }
1243
- case 'blockquote_start': {
1244
- body = '';
1799
+ _proto.slug = function slug(value) {
1800
+ var slug = value.toLowerCase().trim() // remove html tags
1801
+ .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
1802
+ .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
1245
1803
 
1246
- while (this.next().type !== 'blockquote_end') {
1247
- body += this.tok();
1804
+ if (this.seen.hasOwnProperty(slug)) {
1805
+ var originalSlug = slug;
1806
+
1807
+ do {
1808
+ this.seen[originalSlug]++;
1809
+ slug = originalSlug + '-' + this.seen[originalSlug];
1810
+ } while (this.seen.hasOwnProperty(slug));
1248
1811
  }
1249
1812
 
1250
- return this.renderer.blockquote(body);
1813
+ this.seen[slug] = 0;
1814
+ return slug;
1815
+ };
1816
+
1817
+ return Slugger;
1818
+ }();
1819
+
1820
+ var defaults$4 = defaults.defaults;
1821
+ var unescape$1 = helpers.unescape;
1822
+ /**
1823
+ * Parsing & Compiling
1824
+ */
1825
+
1826
+ var Parser_1 = /*#__PURE__*/function () {
1827
+ function Parser(options) {
1828
+ this.options = options || defaults$4;
1829
+ this.options.renderer = this.options.renderer || new Renderer_1();
1830
+ this.renderer = this.options.renderer;
1831
+ this.renderer.options = this.options;
1832
+ this.textRenderer = new TextRenderer_1();
1833
+ this.slugger = new Slugger_1();
1251
1834
  }
1252
- case 'list_start': {
1253
- body = '';
1254
- var ordered = this.token.ordered,
1255
- start = this.token.start;
1835
+ /**
1836
+ * Static Parse Method
1837
+ */
1256
1838
 
1257
- while (this.next().type !== 'list_end') {
1258
- body += this.tok();
1259
- }
1260
1839
 
1261
- return this.renderer.list(body, ordered, start);
1840
+ Parser.parse = function parse(tokens, options) {
1841
+ var parser = new Parser(options);
1842
+ return parser.parse(tokens);
1262
1843
  }
1263
- case 'list_item_start': {
1264
- body = '';
1265
- var loose = this.token.loose;
1266
- var checked = this.token.checked;
1267
- var task = this.token.task;
1268
-
1269
- if (this.token.task) {
1270
- body += this.renderer.checkbox(checked);
1844
+ /**
1845
+ * Parse Loop
1846
+ */
1847
+ ;
1848
+
1849
+ var _proto = Parser.prototype;
1850
+
1851
+ _proto.parse = function parse(tokens, top) {
1852
+ if (top === void 0) {
1853
+ top = true;
1271
1854
  }
1272
1855
 
1273
- while (this.next().type !== 'list_item_end') {
1274
- body += !loose && this.token.type === 'text'
1275
- ? this.parseText()
1276
- : this.tok();
1856
+ var out = '',
1857
+ i,
1858
+ j,
1859
+ k,
1860
+ l2,
1861
+ l3,
1862
+ row,
1863
+ cell,
1864
+ header,
1865
+ body,
1866
+ token,
1867
+ ordered,
1868
+ start,
1869
+ loose,
1870
+ itemBody,
1871
+ item,
1872
+ checked,
1873
+ task,
1874
+ checkbox;
1875
+ var l = tokens.length;
1876
+
1877
+ for (i = 0; i < l; i++) {
1878
+ token = tokens[i];
1879
+
1880
+ switch (token.type) {
1881
+ case 'space':
1882
+ {
1883
+ continue;
1884
+ }
1885
+
1886
+ case 'hr':
1887
+ {
1888
+ out += this.renderer.hr();
1889
+ continue;
1890
+ }
1891
+
1892
+ case 'heading':
1893
+ {
1894
+ out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape$1(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
1895
+ continue;
1896
+ }
1897
+
1898
+ case 'code':
1899
+ {
1900
+ out += this.renderer.code(token.text, token.lang, token.escaped);
1901
+ continue;
1902
+ }
1903
+
1904
+ case 'table':
1905
+ {
1906
+ header = ''; // header
1907
+
1908
+ cell = '';
1909
+ l2 = token.header.length;
1910
+
1911
+ for (j = 0; j < l2; j++) {
1912
+ cell += this.renderer.tablecell(this.parseInline(token.tokens.header[j]), {
1913
+ header: true,
1914
+ align: token.align[j]
1915
+ });
1916
+ }
1917
+
1918
+ header += this.renderer.tablerow(cell);
1919
+ body = '';
1920
+ l2 = token.cells.length;
1921
+
1922
+ for (j = 0; j < l2; j++) {
1923
+ row = token.tokens.cells[j];
1924
+ cell = '';
1925
+ l3 = row.length;
1926
+
1927
+ for (k = 0; k < l3; k++) {
1928
+ cell += this.renderer.tablecell(this.parseInline(row[k]), {
1929
+ header: false,
1930
+ align: token.align[k]
1931
+ });
1932
+ }
1933
+
1934
+ body += this.renderer.tablerow(cell);
1935
+ }
1936
+
1937
+ out += this.renderer.table(header, body);
1938
+ continue;
1939
+ }
1940
+
1941
+ case 'blockquote':
1942
+ {
1943
+ body = this.parse(token.tokens);
1944
+ out += this.renderer.blockquote(body);
1945
+ continue;
1946
+ }
1947
+
1948
+ case 'list':
1949
+ {
1950
+ ordered = token.ordered;
1951
+ start = token.start;
1952
+ loose = token.loose;
1953
+ l2 = token.items.length;
1954
+ body = '';
1955
+
1956
+ for (j = 0; j < l2; j++) {
1957
+ item = token.items[j];
1958
+ checked = item.checked;
1959
+ task = item.task;
1960
+ itemBody = '';
1961
+
1962
+ if (item.task) {
1963
+ checkbox = this.renderer.checkbox(checked);
1964
+
1965
+ if (loose) {
1966
+ if (item.tokens[0].type === 'text') {
1967
+ item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
1968
+
1969
+ if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
1970
+ item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
1971
+ }
1972
+ } else {
1973
+ item.tokens.unshift({
1974
+ type: 'text',
1975
+ text: checkbox
1976
+ });
1977
+ }
1978
+ } else {
1979
+ itemBody += checkbox;
1980
+ }
1981
+ }
1982
+
1983
+ itemBody += this.parse(item.tokens, loose);
1984
+ body += this.renderer.listitem(itemBody, task, checked);
1985
+ }
1986
+
1987
+ out += this.renderer.list(body, ordered, start);
1988
+ continue;
1989
+ }
1990
+
1991
+ case 'html':
1992
+ {
1993
+ // TODO parse inline content if parameter markdown=1
1994
+ out += this.renderer.html(token.text);
1995
+ continue;
1996
+ }
1997
+
1998
+ case 'paragraph':
1999
+ {
2000
+ out += this.renderer.paragraph(this.parseInline(token.tokens));
2001
+ continue;
2002
+ }
2003
+
2004
+ case 'text':
2005
+ {
2006
+ body = token.tokens ? this.parseInline(token.tokens) : token.text;
2007
+
2008
+ while (i + 1 < l && tokens[i + 1].type === 'text') {
2009
+ token = tokens[++i];
2010
+ body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
2011
+ }
2012
+
2013
+ out += top ? this.renderer.paragraph(body) : body;
2014
+ continue;
2015
+ }
2016
+
2017
+ default:
2018
+ {
2019
+ var errMsg = 'Token with "' + token.type + '" type was not found.';
2020
+
2021
+ if (this.options.silent) {
2022
+ console.error(errMsg);
2023
+ return;
2024
+ } else {
2025
+ throw new Error(errMsg);
2026
+ }
2027
+ }
2028
+ }
1277
2029
  }
1278
- return this.renderer.listitem(body, task, checked);
1279
- }
1280
- case 'html': {
1281
- // TODO parse inline content if parameter markdown=1
1282
- return this.renderer.html(this.token.text);
1283
- }
1284
- case 'paragraph': {
1285
- return this.renderer.paragraph(this.inline.output(this.token.text));
1286
- }
1287
- case 'text': {
1288
- return this.renderer.paragraph(this.parseText());
2030
+
2031
+ return out;
1289
2032
  }
1290
- default: {
1291
- var errMsg = 'Token with "' + this.token.type + '" type was not found.';
1292
- if (this.options.silent) {
1293
- console.log(errMsg);
1294
- } else {
1295
- throw new Error(errMsg);
2033
+ /**
2034
+ * Parse Inline Tokens
2035
+ */
2036
+ ;
2037
+
2038
+ _proto.parseInline = function parseInline(tokens, renderer) {
2039
+ renderer = renderer || this.renderer;
2040
+ var out = '',
2041
+ i,
2042
+ token;
2043
+ var l = tokens.length;
2044
+
2045
+ for (i = 0; i < l; i++) {
2046
+ token = tokens[i];
2047
+
2048
+ switch (token.type) {
2049
+ case 'escape':
2050
+ {
2051
+ out += renderer.text(token.text);
2052
+ break;
2053
+ }
2054
+
2055
+ case 'html':
2056
+ {
2057
+ out += renderer.html(token.text);
2058
+ break;
2059
+ }
2060
+
2061
+ case 'link':
2062
+ {
2063
+ out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
2064
+ break;
2065
+ }
2066
+
2067
+ case 'image':
2068
+ {
2069
+ out += renderer.image(token.href, token.title, token.text);
2070
+ break;
2071
+ }
2072
+
2073
+ case 'strong':
2074
+ {
2075
+ out += renderer.strong(this.parseInline(token.tokens, renderer));
2076
+ break;
2077
+ }
2078
+
2079
+ case 'em':
2080
+ {
2081
+ out += renderer.em(this.parseInline(token.tokens, renderer));
2082
+ break;
2083
+ }
2084
+
2085
+ case 'codespan':
2086
+ {
2087
+ out += renderer.codespan(token.text);
2088
+ break;
2089
+ }
2090
+
2091
+ case 'br':
2092
+ {
2093
+ out += renderer.br();
2094
+ break;
2095
+ }
2096
+
2097
+ case 'del':
2098
+ {
2099
+ out += renderer.del(this.parseInline(token.tokens, renderer));
2100
+ break;
2101
+ }
2102
+
2103
+ case 'text':
2104
+ {
2105
+ out += renderer.text(token.text);
2106
+ break;
2107
+ }
2108
+
2109
+ default:
2110
+ {
2111
+ var errMsg = 'Token with "' + token.type + '" type was not found.';
2112
+
2113
+ if (this.options.silent) {
2114
+ console.error(errMsg);
2115
+ return;
2116
+ } else {
2117
+ throw new Error(errMsg);
2118
+ }
2119
+ }
2120
+ }
1296
2121
  }
1297
- }
1298
- }
1299
- };
1300
-
1301
- /**
1302
- * Slugger generates header id
1303
- */
1304
-
1305
- function Slugger() {
1306
- this.seen = {};
1307
- }
1308
2122
 
1309
- /**
1310
- * Convert string to unique id
1311
- */
1312
-
1313
- Slugger.prototype.slug = function(value) {
1314
- var slug = value
1315
- .toLowerCase()
1316
- .trim()
1317
- .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
1318
- .replace(/\s/g, '-');
1319
-
1320
- if (this.seen.hasOwnProperty(slug)) {
1321
- var originalSlug = slug;
1322
- do {
1323
- this.seen[originalSlug]++;
1324
- slug = originalSlug + '-' + this.seen[originalSlug];
1325
- } while (this.seen.hasOwnProperty(slug));
1326
- }
1327
- this.seen[slug] = 0;
1328
-
1329
- return slug;
1330
- };
1331
-
1332
- /**
1333
- * Helpers
1334
- */
2123
+ return out;
2124
+ };
1335
2125
 
1336
- function escape(html, encode) {
1337
- if (encode) {
1338
- if (escape.escapeTest.test(html)) {
1339
- return html.replace(escape.escapeReplace, function(ch) { return escape.replacements[ch]; });
1340
- }
1341
- } else {
1342
- if (escape.escapeTestNoEncode.test(html)) {
1343
- return html.replace(escape.escapeReplaceNoEncode, function(ch) { return escape.replacements[ch]; });
2126
+ return Parser;
2127
+ }();
2128
+
2129
+ var merge$2 = helpers.merge,
2130
+ checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation,
2131
+ escape$2 = helpers.escape;
2132
+ var getDefaults = defaults.getDefaults,
2133
+ changeDefaults = defaults.changeDefaults,
2134
+ defaults$5 = defaults.defaults;
2135
+ /**
2136
+ * Marked
2137
+ */
2138
+
2139
+ function marked(src, opt, callback) {
2140
+ // throw error in case of non string input
2141
+ if (typeof src === 'undefined' || src === null) {
2142
+ throw new Error('marked(): input parameter is undefined or null');
1344
2143
  }
1345
- }
1346
2144
 
1347
- return html;
1348
- }
1349
-
1350
- escape.escapeTest = /[&<>"']/;
1351
- escape.escapeReplace = /[&<>"']/g;
1352
- escape.replacements = {
1353
- '&': '&amp;',
1354
- '<': '&lt;',
1355
- '>': '&gt;',
1356
- '"': '&quot;',
1357
- "'": '&#39;'
1358
- };
1359
-
1360
- escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
1361
- escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
1362
-
1363
- function unescape(html) {
1364
- // explicitly match decimal, hex, and named HTML entities
1365
- return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) {
1366
- n = n.toLowerCase();
1367
- if (n === 'colon') return ':';
1368
- if (n.charAt(0) === '#') {
1369
- return n.charAt(1) === 'x'
1370
- ? String.fromCharCode(parseInt(n.substring(2), 16))
1371
- : String.fromCharCode(+n.substring(1));
1372
- }
1373
- return '';
1374
- });
1375
- }
1376
-
1377
- function edit(regex, opt) {
1378
- regex = regex.source || regex;
1379
- opt = opt || '';
1380
- return {
1381
- replace: function(name, val) {
1382
- val = val.source || val;
1383
- val = val.replace(/(^|[^\[])\^/g, '$1');
1384
- regex = regex.replace(name, val);
1385
- return this;
1386
- },
1387
- getRegex: function() {
1388
- return new RegExp(regex, opt);
2145
+ if (typeof src !== 'string') {
2146
+ throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
1389
2147
  }
1390
- };
1391
- }
1392
2148
 
1393
- function cleanUrl(sanitize, base, href) {
1394
- if (sanitize) {
1395
- try {
1396
- var prot = decodeURIComponent(unescape(href))
1397
- .replace(/[^\w:]/g, '')
1398
- .toLowerCase();
1399
- } catch (e) {
1400
- return null;
1401
- }
1402
- if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
1403
- return null;
1404
- }
1405
- }
1406
- if (base && !originIndependentUrl.test(href)) {
1407
- href = resolveUrl(base, href);
1408
- }
1409
- try {
1410
- href = encodeURI(href).replace(/%25/g, '%');
1411
- } catch (e) {
1412
- return null;
1413
- }
1414
- return href;
1415
- }
1416
-
1417
- function resolveUrl(base, href) {
1418
- if (!baseUrls[' ' + base]) {
1419
- // we can ignore everything in base after the last slash of its path component,
1420
- // but we might need to add _that_
1421
- // https://tools.ietf.org/html/rfc3986#section-3
1422
- if (/^[^:]+:\/*[^/]*$/.test(base)) {
1423
- baseUrls[' ' + base] = base + '/';
1424
- } else {
1425
- baseUrls[' ' + base] = rtrim(base, '/', true);
1426
- }
1427
- }
1428
- base = baseUrls[' ' + base];
1429
-
1430
- if (href.slice(0, 2) === '//') {
1431
- return base.replace(/:[\s\S]*/, ':') + href;
1432
- } else if (href.charAt(0) === '/') {
1433
- return base.replace(/(:\/*[^/]*)[\s\S]*/, '$1') + href;
1434
- } else {
1435
- return base + href;
1436
- }
1437
- }
1438
- var baseUrls = {};
1439
- var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
1440
-
1441
- function noop() {}
1442
- noop.exec = noop;
1443
-
1444
- function merge(obj) {
1445
- var i = 1,
1446
- target,
1447
- key;
1448
-
1449
- for (; i < arguments.length; i++) {
1450
- target = arguments[i];
1451
- for (key in target) {
1452
- if (Object.prototype.hasOwnProperty.call(target, key)) {
1453
- obj[key] = target[key];
1454
- }
1455
- }
1456
- }
2149
+ if (callback || typeof opt === 'function') {
2150
+ var _ret = function () {
2151
+ if (!callback) {
2152
+ callback = opt;
2153
+ opt = null;
2154
+ }
1457
2155
 
1458
- return obj;
1459
- }
1460
-
1461
- function splitCells(tableRow, count) {
1462
- // ensure that every cell-delimiting pipe has a space
1463
- // before it to distinguish it from an escaped pipe
1464
- var row = tableRow.replace(/\|/g, function(match, offset, str) {
1465
- var escaped = false,
1466
- curr = offset;
1467
- while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
1468
- if (escaped) {
1469
- // odd number of slashes means | is escaped
1470
- // so we leave it alone
1471
- return '|';
1472
- } else {
1473
- // add space before unescaped |
1474
- return ' |';
2156
+ opt = merge$2({}, marked.defaults, opt || {});
2157
+ checkSanitizeDeprecation$1(opt);
2158
+ var highlight = opt.highlight;
2159
+ var tokens,
2160
+ pending,
2161
+ i = 0;
2162
+
2163
+ try {
2164
+ tokens = Lexer_1.lex(src, opt);
2165
+ } catch (e) {
2166
+ return {
2167
+ v: callback(e)
2168
+ };
1475
2169
  }
1476
- }),
1477
- cells = row.split(/ \|/),
1478
- i = 0;
1479
-
1480
- if (cells.length > count) {
1481
- cells.splice(count);
1482
- } else {
1483
- while (cells.length < count) cells.push('');
1484
- }
1485
2170
 
1486
- for (; i < cells.length; i++) {
1487
- // leading or trailing whitespace is ignored per the gfm spec
1488
- cells[i] = cells[i].trim().replace(/\\\|/g, '|');
1489
- }
1490
- return cells;
1491
- }
1492
-
1493
- // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
1494
- // /c*$/ is vulnerable to REDOS.
1495
- // invert: Remove suffix of non-c chars instead. Default falsey.
1496
- function rtrim(str, c, invert) {
1497
- if (str.length === 0) {
1498
- return '';
1499
- }
2171
+ pending = tokens.length;
1500
2172
 
1501
- // Length of suffix matching the invert condition.
1502
- var suffLen = 0;
2173
+ var done = function done(err) {
2174
+ if (err) {
2175
+ opt.highlight = highlight;
2176
+ return callback(err);
2177
+ }
1503
2178
 
1504
- // Step left until we fail to match the invert condition.
1505
- while (suffLen < str.length) {
1506
- var currChar = str.charAt(str.length - suffLen - 1);
1507
- if (currChar === c && !invert) {
1508
- suffLen++;
1509
- } else if (currChar !== c && invert) {
1510
- suffLen++;
1511
- } else {
1512
- break;
1513
- }
1514
- }
2179
+ var out;
1515
2180
 
1516
- return str.substr(0, str.length - suffLen);
1517
- }
2181
+ try {
2182
+ out = Parser_1.parse(tokens, opt);
2183
+ } catch (e) {
2184
+ err = e;
2185
+ }
1518
2186
 
1519
- function findClosingBracket(str, b) {
1520
- if (str.indexOf(b[1]) === -1) {
1521
- return -1;
1522
- }
1523
- var level = 0;
1524
- for (var i = 0; i < str.length; i++) {
1525
- if (str[i] === '\\') {
1526
- i++;
1527
- } else if (str[i] === b[0]) {
1528
- level++;
1529
- } else if (str[i] === b[1]) {
1530
- level--;
1531
- if (level < 0) {
1532
- return i;
1533
- }
1534
- }
1535
- }
1536
- return -1;
1537
- }
2187
+ opt.highlight = highlight;
2188
+ return err ? callback(err) : callback(null, out);
2189
+ };
1538
2190
 
1539
- function checkSanitizeDeprecation(opt) {
1540
- if (opt && opt.sanitize && !opt.silent) {
1541
- 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');
1542
- }
1543
- }
2191
+ if (!highlight || highlight.length < 3) {
2192
+ return {
2193
+ v: done()
2194
+ };
2195
+ }
1544
2196
 
1545
- /**
1546
- * Marked
1547
- */
2197
+ delete opt.highlight;
2198
+ if (!pending) return {
2199
+ v: done()
2200
+ };
1548
2201
 
1549
- function marked(src, opt, callback) {
1550
- // throw error in case of non string input
1551
- if (typeof src === 'undefined' || src === null) {
1552
- throw new Error('marked(): input parameter is undefined or null');
1553
- }
1554
- if (typeof src !== 'string') {
1555
- throw new Error('marked(): input parameter is of type '
1556
- + Object.prototype.toString.call(src) + ', string expected');
1557
- }
2202
+ for (; i < tokens.length; i++) {
2203
+ (function (token) {
2204
+ if (token.type !== 'code') {
2205
+ return --pending || done();
2206
+ }
1558
2207
 
1559
- if (callback || typeof opt === 'function') {
1560
- if (!callback) {
1561
- callback = opt;
1562
- opt = null;
1563
- }
2208
+ return highlight(token.text, token.lang, function (err, code) {
2209
+ if (err) return done(err);
1564
2210
 
1565
- opt = merge({}, marked.defaults, opt || {});
1566
- checkSanitizeDeprecation(opt);
2211
+ if (code == null || code === token.text) {
2212
+ return --pending || done();
2213
+ }
1567
2214
 
1568
- var highlight = opt.highlight,
1569
- tokens,
1570
- pending,
1571
- i = 0;
2215
+ token.text = code;
2216
+ token.escaped = true;
2217
+ --pending || done();
2218
+ });
2219
+ })(tokens[i]);
2220
+ }
2221
+
2222
+ return {
2223
+ v: void 0
2224
+ };
2225
+ }();
2226
+
2227
+ if (typeof _ret === "object") return _ret.v;
2228
+ }
1572
2229
 
1573
2230
  try {
1574
- tokens = Lexer.lex(src, opt);
2231
+ opt = merge$2({}, marked.defaults, opt || {});
2232
+ checkSanitizeDeprecation$1(opt);
2233
+ return Parser_1.parse(Lexer_1.lex(src, opt), opt);
1575
2234
  } catch (e) {
1576
- return callback(e);
2235
+ e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2236
+
2237
+ if ((opt || marked.defaults).silent) {
2238
+ return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
2239
+ }
2240
+
2241
+ throw e;
1577
2242
  }
2243
+ }
2244
+ /**
2245
+ * Options
2246
+ */
1578
2247
 
1579
- pending = tokens.length;
1580
2248
 
1581
- var done = function(err) {
1582
- if (err) {
1583
- opt.highlight = highlight;
1584
- return callback(err);
1585
- }
2249
+ marked.options = marked.setOptions = function (opt) {
2250
+ merge$2(marked.defaults, opt);
2251
+ changeDefaults(marked.defaults);
2252
+ return marked;
2253
+ };
1586
2254
 
1587
- var out;
2255
+ marked.getDefaults = getDefaults;
2256
+ marked.defaults = defaults$5;
2257
+ /**
2258
+ * Use Extension
2259
+ */
1588
2260
 
1589
- try {
1590
- out = Parser.parse(tokens, opt);
1591
- } catch (e) {
1592
- err = e;
1593
- }
2261
+ marked.use = function (extension) {
2262
+ var opts = merge$2({}, extension);
1594
2263
 
1595
- opt.highlight = highlight;
2264
+ if (extension.renderer) {
2265
+ (function () {
2266
+ var renderer = marked.defaults.renderer || new Renderer_1();
1596
2267
 
1597
- return err
1598
- ? callback(err)
1599
- : callback(null, out);
1600
- };
2268
+ var _loop = function _loop(prop) {
2269
+ var prevRenderer = renderer[prop];
1601
2270
 
1602
- if (!highlight || highlight.length < 3) {
1603
- return done();
1604
- }
2271
+ renderer[prop] = function () {
2272
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2273
+ args[_key] = arguments[_key];
2274
+ }
2275
+
2276
+ var ret = extension.renderer[prop].apply(renderer, args);
1605
2277
 
1606
- delete opt.highlight;
2278
+ if (ret === false) {
2279
+ ret = prevRenderer.apply(renderer, args);
2280
+ }
1607
2281
 
1608
- if (!pending) return done();
2282
+ return ret;
2283
+ };
2284
+ };
1609
2285
 
1610
- for (; i < tokens.length; i++) {
1611
- (function(token) {
1612
- if (token.type !== 'code') {
1613
- return --pending || done();
2286
+ for (var prop in extension.renderer) {
2287
+ _loop(prop);
1614
2288
  }
1615
- return highlight(token.text, token.lang, function(err, code) {
1616
- if (err) return done(err);
1617
- if (code == null || code === token.text) {
1618
- return --pending || done();
1619
- }
1620
- token.text = code;
1621
- token.escaped = true;
1622
- --pending || done();
1623
- });
1624
- })(tokens[i]);
1625
- }
1626
2289
 
1627
- return;
1628
- }
1629
- try {
1630
- if (opt) opt = merge({}, marked.defaults, opt);
1631
- checkSanitizeDeprecation(opt);
1632
- return Parser.parse(Lexer.lex(src, opt), opt);
1633
- } catch (e) {
1634
- e.message += '\nPlease report this to https://github.com/markedjs/marked.';
1635
- if ((opt || marked.defaults).silent) {
1636
- return '<p>An error occurred:</p><pre>'
1637
- + escape(e.message + '', true)
1638
- + '</pre>';
2290
+ opts.renderer = renderer;
2291
+ })();
1639
2292
  }
1640
- throw e;
1641
- }
1642
- }
1643
2293
 
1644
- /**
1645
- * Options
1646
- */
2294
+ if (extension.tokenizer) {
2295
+ (function () {
2296
+ var tokenizer = marked.defaults.tokenizer || new Tokenizer_1();
1647
2297
 
1648
- marked.options =
1649
- marked.setOptions = function(opt) {
1650
- merge(marked.defaults, opt);
1651
- return marked;
1652
- };
1653
-
1654
- marked.getDefaults = function() {
1655
- return {
1656
- baseUrl: null,
1657
- breaks: false,
1658
- gfm: true,
1659
- headerIds: true,
1660
- headerPrefix: '',
1661
- highlight: null,
1662
- langPrefix: 'language-',
1663
- mangle: true,
1664
- pedantic: false,
1665
- renderer: new Renderer(),
1666
- sanitize: false,
1667
- sanitizer: null,
1668
- silent: false,
1669
- smartLists: false,
1670
- smartypants: false,
1671
- xhtml: false
1672
- };
1673
- };
2298
+ var _loop2 = function _loop2(prop) {
2299
+ var prevTokenizer = tokenizer[prop];
1674
2300
 
1675
- marked.defaults = marked.getDefaults();
2301
+ tokenizer[prop] = function () {
2302
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2303
+ args[_key2] = arguments[_key2];
2304
+ }
1676
2305
 
1677
- /**
1678
- * Expose
1679
- */
2306
+ var ret = extension.tokenizer[prop].apply(tokenizer, args);
2307
+
2308
+ if (ret === false) {
2309
+ ret = prevTokenizer.apply(tokenizer, args);
2310
+ }
2311
+
2312
+ return ret;
2313
+ };
2314
+ };
1680
2315
 
1681
- marked.Parser = Parser;
1682
- marked.parser = Parser.parse;
2316
+ for (var prop in extension.tokenizer) {
2317
+ _loop2(prop);
2318
+ }
1683
2319
 
1684
- marked.Renderer = Renderer;
1685
- marked.TextRenderer = TextRenderer;
2320
+ opts.tokenizer = tokenizer;
2321
+ })();
2322
+ }
1686
2323
 
1687
- marked.Lexer = Lexer;
1688
- marked.lexer = Lexer.lex;
2324
+ marked.setOptions(opts);
2325
+ };
2326
+ /**
2327
+ * Expose
2328
+ */
1689
2329
 
1690
- marked.InlineLexer = InlineLexer;
1691
- marked.inlineLexer = InlineLexer.output;
1692
2330
 
1693
- marked.Slugger = Slugger;
2331
+ marked.Parser = Parser_1;
2332
+ marked.parser = Parser_1.parse;
2333
+ marked.Renderer = Renderer_1;
2334
+ marked.TextRenderer = TextRenderer_1;
2335
+ marked.Lexer = Lexer_1;
2336
+ marked.lexer = Lexer_1.lex;
2337
+ marked.Tokenizer = Tokenizer_1;
2338
+ marked.Slugger = Slugger_1;
2339
+ marked.parse = marked;
2340
+ var marked_1 = marked;
1694
2341
 
1695
- marked.parse = marked;
2342
+ return marked_1;
1696
2343
 
1697
- if (typeof module !== 'undefined' && typeof exports === 'object') {
1698
- module.exports = marked;
1699
- } else if (typeof define === 'function' && define.amd) {
1700
- define(function() { return marked; });
1701
- } else {
1702
- root.marked = marked;
1703
- }
1704
- })(this || (typeof window !== 'undefined' ? window : global));
2344
+ })));