marked 0.6.3 → 0.8.2

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,1700 +1,1790 @@
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: noop,
18
- hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
19
- heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
20
- nptable: noop,
21
- blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
22
- list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
23
- html: '^ {0,3}(?:' // optional indentation
24
- + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
25
- + '|comment[^\\n]*(\\n+|$)' // (2)
26
- + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
27
- + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
28
- + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
29
- + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
30
- + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
31
- + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
32
- + ')',
33
- def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
34
- table: noop,
35
- lheading: /^([^\n]+)\n {0,3}(=|-){2,} *(?:\n+|$)/,
36
- paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading| {0,3}>|<\/?(?:tag)(?: +|\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)*)/,
37
- text: /^[^\n]+/
38
- };
39
-
40
- block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
41
- block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
42
- block.def = edit(block.def)
43
- .replace('label', block._label)
44
- .replace('title', block._title)
45
- .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
+ }
46
27
 
47
- block.bullet = /(?:[*+-]|\d{1,9}\.)/;
48
- block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
49
- block.item = edit(block.item, 'gm')
50
- .replace(/bull/g, block.bullet)
51
- .getRegex();
28
+ function _createClass(Constructor, protoProps, staticProps) {
29
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
30
+ if (staticProps) _defineProperties(Constructor, staticProps);
31
+ return Constructor;
32
+ }
52
33
 
53
- block.list = edit(block.list)
54
- .replace(/bull/g, block.bullet)
55
- .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
56
- .replace('def', '\\n+(?=' + block.def.source + ')')
57
- .getRegex();
34
+ function createCommonjsModule(fn, module) {
35
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
36
+ }
58
37
 
59
- block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
60
- + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
61
- + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
62
- + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
63
- + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
64
- + '|track|ul';
65
- block._comment = /<!--(?!-?>)[\s\S]*?-->/;
66
- block.html = edit(block.html, 'i')
67
- .replace('comment', block._comment)
68
- .replace('tag', block._tag)
69
- .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
70
- .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
+ xhtml: false
57
+ };
58
+ }
71
59
 
72
- block.paragraph = edit(block.paragraph)
73
- .replace('hr', block.hr)
74
- .replace('heading', block.heading)
75
- .replace('lheading', block.lheading)
76
- .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
77
- .getRegex();
60
+ function changeDefaults(newDefaults) {
61
+ module.exports.defaults = newDefaults;
62
+ }
78
63
 
79
- block.blockquote = edit(block.blockquote)
80
- .replace('paragraph', block.paragraph)
81
- .getRegex();
64
+ module.exports = {
65
+ defaults: getDefaults(),
66
+ getDefaults: getDefaults,
67
+ changeDefaults: changeDefaults
68
+ };
69
+ });
70
+ var defaults_1 = defaults.defaults;
71
+ var defaults_2 = defaults.getDefaults;
72
+ var defaults_3 = defaults.changeDefaults;
73
+
74
+ /**
75
+ * Helpers
76
+ */
77
+ var escapeTest = /[&<>"']/;
78
+ var escapeReplace = /[&<>"']/g;
79
+ var escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
80
+ var escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
81
+ var escapeReplacements = {
82
+ '&': '&amp;',
83
+ '<': '&lt;',
84
+ '>': '&gt;',
85
+ '"': '&quot;',
86
+ "'": '&#39;'
87
+ };
82
88
 
83
- /**
84
- * Normal Block Grammar
85
- */
89
+ var getEscapeReplacement = function getEscapeReplacement(ch) {
90
+ return escapeReplacements[ch];
91
+ };
86
92
 
87
- block.normal = merge({}, block);
93
+ function escape(html, encode) {
94
+ if (encode) {
95
+ if (escapeTest.test(html)) {
96
+ return html.replace(escapeReplace, getEscapeReplacement);
97
+ }
98
+ } else {
99
+ if (escapeTestNoEncode.test(html)) {
100
+ return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
101
+ }
102
+ }
88
103
 
89
- /**
90
- * GFM Block Grammar
91
- */
104
+ return html;
105
+ }
92
106
 
93
- block.gfm = merge({}, block.normal, {
94
- fences: /^ {0,3}(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
95
- paragraph: /^/,
96
- heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
97
- });
107
+ var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
98
108
 
99
- block.gfm.paragraph = edit(block.paragraph)
100
- .replace('(?!', '(?!'
101
- + block.gfm.fences.source.replace('\\1', '\\2') + '|'
102
- + block.list.source.replace('\\1', '\\3') + '|')
103
- .getRegex();
109
+ function unescape(html) {
110
+ // explicitly match decimal, hex, and named HTML entities
111
+ return html.replace(unescapeTest, function (_, n) {
112
+ n = n.toLowerCase();
113
+ if (n === 'colon') return ':';
104
114
 
105
- /**
106
- * GFM + Tables Block Grammar
107
- */
115
+ if (n.charAt(0) === '#') {
116
+ return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
117
+ }
108
118
 
109
- block.tables = merge({}, block.gfm, {
110
- nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,
111
- table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/
112
- });
119
+ return '';
120
+ });
121
+ }
113
122
 
114
- /**
115
- * Pedantic grammar
116
- */
123
+ var caret = /(^|[^\[])\^/g;
124
+
125
+ function edit(regex, opt) {
126
+ regex = regex.source || regex;
127
+ opt = opt || '';
128
+ var obj = {
129
+ replace: function replace(name, val) {
130
+ val = val.source || val;
131
+ val = val.replace(caret, '$1');
132
+ regex = regex.replace(name, val);
133
+ return obj;
134
+ },
135
+ getRegex: function getRegex() {
136
+ return new RegExp(regex, opt);
137
+ }
138
+ };
139
+ return obj;
140
+ }
117
141
 
118
- block.pedantic = merge({}, block.normal, {
119
- html: edit(
120
- '^ *(?:comment *(?:\\n|\\s*$)'
121
- + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
122
- + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
123
- .replace('comment', block._comment)
124
- .replace(/tag/g, '(?!(?:'
125
- + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
126
- + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
127
- + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
128
- .getRegex(),
129
- def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/
130
- });
142
+ var nonWordAndColonTest = /[^\w:]/g;
143
+ var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
131
144
 
132
- /**
133
- * Block Lexer
134
- */
145
+ function cleanUrl(sanitize, base, href) {
146
+ if (sanitize) {
147
+ var prot;
135
148
 
136
- function Lexer(options) {
137
- this.tokens = [];
138
- this.tokens.links = Object.create(null);
139
- this.options = options || marked.defaults;
140
- this.rules = block.normal;
141
-
142
- if (this.options.pedantic) {
143
- this.rules = block.pedantic;
144
- } else if (this.options.gfm) {
145
- if (this.options.tables) {
146
- this.rules = block.tables;
147
- } else {
148
- this.rules = block.gfm;
149
+ try {
150
+ prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, '').toLowerCase();
151
+ } catch (e) {
152
+ return null;
153
+ }
154
+
155
+ if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
156
+ return null;
157
+ }
149
158
  }
159
+
160
+ if (base && !originIndependentUrl.test(href)) {
161
+ href = resolveUrl(base, href);
162
+ }
163
+
164
+ try {
165
+ href = encodeURI(href).replace(/%25/g, '%');
166
+ } catch (e) {
167
+ return null;
168
+ }
169
+
170
+ return href;
150
171
  }
151
- }
152
172
 
153
- /**
154
- * Expose Block Rules
155
- */
173
+ var baseUrls = {};
174
+ var justDomain = /^[^:]+:\/*[^/]*$/;
175
+ var protocol = /^([^:]+:)[\s\S]*$/;
176
+ var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
177
+
178
+ function resolveUrl(base, href) {
179
+ if (!baseUrls[' ' + base]) {
180
+ // we can ignore everything in base after the last slash of its path component,
181
+ // but we might need to add _that_
182
+ // https://tools.ietf.org/html/rfc3986#section-3
183
+ if (justDomain.test(base)) {
184
+ baseUrls[' ' + base] = base + '/';
185
+ } else {
186
+ baseUrls[' ' + base] = rtrim(base, '/', true);
187
+ }
188
+ }
156
189
 
157
- Lexer.rules = block;
190
+ base = baseUrls[' ' + base];
191
+ var relativeBase = base.indexOf(':') === -1;
158
192
 
159
- /**
160
- * Static Lex Method
161
- */
193
+ if (href.substring(0, 2) === '//') {
194
+ if (relativeBase) {
195
+ return href;
196
+ }
162
197
 
163
- Lexer.lex = function(src, options) {
164
- var lexer = new Lexer(options);
165
- return lexer.lex(src);
166
- };
198
+ return base.replace(protocol, '$1') + href;
199
+ } else if (href.charAt(0) === '/') {
200
+ if (relativeBase) {
201
+ return href;
202
+ }
167
203
 
168
- /**
169
- * Preprocessing
170
- */
204
+ return base.replace(domain, '$1') + href;
205
+ } else {
206
+ return base + href;
207
+ }
208
+ }
171
209
 
172
- Lexer.prototype.lex = function(src) {
173
- src = src
174
- .replace(/\r\n|\r/g, '\n')
175
- .replace(/\t/g, ' ')
176
- .replace(/\u00a0/g, ' ')
177
- .replace(/\u2424/g, '\n');
210
+ var noopTest = {
211
+ exec: function noopTest() {}
212
+ };
178
213
 
179
- return this.token(src, true);
180
- };
214
+ function merge(obj) {
215
+ var i = 1,
216
+ target,
217
+ key;
181
218
 
182
- /**
183
- * Lexing
184
- */
219
+ for (; i < arguments.length; i++) {
220
+ target = arguments[i];
185
221
 
186
- Lexer.prototype.token = function(src, top) {
187
- src = src.replace(/^ +$/gm, '');
188
- var next,
189
- loose,
190
- cap,
191
- bull,
192
- b,
193
- item,
194
- listStart,
195
- listItems,
196
- t,
197
- space,
198
- i,
199
- tag,
200
- l,
201
- isordered,
202
- istask,
203
- ischecked;
204
-
205
- while (src) {
206
- // newline
207
- if (cap = this.rules.newline.exec(src)) {
208
- src = src.substring(cap[0].length);
209
- if (cap[0].length > 1) {
210
- this.tokens.push({
211
- type: 'space'
212
- });
222
+ for (key in target) {
223
+ if (Object.prototype.hasOwnProperty.call(target, key)) {
224
+ obj[key] = target[key];
225
+ }
213
226
  }
214
227
  }
215
228
 
216
- // code
217
- if (cap = this.rules.code.exec(src)) {
218
- var lastToken = this.tokens[this.tokens.length - 1];
219
- src = src.substring(cap[0].length);
220
- // An indented code block cannot interrupt a paragraph.
221
- if (lastToken && lastToken.type === 'paragraph') {
222
- lastToken.text += '\n' + cap[0].trimRight();
229
+ return obj;
230
+ }
231
+
232
+ function splitCells(tableRow, count) {
233
+ // ensure that every cell-delimiting pipe has a space
234
+ // before it to distinguish it from an escaped pipe
235
+ var row = tableRow.replace(/\|/g, function (match, offset, str) {
236
+ var escaped = false,
237
+ curr = offset;
238
+
239
+ while (--curr >= 0 && str[curr] === '\\') {
240
+ escaped = !escaped;
241
+ }
242
+
243
+ if (escaped) {
244
+ // odd number of slashes means | is escaped
245
+ // so we leave it alone
246
+ return '|';
223
247
  } else {
224
- cap = cap[0].replace(/^ {4}/gm, '');
225
- this.tokens.push({
226
- type: 'code',
227
- codeBlockStyle: 'indented',
228
- text: !this.options.pedantic
229
- ? rtrim(cap, '\n')
230
- : cap
231
- });
248
+ // add space before unescaped |
249
+ return ' |';
232
250
  }
233
- continue;
234
- }
251
+ }),
252
+ cells = row.split(/ \|/);
253
+ var i = 0;
235
254
 
236
- // fences (gfm)
237
- if (cap = this.rules.fences.exec(src)) {
238
- src = src.substring(cap[0].length);
239
- this.tokens.push({
240
- type: 'code',
241
- lang: cap[2] ? cap[2].trim() : cap[2],
242
- text: cap[3] || ''
243
- });
244
- continue;
255
+ if (cells.length > count) {
256
+ cells.splice(count);
257
+ } else {
258
+ while (cells.length < count) {
259
+ cells.push('');
260
+ }
245
261
  }
246
262
 
247
- // heading
248
- if (cap = this.rules.heading.exec(src)) {
249
- src = src.substring(cap[0].length);
250
- this.tokens.push({
251
- type: 'heading',
252
- depth: cap[1].length,
253
- text: cap[2]
254
- });
255
- continue;
263
+ for (; i < cells.length; i++) {
264
+ // leading or trailing whitespace is ignored per the gfm spec
265
+ cells[i] = cells[i].trim().replace(/\\\|/g, '|');
256
266
  }
257
267
 
258
- // table no leading pipe (gfm)
259
- if (cap = this.rules.nptable.exec(src)) {
260
- item = {
261
- type: 'table',
262
- header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
263
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
264
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
265
- };
268
+ return cells;
269
+ } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
270
+ // /c*$/ is vulnerable to REDOS.
271
+ // invert: Remove suffix of non-c chars instead. Default falsey.
266
272
 
267
- if (item.header.length === item.align.length) {
268
- src = src.substring(cap[0].length);
269
273
 
270
- for (i = 0; i < item.align.length; i++) {
271
- if (/^ *-+: *$/.test(item.align[i])) {
272
- item.align[i] = 'right';
273
- } else if (/^ *:-+: *$/.test(item.align[i])) {
274
- item.align[i] = 'center';
275
- } else if (/^ *:-+ *$/.test(item.align[i])) {
276
- item.align[i] = 'left';
277
- } else {
278
- item.align[i] = null;
279
- }
280
- }
274
+ function rtrim(str, c, invert) {
275
+ var l = str.length;
276
+
277
+ if (l === 0) {
278
+ return '';
279
+ } // Length of suffix matching the invert condition.
281
280
 
282
- for (i = 0; i < item.cells.length; i++) {
283
- item.cells[i] = splitCells(item.cells[i], item.header.length);
284
- }
285
281
 
286
- this.tokens.push(item);
282
+ var suffLen = 0; // Step left until we fail to match the invert condition.
287
283
 
288
- continue;
284
+ while (suffLen < l) {
285
+ var currChar = str.charAt(l - suffLen - 1);
286
+
287
+ if (currChar === c && !invert) {
288
+ suffLen++;
289
+ } else if (currChar !== c && invert) {
290
+ suffLen++;
291
+ } else {
292
+ break;
289
293
  }
290
294
  }
291
295
 
292
- // hr
293
- if (cap = this.rules.hr.exec(src)) {
294
- src = src.substring(cap[0].length);
295
- this.tokens.push({
296
- type: 'hr'
297
- });
298
- continue;
299
- }
296
+ return str.substr(0, l - suffLen);
297
+ }
300
298
 
301
- // blockquote
302
- if (cap = this.rules.blockquote.exec(src)) {
303
- src = src.substring(cap[0].length);
299
+ function findClosingBracket(str, b) {
300
+ if (str.indexOf(b[1]) === -1) {
301
+ return -1;
302
+ }
304
303
 
305
- this.tokens.push({
306
- type: 'blockquote_start'
307
- });
304
+ var l = str.length;
305
+ var level = 0,
306
+ i = 0;
308
307
 
309
- cap = cap[0].replace(/^ *> ?/gm, '');
308
+ for (; i < l; i++) {
309
+ if (str[i] === '\\') {
310
+ i++;
311
+ } else if (str[i] === b[0]) {
312
+ level++;
313
+ } else if (str[i] === b[1]) {
314
+ level--;
310
315
 
311
- // Pass `top` to keep the current
312
- // "toplevel" state. This is exactly
313
- // how markdown.pl works.
314
- this.token(cap, top);
316
+ if (level < 0) {
317
+ return i;
318
+ }
319
+ }
320
+ }
315
321
 
316
- this.tokens.push({
317
- type: 'blockquote_end'
318
- });
322
+ return -1;
323
+ }
319
324
 
320
- continue;
325
+ function checkSanitizeDeprecation(opt) {
326
+ if (opt && opt.sanitize && !opt.silent) {
327
+ 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');
321
328
  }
329
+ }
322
330
 
323
- // list
324
- if (cap = this.rules.list.exec(src)) {
325
- src = src.substring(cap[0].length);
326
- bull = cap[2];
327
- isordered = bull.length > 1;
328
-
329
- listStart = {
330
- type: 'list_start',
331
- ordered: isordered,
332
- start: isordered ? +bull : '',
333
- loose: false
334
- };
331
+ var helpers = {
332
+ escape: escape,
333
+ unescape: unescape,
334
+ edit: edit,
335
+ cleanUrl: cleanUrl,
336
+ resolveUrl: resolveUrl,
337
+ noopTest: noopTest,
338
+ merge: merge,
339
+ splitCells: splitCells,
340
+ rtrim: rtrim,
341
+ findClosingBracket: findClosingBracket,
342
+ checkSanitizeDeprecation: checkSanitizeDeprecation
343
+ };
344
+
345
+ var noopTest$1 = helpers.noopTest,
346
+ edit$1 = helpers.edit,
347
+ merge$1 = helpers.merge;
348
+ /**
349
+ * Block-Level Grammar
350
+ */
351
+
352
+ var block = {
353
+ newline: /^\n+/,
354
+ code: /^( {4}[^\n]+\n*)+/,
355
+ fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
356
+ hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
357
+ heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
358
+ blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
359
+ list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
360
+ html: '^ {0,3}(?:' // optional indentation
361
+ + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
362
+ + '|comment[^\\n]*(\\n+|$)' // (2)
363
+ + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
364
+ + '|<![A-Z][\\s\\S]*?>\\n*' // (4)
365
+ + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
366
+ + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
367
+ + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
368
+ + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
369
+ + ')',
370
+ def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
371
+ nptable: noopTest$1,
372
+ table: noopTest$1,
373
+ lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
374
+ // regex template, placeholders will be replaced according to different paragraph
375
+ // interruption rules of commonmark and the original markdown spec:
376
+ _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
377
+ text: /^[^\n]+/
378
+ };
379
+ block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
380
+ block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
381
+ block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex();
382
+ block.bullet = /(?:[*+-]|\d{1,9}\.)/;
383
+ block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
384
+ block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex();
385
+ 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();
386
+ 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';
387
+ block._comment = /<!--(?!-?>)[\s\S]*?-->/;
388
+ 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();
389
+ 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
390
+ .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
391
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
392
+ .getRegex();
393
+ block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex();
394
+ /**
395
+ * Normal Block Grammar
396
+ */
397
+
398
+ block.normal = merge$1({}, block);
399
+ /**
400
+ * GFM Block Grammar
401
+ */
402
+
403
+ block.gfm = merge$1({}, block.normal, {
404
+ nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
405
+ + ' *([-:]+ *\\|[-| :]*)' // Align
406
+ + '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)',
407
+ // Cells
408
+ table: '^ *\\|(.+)\\n' // Header
409
+ + ' *\\|?( *[-:]+[-| :]*)' // Align
410
+ + '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
411
+
412
+ });
413
+ 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
414
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
415
+ .getRegex();
416
+ 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
417
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
418
+ .getRegex();
419
+ /**
420
+ * Pedantic grammar (original John Gruber's loose markdown specification)
421
+ */
422
+
423
+ block.pedantic = merge$1({}, block.normal, {
424
+ html: edit$1('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
425
+ + '|<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(),
426
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
427
+ heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
428
+ fences: noopTest$1,
429
+ // fences not supported
430
+ 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()
431
+ });
432
+ /**
433
+ * Inline-Level Grammar
434
+ */
435
+
436
+ var inline = {
437
+ escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
438
+ autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
439
+ url: noopTest$1,
440
+ tag: '^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
441
+ + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
442
+ + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
443
+ + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
444
+ + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
445
+ // CDATA section
446
+ link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
447
+ reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
448
+ nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
449
+ strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
450
+ em: /^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
451
+ code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
452
+ br: /^( {2,}|\\)\n(?!\s*$)/,
453
+ del: noopTest$1,
454
+ text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
455
+ }; // list of punctuation marks from common mark spec
456
+ // without ` and ] to workaround Rule 17 (inline code blocks/links)
457
+
458
+ inline._punctuation = '!"#$%&\'()*+,\\-./:;<=>?@\\[^_{|}~';
459
+ inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
460
+ inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
461
+ inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
462
+ 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])?)+(?![-_])/;
463
+ inline.autolink = edit$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex();
464
+ inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
465
+ inline.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex();
466
+ inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
467
+ inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
468
+ inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
469
+ inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex();
470
+ inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex();
471
+ /**
472
+ * Normal Inline Grammar
473
+ */
474
+
475
+ inline.normal = merge$1({}, inline);
476
+ /**
477
+ * Pedantic Inline Grammar
478
+ */
479
+
480
+ inline.pedantic = merge$1({}, inline.normal, {
481
+ strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
482
+ em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
483
+ link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
484
+ reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
485
+ });
486
+ /**
487
+ * GFM Inline Grammar
488
+ */
489
+
490
+ inline.gfm = merge$1({}, inline.normal, {
491
+ escape: edit$1(inline.escape).replace('])', '~|])').getRegex(),
492
+ _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
493
+ url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
494
+ _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
495
+ del: /^~+(?=\S)([\s\S]*?\S)~+/,
496
+ text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
497
+ });
498
+ inline.gfm.url = edit$1(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
499
+ /**
500
+ * GFM + Line Breaks Inline Grammar
501
+ */
502
+
503
+ inline.breaks = merge$1({}, inline.gfm, {
504
+ br: edit$1(inline.br).replace('{2,}', '*').getRegex(),
505
+ text: edit$1(inline.gfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
506
+ });
507
+ var rules = {
508
+ block: block,
509
+ inline: inline
510
+ };
335
511
 
336
- this.tokens.push(listStart);
512
+ var defaults$1 = defaults.defaults;
513
+ var block$1 = rules.block;
514
+ var rtrim$1 = helpers.rtrim,
515
+ splitCells$1 = helpers.splitCells,
516
+ escape$1 = helpers.escape;
517
+ /**
518
+ * Block Lexer
519
+ */
520
+
521
+ var Lexer_1 = /*#__PURE__*/function () {
522
+ function Lexer(options) {
523
+ this.tokens = [];
524
+ this.tokens.links = Object.create(null);
525
+ this.options = options || defaults$1;
526
+ this.rules = block$1.normal;
337
527
 
338
- // Get each top-level item.
339
- cap = cap[0].match(this.rules.item);
528
+ if (this.options.pedantic) {
529
+ this.rules = block$1.pedantic;
530
+ } else if (this.options.gfm) {
531
+ this.rules = block$1.gfm;
532
+ }
533
+ }
534
+ /**
535
+ * Expose Block Rules
536
+ */
340
537
 
341
- listItems = [];
342
- next = false;
343
- l = cap.length;
344
- i = 0;
345
538
 
346
- for (; i < l; i++) {
347
- item = cap[i];
348
-
349
- // Remove the list item's bullet
350
- // so it is seen as the next token.
351
- space = item.length;
352
- item = item.replace(/^ *([*+-]|\d+\.) */, '');
353
-
354
- // Outdent whatever the
355
- // list item contains. Hacky.
356
- if (~item.indexOf('\n ')) {
357
- space -= item.length;
358
- item = !this.options.pedantic
359
- ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
360
- : item.replace(/^ {1,4}/gm, '');
361
- }
539
+ /**
540
+ * Static Lex Method
541
+ */
542
+ Lexer.lex = function lex(src, options) {
543
+ var lexer = new Lexer(options);
544
+ return lexer.lex(src);
545
+ };
362
546
 
363
- // Determine whether the next list item belongs here.
364
- // Backpedal if it does not belong in this list.
365
- if (i !== l - 1) {
366
- b = block.bullet.exec(cap[i + 1])[0];
367
- if (bull.length > 1 ? b.length === 1
368
- : (b.length > 1 || (this.options.smartLists && b !== bull))) {
369
- src = cap.slice(i + 1).join('\n') + src;
370
- i = l - 1;
547
+ var _proto = Lexer.prototype;
548
+
549
+ /**
550
+ * Preprocessing
551
+ */
552
+ _proto.lex = function lex(src) {
553
+ src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
554
+ return this.token(src, true);
555
+ };
556
+
557
+ /**
558
+ * Lexing
559
+ */
560
+ _proto.token = function token(src, top) {
561
+ src = src.replace(/^ +$/gm, '');
562
+ var next, loose, cap, bull, b, item, listStart, listItems, t, space, i, tag, l, isordered, istask, ischecked;
563
+
564
+ while (src) {
565
+ // newline
566
+ if (cap = this.rules.newline.exec(src)) {
567
+ src = src.substring(cap[0].length);
568
+
569
+ if (cap[0].length > 1) {
570
+ this.tokens.push({
571
+ type: 'space'
572
+ });
371
573
  }
372
- }
574
+ } // code
373
575
 
374
- // Determine whether item is loose or not.
375
- // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
376
- // for discount behavior.
377
- loose = next || /\n\n(?!\s*$)/.test(item);
378
- if (i !== l - 1) {
379
- next = item.charAt(item.length - 1) === '\n';
380
- if (!loose) loose = next;
381
- }
382
576
 
383
- if (loose) {
384
- listStart.loose = true;
385
- }
577
+ if (cap = this.rules.code.exec(src)) {
578
+ var lastToken = this.tokens[this.tokens.length - 1];
579
+ src = src.substring(cap[0].length); // An indented code block cannot interrupt a paragraph.
386
580
 
387
- // Check for task list items
388
- istask = /^\[[ xX]\] /.test(item);
389
- ischecked = undefined;
390
- if (istask) {
391
- ischecked = item[1] !== ' ';
392
- item = item.replace(/^\[[ xX]\] +/, '');
393
- }
581
+ if (lastToken && lastToken.type === 'paragraph') {
582
+ lastToken.text += '\n' + cap[0].trimRight();
583
+ } else {
584
+ cap = cap[0].replace(/^ {4}/gm, '');
585
+ this.tokens.push({
586
+ type: 'code',
587
+ codeBlockStyle: 'indented',
588
+ text: !this.options.pedantic ? rtrim$1(cap, '\n') : cap
589
+ });
590
+ }
394
591
 
395
- t = {
396
- type: 'list_item_start',
397
- task: istask,
398
- checked: ischecked,
399
- loose: loose
400
- };
592
+ continue;
593
+ } // fences
594
+
595
+
596
+ if (cap = this.rules.fences.exec(src)) {
597
+ src = src.substring(cap[0].length);
598
+ this.tokens.push({
599
+ type: 'code',
600
+ lang: cap[2] ? cap[2].trim() : cap[2],
601
+ text: cap[3] || ''
602
+ });
603
+ continue;
604
+ } // heading
605
+
606
+
607
+ if (cap = this.rules.heading.exec(src)) {
608
+ src = src.substring(cap[0].length);
609
+ this.tokens.push({
610
+ type: 'heading',
611
+ depth: cap[1].length,
612
+ text: cap[2]
613
+ });
614
+ continue;
615
+ } // table no leading pipe (gfm)
616
+
617
+
618
+ if (cap = this.rules.nptable.exec(src)) {
619
+ item = {
620
+ type: 'table',
621
+ header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
622
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
623
+ cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
624
+ };
625
+
626
+ if (item.header.length === item.align.length) {
627
+ src = src.substring(cap[0].length);
628
+
629
+ for (i = 0; i < item.align.length; i++) {
630
+ if (/^ *-+: *$/.test(item.align[i])) {
631
+ item.align[i] = 'right';
632
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
633
+ item.align[i] = 'center';
634
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
635
+ item.align[i] = 'left';
636
+ } else {
637
+ item.align[i] = null;
638
+ }
639
+ }
640
+
641
+ for (i = 0; i < item.cells.length; i++) {
642
+ item.cells[i] = splitCells$1(item.cells[i], item.header.length);
643
+ }
644
+
645
+ this.tokens.push(item);
646
+ continue;
647
+ }
648
+ } // hr
649
+
650
+
651
+ if (cap = this.rules.hr.exec(src)) {
652
+ src = src.substring(cap[0].length);
653
+ this.tokens.push({
654
+ type: 'hr'
655
+ });
656
+ continue;
657
+ } // blockquote
658
+
659
+
660
+ if (cap = this.rules.blockquote.exec(src)) {
661
+ src = src.substring(cap[0].length);
662
+ this.tokens.push({
663
+ type: 'blockquote_start'
664
+ });
665
+ cap = cap[0].replace(/^ *> ?/gm, ''); // Pass `top` to keep the current
666
+ // "toplevel" state. This is exactly
667
+ // how markdown.pl works.
668
+
669
+ this.token(cap, top);
670
+ this.tokens.push({
671
+ type: 'blockquote_end'
672
+ });
673
+ continue;
674
+ } // list
675
+
676
+
677
+ if (cap = this.rules.list.exec(src)) {
678
+ src = src.substring(cap[0].length);
679
+ bull = cap[2];
680
+ isordered = bull.length > 1;
681
+ listStart = {
682
+ type: 'list_start',
683
+ ordered: isordered,
684
+ start: isordered ? +bull : '',
685
+ loose: false
686
+ };
687
+ this.tokens.push(listStart); // Get each top-level item.
688
+
689
+ cap = cap[0].match(this.rules.item);
690
+ listItems = [];
691
+ next = false;
692
+ l = cap.length;
693
+ i = 0;
694
+
695
+ for (; i < l; i++) {
696
+ item = cap[i]; // Remove the list item's bullet
697
+ // so it is seen as the next token.
698
+
699
+ space = item.length;
700
+ item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the
701
+ // list item contains. Hacky.
702
+
703
+ if (~item.indexOf('\n ')) {
704
+ space -= item.length;
705
+ item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
706
+ } // Determine whether the next list item belongs here.
707
+ // Backpedal if it does not belong in this list.
708
+
709
+
710
+ if (i !== l - 1) {
711
+ b = block$1.bullet.exec(cap[i + 1])[0];
712
+
713
+ if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) {
714
+ src = cap.slice(i + 1).join('\n') + src;
715
+ i = l - 1;
716
+ }
717
+ } // Determine whether item is loose or not.
718
+ // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
719
+ // for discount behavior.
720
+
721
+
722
+ loose = next || /\n\n(?!\s*$)/.test(item);
723
+
724
+ if (i !== l - 1) {
725
+ next = item.charAt(item.length - 1) === '\n';
726
+ if (!loose) loose = next;
727
+ }
728
+
729
+ if (loose) {
730
+ listStart.loose = true;
731
+ } // Check for task list items
732
+
733
+
734
+ istask = /^\[[ xX]\] /.test(item);
735
+ ischecked = undefined;
736
+
737
+ if (istask) {
738
+ ischecked = item[1] !== ' ';
739
+ item = item.replace(/^\[[ xX]\] +/, '');
740
+ }
741
+
742
+ t = {
743
+ type: 'list_item_start',
744
+ task: istask,
745
+ checked: ischecked,
746
+ loose: loose
747
+ };
748
+ listItems.push(t);
749
+ this.tokens.push(t); // Recurse.
750
+
751
+ this.token(item, false);
752
+ this.tokens.push({
753
+ type: 'list_item_end'
754
+ });
755
+ }
401
756
 
402
- listItems.push(t);
403
- this.tokens.push(t);
757
+ if (listStart.loose) {
758
+ l = listItems.length;
759
+ i = 0;
404
760
 
405
- // Recurse.
406
- this.token(item, false);
761
+ for (; i < l; i++) {
762
+ listItems[i].loose = true;
763
+ }
764
+ }
407
765
 
408
- this.tokens.push({
409
- type: 'list_item_end'
410
- });
411
- }
766
+ this.tokens.push({
767
+ type: 'list_end'
768
+ });
769
+ continue;
770
+ } // html
771
+
772
+
773
+ if (cap = this.rules.html.exec(src)) {
774
+ src = src.substring(cap[0].length);
775
+ this.tokens.push({
776
+ type: this.options.sanitize ? 'paragraph' : 'html',
777
+ pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
778
+ text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0]) : cap[0]
779
+ });
780
+ continue;
781
+ } // def
782
+
783
+
784
+ if (top && (cap = this.rules.def.exec(src))) {
785
+ src = src.substring(cap[0].length);
786
+ if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
787
+ tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
788
+
789
+ if (!this.tokens.links[tag]) {
790
+ this.tokens.links[tag] = {
791
+ href: cap[2],
792
+ title: cap[3]
793
+ };
794
+ }
412
795
 
413
- if (listStart.loose) {
414
- l = listItems.length;
415
- i = 0;
416
- for (; i < l; i++) {
417
- listItems[i].loose = true;
796
+ continue;
797
+ } // table (gfm)
798
+
799
+
800
+ if (cap = this.rules.table.exec(src)) {
801
+ item = {
802
+ type: 'table',
803
+ header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
804
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
805
+ cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
806
+ };
807
+
808
+ if (item.header.length === item.align.length) {
809
+ src = src.substring(cap[0].length);
810
+
811
+ for (i = 0; i < item.align.length; i++) {
812
+ if (/^ *-+: *$/.test(item.align[i])) {
813
+ item.align[i] = 'right';
814
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
815
+ item.align[i] = 'center';
816
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
817
+ item.align[i] = 'left';
818
+ } else {
819
+ item.align[i] = null;
820
+ }
821
+ }
822
+
823
+ for (i = 0; i < item.cells.length; i++) {
824
+ item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
825
+ }
826
+
827
+ this.tokens.push(item);
828
+ continue;
829
+ }
830
+ } // lheading
831
+
832
+
833
+ if (cap = this.rules.lheading.exec(src)) {
834
+ src = src.substring(cap[0].length);
835
+ this.tokens.push({
836
+ type: 'heading',
837
+ depth: cap[2].charAt(0) === '=' ? 1 : 2,
838
+ text: cap[1]
839
+ });
840
+ continue;
841
+ } // top-level paragraph
842
+
843
+
844
+ if (top && (cap = this.rules.paragraph.exec(src))) {
845
+ src = src.substring(cap[0].length);
846
+ this.tokens.push({
847
+ type: 'paragraph',
848
+ text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
849
+ });
850
+ continue;
851
+ } // text
852
+
853
+
854
+ if (cap = this.rules.text.exec(src)) {
855
+ // Top-level should never reach here.
856
+ src = src.substring(cap[0].length);
857
+ this.tokens.push({
858
+ type: 'text',
859
+ text: cap[0]
860
+ });
861
+ continue;
862
+ }
863
+
864
+ if (src) {
865
+ throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
418
866
  }
419
867
  }
420
868
 
421
- this.tokens.push({
422
- type: 'list_end'
423
- });
869
+ return this.tokens;
870
+ };
424
871
 
425
- continue;
426
- }
872
+ _createClass(Lexer, null, [{
873
+ key: "rules",
874
+ get: function get() {
875
+ return block$1;
876
+ }
877
+ }]);
427
878
 
428
- // html
429
- if (cap = this.rules.html.exec(src)) {
430
- src = src.substring(cap[0].length);
431
- this.tokens.push({
432
- type: this.options.sanitize
433
- ? 'paragraph'
434
- : 'html',
435
- pre: !this.options.sanitizer
436
- && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
437
- text: cap[0]
438
- });
439
- continue;
440
- }
879
+ return Lexer;
880
+ }();
441
881
 
442
- // def
443
- if (top && (cap = this.rules.def.exec(src))) {
444
- src = src.substring(cap[0].length);
445
- if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
446
- tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
447
- if (!this.tokens.links[tag]) {
448
- this.tokens.links[tag] = {
449
- href: cap[2],
450
- title: cap[3]
451
- };
452
- }
453
- continue;
882
+ var defaults$2 = defaults.defaults;
883
+ var cleanUrl$1 = helpers.cleanUrl,
884
+ escape$2 = helpers.escape;
885
+ /**
886
+ * Renderer
887
+ */
888
+
889
+ var Renderer_1 = /*#__PURE__*/function () {
890
+ function Renderer(options) {
891
+ this.options = options || defaults$2;
454
892
  }
455
893
 
456
- // table (gfm)
457
- if (cap = this.rules.table.exec(src)) {
458
- item = {
459
- type: 'table',
460
- header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
461
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
462
- cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
463
- };
894
+ var _proto = Renderer.prototype;
464
895
 
465
- if (item.header.length === item.align.length) {
466
- src = src.substring(cap[0].length);
896
+ _proto.code = function code(_code, infostring, escaped) {
897
+ var lang = (infostring || '').match(/\S*/)[0];
467
898
 
468
- for (i = 0; i < item.align.length; 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
- }
899
+ if (this.options.highlight) {
900
+ var out = this.options.highlight(_code, lang);
479
901
 
480
- for (i = 0; i < item.cells.length; i++) {
481
- item.cells[i] = splitCells(
482
- item.cells[i].replace(/^ *\| *| *\| *$/g, ''),
483
- item.header.length);
902
+ if (out != null && out !== _code) {
903
+ escaped = true;
904
+ _code = out;
484
905
  }
906
+ }
485
907
 
486
- this.tokens.push(item);
487
-
488
- continue;
908
+ if (!lang) {
909
+ return '<pre><code>' + (escaped ? _code : escape$2(_code, true)) + '</code></pre>';
489
910
  }
490
- }
491
911
 
492
- // lheading
493
- if (cap = this.rules.lheading.exec(src)) {
494
- src = src.substring(cap[0].length);
495
- this.tokens.push({
496
- type: 'heading',
497
- depth: cap[2] === '=' ? 1 : 2,
498
- text: cap[1]
499
- });
500
- continue;
501
- }
912
+ return '<pre><code class="' + this.options.langPrefix + escape$2(lang, true) + '">' + (escaped ? _code : escape$2(_code, true)) + '</code></pre>\n';
913
+ };
502
914
 
503
- // top-level paragraph
504
- if (top && (cap = this.rules.paragraph.exec(src))) {
505
- src = src.substring(cap[0].length);
506
- this.tokens.push({
507
- type: 'paragraph',
508
- text: cap[1].charAt(cap[1].length - 1) === '\n'
509
- ? cap[1].slice(0, -1)
510
- : cap[1]
511
- });
512
- continue;
513
- }
915
+ _proto.blockquote = function blockquote(quote) {
916
+ return '<blockquote>\n' + quote + '</blockquote>\n';
917
+ };
514
918
 
515
- // text
516
- if (cap = this.rules.text.exec(src)) {
517
- // Top-level should never reach here.
518
- src = src.substring(cap[0].length);
519
- this.tokens.push({
520
- type: 'text',
521
- text: cap[0]
522
- });
523
- continue;
524
- }
919
+ _proto.html = function html(_html) {
920
+ return _html;
921
+ };
525
922
 
526
- if (src) {
527
- throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
528
- }
529
- }
923
+ _proto.heading = function heading(text, level, raw, slugger) {
924
+ if (this.options.headerIds) {
925
+ return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n';
926
+ } // ignore IDs
530
927
 
531
- return this.tokens;
532
- };
533
928
 
534
- /**
535
- * Inline-Level Grammar
536
- */
929
+ return '<h' + level + '>' + text + '</h' + level + '>\n';
930
+ };
537
931
 
538
- var inline = {
539
- escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
540
- autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
541
- url: noop,
542
- tag: '^comment'
543
- + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
544
- + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
545
- + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
546
- + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
547
- + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section
548
- link: /^!?\[(label)\]\(href(?:\s+(title))?\s*\)/,
549
- reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
550
- nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
551
- strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
552
- em: /^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
553
- code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
554
- br: /^( {2,}|\\)\n(?!\s*$)/,
555
- del: noop,
556
- text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
557
- };
558
-
559
- // list of punctuation marks from common mark spec
560
- // without ` and ] to workaround Rule 17 (inline code blocks/links)
561
- inline._punctuation = '!"#$%&\'()*+,\\-./:;<=>?@\\[^_{|}~';
562
- inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
563
-
564
- inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
565
-
566
- inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
567
- 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])?)+(?![-_])/;
568
- inline.autolink = edit(inline.autolink)
569
- .replace('scheme', inline._scheme)
570
- .replace('email', inline._email)
571
- .getRegex();
932
+ _proto.hr = function hr() {
933
+ return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
934
+ };
572
935
 
573
- inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
936
+ _proto.list = function list(body, ordered, start) {
937
+ var type = ordered ? 'ol' : 'ul',
938
+ startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
939
+ return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
940
+ };
574
941
 
575
- inline.tag = edit(inline.tag)
576
- .replace('comment', block._comment)
577
- .replace('attribute', inline._attribute)
578
- .getRegex();
942
+ _proto.listitem = function listitem(text) {
943
+ return '<li>' + text + '</li>\n';
944
+ };
579
945
 
580
- inline._label = /(?:\[[^\[\]]*\]|\\[\[\]]?|`[^`]*`|`(?!`)|[^\[\]\\`])*?/;
581
- inline._href = /\s*(<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*)/;
582
- inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
946
+ _proto.checkbox = function checkbox(checked) {
947
+ return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
948
+ };
583
949
 
584
- inline.link = edit(inline.link)
585
- .replace('label', inline._label)
586
- .replace('href', inline._href)
587
- .replace('title', inline._title)
588
- .getRegex();
950
+ _proto.paragraph = function paragraph(text) {
951
+ return '<p>' + text + '</p>\n';
952
+ };
589
953
 
590
- inline.reflink = edit(inline.reflink)
591
- .replace('label', inline._label)
592
- .getRegex();
954
+ _proto.table = function table(header, body) {
955
+ if (body) body = '<tbody>' + body + '</tbody>';
956
+ return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
957
+ };
593
958
 
594
- /**
595
- * Normal Inline Grammar
596
- */
959
+ _proto.tablerow = function tablerow(content) {
960
+ return '<tr>\n' + content + '</tr>\n';
961
+ };
597
962
 
598
- inline.normal = merge({}, inline);
963
+ _proto.tablecell = function tablecell(content, flags) {
964
+ var type = flags.header ? 'th' : 'td';
965
+ var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
966
+ return tag + content + '</' + type + '>\n';
967
+ };
599
968
 
600
- /**
601
- * Pedantic Inline Grammar
602
- */
969
+ // span level renderer
970
+ _proto.strong = function strong(text) {
971
+ return '<strong>' + text + '</strong>';
972
+ };
973
+
974
+ _proto.em = function em(text) {
975
+ return '<em>' + text + '</em>';
976
+ };
603
977
 
604
- inline.pedantic = merge({}, inline.normal, {
605
- strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
606
- em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
607
- link: edit(/^!?\[(label)\]\((.*?)\)/)
608
- .replace('label', inline._label)
609
- .getRegex(),
610
- reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
611
- .replace('label', inline._label)
612
- .getRegex()
613
- });
978
+ _proto.codespan = function codespan(text) {
979
+ return '<code>' + text + '</code>';
980
+ };
614
981
 
615
- /**
616
- * GFM Inline Grammar
617
- */
982
+ _proto.br = function br() {
983
+ return this.options.xhtml ? '<br/>' : '<br>';
984
+ };
618
985
 
619
- inline.gfm = merge({}, inline.normal, {
620
- escape: edit(inline.escape).replace('])', '~|])').getRegex(),
621
- _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
622
- url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
623
- _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
624
- del: /^~+(?=\S)([\s\S]*?\S)~+/,
625
- text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
626
- });
627
-
628
- inline.gfm.url = edit(inline.gfm.url, 'i')
629
- .replace('email', inline.gfm._extended_email)
630
- .getRegex();
631
- /**
632
- * GFM + Line Breaks Inline Grammar
633
- */
986
+ _proto.del = function del(text) {
987
+ return '<del>' + text + '</del>';
988
+ };
634
989
 
635
- inline.breaks = merge({}, inline.gfm, {
636
- br: edit(inline.br).replace('{2,}', '*').getRegex(),
637
- text: edit(inline.gfm.text)
638
- .replace('\\b_', '\\b_| {2,}\\n')
639
- .replace(/\{2,\}/g, '*')
640
- .getRegex()
641
- });
990
+ _proto.link = function link(href, title, text) {
991
+ href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
642
992
 
643
- /**
644
- * Inline Lexer & Compiler
645
- */
993
+ if (href === null) {
994
+ return text;
995
+ }
646
996
 
647
- function InlineLexer(links, options) {
648
- this.options = options || marked.defaults;
649
- this.links = links;
650
- this.rules = inline.normal;
651
- this.renderer = this.options.renderer || new Renderer();
652
- this.renderer.options = this.options;
997
+ var out = '<a href="' + escape$2(href) + '"';
653
998
 
654
- if (!this.links) {
655
- throw new Error('Tokens array requires a `links` property.');
656
- }
999
+ if (title) {
1000
+ out += ' title="' + title + '"';
1001
+ }
657
1002
 
658
- if (this.options.pedantic) {
659
- this.rules = inline.pedantic;
660
- } else if (this.options.gfm) {
661
- if (this.options.breaks) {
662
- this.rules = inline.breaks;
663
- } else {
664
- this.rules = inline.gfm;
665
- }
666
- }
667
- }
1003
+ out += '>' + text + '</a>';
1004
+ return out;
1005
+ };
668
1006
 
669
- /**
670
- * Expose Inline Rules
671
- */
1007
+ _proto.image = function image(href, title, text) {
1008
+ href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
672
1009
 
673
- InlineLexer.rules = inline;
1010
+ if (href === null) {
1011
+ return text;
1012
+ }
674
1013
 
675
- /**
676
- * Static Lexing/Compiling Method
677
- */
1014
+ var out = '<img src="' + href + '" alt="' + text + '"';
678
1015
 
679
- InlineLexer.output = function(src, links, options) {
680
- var inline = new InlineLexer(links, options);
681
- return inline.output(src);
682
- };
1016
+ if (title) {
1017
+ out += ' title="' + title + '"';
1018
+ }
683
1019
 
684
- /**
685
- * Lexing/Compiling
686
- */
1020
+ out += this.options.xhtml ? '/>' : '>';
1021
+ return out;
1022
+ };
1023
+
1024
+ _proto.text = function text(_text) {
1025
+ return _text;
1026
+ };
687
1027
 
688
- InlineLexer.prototype.output = function(src) {
689
- var out = '',
690
- link,
691
- text,
692
- href,
693
- title,
694
- cap,
695
- prevCapZero;
696
-
697
- while (src) {
698
- // escape
699
- if (cap = this.rules.escape.exec(src)) {
700
- src = src.substring(cap[0].length);
701
- out += escape(cap[1]);
702
- continue;
1028
+ return Renderer;
1029
+ }();
1030
+
1031
+ /**
1032
+ * Slugger generates header id
1033
+ */
1034
+ var Slugger_1 = /*#__PURE__*/function () {
1035
+ function Slugger() {
1036
+ this.seen = {};
703
1037
  }
1038
+ /**
1039
+ * Convert string to unique id
1040
+ */
704
1041
 
705
- // tag
706
- if (cap = this.rules.tag.exec(src)) {
707
- if (!this.inLink && /^<a /i.test(cap[0])) {
708
- this.inLink = true;
709
- } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
710
- this.inLink = false;
711
- }
712
- if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
713
- this.inRawBlock = true;
714
- } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
715
- this.inRawBlock = false;
1042
+
1043
+ var _proto = Slugger.prototype;
1044
+
1045
+ _proto.slug = function slug(value) {
1046
+ var slug = value.toLowerCase().trim() // remove html tags
1047
+ .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
1048
+ .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
1049
+
1050
+ if (this.seen.hasOwnProperty(slug)) {
1051
+ var originalSlug = slug;
1052
+
1053
+ do {
1054
+ this.seen[originalSlug]++;
1055
+ slug = originalSlug + '-' + this.seen[originalSlug];
1056
+ } while (this.seen.hasOwnProperty(slug));
716
1057
  }
717
1058
 
718
- src = src.substring(cap[0].length);
719
- out += this.options.sanitize
720
- ? this.options.sanitizer
721
- ? this.options.sanitizer(cap[0])
722
- : escape(cap[0])
723
- : cap[0];
724
- continue;
725
- }
1059
+ this.seen[slug] = 0;
1060
+ return slug;
1061
+ };
726
1062
 
727
- // link
728
- if (cap = this.rules.link.exec(src)) {
729
- var lastParenIndex = findClosingBracket(cap[2], '()');
730
- if (lastParenIndex > -1) {
731
- var linkLen = cap[0].length - (cap[2].length - lastParenIndex) - (cap[3] || '').length;
732
- cap[2] = cap[2].substring(0, lastParenIndex);
733
- cap[0] = cap[0].substring(0, linkLen).trim();
734
- cap[3] = '';
1063
+ return Slugger;
1064
+ }();
1065
+
1066
+ var defaults$3 = defaults.defaults;
1067
+ var inline$1 = rules.inline;
1068
+ var findClosingBracket$1 = helpers.findClosingBracket,
1069
+ escape$3 = helpers.escape;
1070
+ /**
1071
+ * Inline Lexer & Compiler
1072
+ */
1073
+
1074
+ var InlineLexer_1 = /*#__PURE__*/function () {
1075
+ function InlineLexer(links, options) {
1076
+ this.options = options || defaults$3;
1077
+ this.links = links;
1078
+ this.rules = inline$1.normal;
1079
+ this.options.renderer = this.options.renderer || new Renderer_1();
1080
+ this.renderer = this.options.renderer;
1081
+ this.renderer.options = this.options;
1082
+
1083
+ if (!this.links) {
1084
+ throw new Error('Tokens array requires a `links` property.');
735
1085
  }
736
- src = src.substring(cap[0].length);
737
- this.inLink = true;
738
- href = cap[2];
739
- if (this.options.pedantic) {
740
- link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
741
1086
 
742
- if (link) {
743
- href = link[1];
744
- title = link[3];
1087
+ if (this.options.pedantic) {
1088
+ this.rules = inline$1.pedantic;
1089
+ } else if (this.options.gfm) {
1090
+ if (this.options.breaks) {
1091
+ this.rules = inline$1.breaks;
745
1092
  } else {
746
- title = '';
1093
+ this.rules = inline$1.gfm;
747
1094
  }
748
- } else {
749
- title = cap[3] ? cap[3].slice(1, -1) : '';
750
1095
  }
751
- href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
752
- out += this.outputLink(cap, {
753
- href: InlineLexer.escapes(href),
754
- title: InlineLexer.escapes(title)
755
- });
756
- this.inLink = false;
757
- continue;
758
1096
  }
1097
+ /**
1098
+ * Expose Inline Rules
1099
+ */
759
1100
 
760
- // reflink, nolink
761
- if ((cap = this.rules.reflink.exec(src))
762
- || (cap = this.rules.nolink.exec(src))) {
763
- src = src.substring(cap[0].length);
764
- link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
765
- link = this.links[link.toLowerCase()];
766
- if (!link || !link.href) {
767
- out += cap[0].charAt(0);
768
- src = cap[0].substring(1) + src;
769
- continue;
770
- }
771
- this.inLink = true;
772
- out += this.outputLink(cap, link);
773
- this.inLink = false;
774
- continue;
775
- }
776
1101
 
777
- // strong
778
- if (cap = this.rules.strong.exec(src)) {
779
- src = src.substring(cap[0].length);
780
- out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1]));
781
- continue;
1102
+ /**
1103
+ * Static Lexing/Compiling Method
1104
+ */
1105
+ InlineLexer.output = function output(src, links, options) {
1106
+ var inline = new InlineLexer(links, options);
1107
+ return inline.output(src);
782
1108
  }
1109
+ /**
1110
+ * Lexing/Compiling
1111
+ */
1112
+ ;
1113
+
1114
+ var _proto = InlineLexer.prototype;
1115
+
1116
+ _proto.output = function output(src) {
1117
+ var out = '',
1118
+ link,
1119
+ text,
1120
+ href,
1121
+ title,
1122
+ cap,
1123
+ prevCapZero;
1124
+
1125
+ while (src) {
1126
+ // escape
1127
+ if (cap = this.rules.escape.exec(src)) {
1128
+ src = src.substring(cap[0].length);
1129
+ out += escape$3(cap[1]);
1130
+ continue;
1131
+ } // tag
1132
+
1133
+
1134
+ if (cap = this.rules.tag.exec(src)) {
1135
+ if (!this.inLink && /^<a /i.test(cap[0])) {
1136
+ this.inLink = true;
1137
+ } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
1138
+ this.inLink = false;
1139
+ }
783
1140
 
784
- // em
785
- if (cap = this.rules.em.exec(src)) {
786
- src = src.substring(cap[0].length);
787
- out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]));
788
- continue;
789
- }
1141
+ if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
1142
+ this.inRawBlock = true;
1143
+ } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
1144
+ this.inRawBlock = false;
1145
+ }
790
1146
 
791
- // code
792
- if (cap = this.rules.code.exec(src)) {
793
- src = src.substring(cap[0].length);
794
- out += this.renderer.codespan(escape(cap[2].trim(), true));
795
- continue;
796
- }
1147
+ src = src.substring(cap[0].length);
1148
+ out += this.renderer.html(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]);
1149
+ continue;
1150
+ } // link
797
1151
 
798
- // br
799
- if (cap = this.rules.br.exec(src)) {
800
- src = src.substring(cap[0].length);
801
- out += this.renderer.br();
802
- continue;
803
- }
804
1152
 
805
- // del (gfm)
806
- if (cap = this.rules.del.exec(src)) {
807
- src = src.substring(cap[0].length);
808
- out += this.renderer.del(this.output(cap[1]));
809
- continue;
810
- }
1153
+ if (cap = this.rules.link.exec(src)) {
1154
+ var lastParenIndex = findClosingBracket$1(cap[2], '()');
811
1155
 
812
- // autolink
813
- if (cap = this.rules.autolink.exec(src)) {
814
- src = src.substring(cap[0].length);
815
- if (cap[2] === '@') {
816
- text = escape(this.mangle(cap[1]));
817
- href = 'mailto:' + text;
818
- } else {
819
- text = escape(cap[1]);
820
- href = text;
821
- }
822
- out += this.renderer.link(href, null, text);
823
- continue;
824
- }
1156
+ if (lastParenIndex > -1) {
1157
+ var start = cap[0].indexOf('!') === 0 ? 5 : 4;
1158
+ var linkLen = start + cap[1].length + lastParenIndex;
1159
+ cap[2] = cap[2].substring(0, lastParenIndex);
1160
+ cap[0] = cap[0].substring(0, linkLen).trim();
1161
+ cap[3] = '';
1162
+ }
825
1163
 
826
- // url (gfm)
827
- if (!this.inLink && (cap = this.rules.url.exec(src))) {
828
- if (cap[2] === '@') {
829
- text = escape(cap[0]);
830
- href = 'mailto:' + text;
831
- } else {
832
- // do extended autolink path validation
833
- do {
834
- prevCapZero = cap[0];
835
- cap[0] = this.rules._backpedal.exec(cap[0])[0];
836
- } while (prevCapZero !== cap[0]);
837
- text = escape(cap[0]);
838
- if (cap[1] === 'www.') {
839
- href = 'http://' + text;
840
- } else {
841
- href = text;
842
- }
843
- }
844
- src = src.substring(cap[0].length);
845
- out += this.renderer.link(href, null, text);
846
- continue;
847
- }
1164
+ src = src.substring(cap[0].length);
1165
+ this.inLink = true;
1166
+ href = cap[2];
848
1167
 
849
- // text
850
- if (cap = this.rules.text.exec(src)) {
851
- src = src.substring(cap[0].length);
852
- if (this.inRawBlock) {
853
- out += this.renderer.text(cap[0]);
854
- } else {
855
- out += this.renderer.text(escape(this.smartypants(cap[0])));
856
- }
857
- continue;
858
- }
1168
+ if (this.options.pedantic) {
1169
+ link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
859
1170
 
860
- if (src) {
861
- throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
862
- }
863
- }
1171
+ if (link) {
1172
+ href = link[1];
1173
+ title = link[3];
1174
+ } else {
1175
+ title = '';
1176
+ }
1177
+ } else {
1178
+ title = cap[3] ? cap[3].slice(1, -1) : '';
1179
+ }
864
1180
 
865
- return out;
866
- };
1181
+ href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
1182
+ out += this.outputLink(cap, {
1183
+ href: InlineLexer.escapes(href),
1184
+ title: InlineLexer.escapes(title)
1185
+ });
1186
+ this.inLink = false;
1187
+ continue;
1188
+ } // reflink, nolink
1189
+
1190
+
1191
+ if ((cap = this.rules.reflink.exec(src)) || (cap = this.rules.nolink.exec(src))) {
1192
+ src = src.substring(cap[0].length);
1193
+ link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
1194
+ link = this.links[link.toLowerCase()];
1195
+
1196
+ if (!link || !link.href) {
1197
+ out += cap[0].charAt(0);
1198
+ src = cap[0].substring(1) + src;
1199
+ continue;
1200
+ }
867
1201
 
868
- InlineLexer.escapes = function(text) {
869
- return text ? text.replace(InlineLexer.rules._escapes, '$1') : text;
870
- };
1202
+ this.inLink = true;
1203
+ out += this.outputLink(cap, link);
1204
+ this.inLink = false;
1205
+ continue;
1206
+ } // strong
871
1207
 
872
- /**
873
- * Compile Link
874
- */
875
1208
 
876
- InlineLexer.prototype.outputLink = function(cap, link) {
877
- var href = link.href,
878
- title = link.title ? escape(link.title) : null;
1209
+ if (cap = this.rules.strong.exec(src)) {
1210
+ src = src.substring(cap[0].length);
1211
+ out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1]));
1212
+ continue;
1213
+ } // em
879
1214
 
880
- return cap[0].charAt(0) !== '!'
881
- ? this.renderer.link(href, title, this.output(cap[1]))
882
- : this.renderer.image(href, title, escape(cap[1]));
883
- };
884
1215
 
885
- /**
886
- * Smartypants Transformations
887
- */
1216
+ if (cap = this.rules.em.exec(src)) {
1217
+ src = src.substring(cap[0].length);
1218
+ out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]));
1219
+ continue;
1220
+ } // code
888
1221
 
889
- InlineLexer.prototype.smartypants = function(text) {
890
- if (!this.options.smartypants) return text;
891
- return text
892
- // em-dashes
893
- .replace(/---/g, '\u2014')
894
- // en-dashes
895
- .replace(/--/g, '\u2013')
896
- // opening singles
897
- .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
898
- // closing singles & apostrophes
899
- .replace(/'/g, '\u2019')
900
- // opening doubles
901
- .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
902
- // closing doubles
903
- .replace(/"/g, '\u201d')
904
- // ellipses
905
- .replace(/\.{3}/g, '\u2026');
906
- };
907
1222
 
908
- /**
909
- * Mangle Links
910
- */
1223
+ if (cap = this.rules.code.exec(src)) {
1224
+ src = src.substring(cap[0].length);
1225
+ out += this.renderer.codespan(escape$3(cap[2].trim(), true));
1226
+ continue;
1227
+ } // br
911
1228
 
912
- InlineLexer.prototype.mangle = function(text) {
913
- if (!this.options.mangle) return text;
914
- var out = '',
915
- l = text.length,
916
- i = 0,
917
- ch;
918
-
919
- for (; i < l; i++) {
920
- ch = text.charCodeAt(i);
921
- if (Math.random() > 0.5) {
922
- ch = 'x' + ch.toString(16);
923
- }
924
- out += '&#' + ch + ';';
925
- }
926
1229
 
927
- return out;
928
- };
1230
+ if (cap = this.rules.br.exec(src)) {
1231
+ src = src.substring(cap[0].length);
1232
+ out += this.renderer.br();
1233
+ continue;
1234
+ } // del (gfm)
929
1235
 
930
- /**
931
- * Renderer
932
- */
933
1236
 
934
- function Renderer(options) {
935
- this.options = options || marked.defaults;
936
- }
937
-
938
- Renderer.prototype.code = function(code, infostring, escaped) {
939
- var lang = (infostring || '').match(/\S*/)[0];
940
- if (this.options.highlight) {
941
- var out = this.options.highlight(code, lang);
942
- if (out != null && out !== code) {
943
- escaped = true;
944
- code = out;
945
- }
946
- }
1237
+ if (cap = this.rules.del.exec(src)) {
1238
+ src = src.substring(cap[0].length);
1239
+ out += this.renderer.del(this.output(cap[1]));
1240
+ continue;
1241
+ } // autolink
947
1242
 
948
- if (!lang) {
949
- return '<pre><code>'
950
- + (escaped ? code : escape(code, true))
951
- + '</code></pre>';
952
- }
953
1243
 
954
- return '<pre><code class="'
955
- + this.options.langPrefix
956
- + escape(lang, true)
957
- + '">'
958
- + (escaped ? code : escape(code, true))
959
- + '</code></pre>\n';
960
- };
961
-
962
- Renderer.prototype.blockquote = function(quote) {
963
- return '<blockquote>\n' + quote + '</blockquote>\n';
964
- };
965
-
966
- Renderer.prototype.html = function(html) {
967
- return html;
968
- };
969
-
970
- Renderer.prototype.heading = function(text, level, raw, slugger) {
971
- if (this.options.headerIds) {
972
- return '<h'
973
- + level
974
- + ' id="'
975
- + this.options.headerPrefix
976
- + slugger.slug(raw)
977
- + '">'
978
- + text
979
- + '</h'
980
- + level
981
- + '>\n';
982
- }
983
- // ignore IDs
984
- return '<h' + level + '>' + text + '</h' + level + '>\n';
985
- };
986
-
987
- Renderer.prototype.hr = function() {
988
- return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
989
- };
990
-
991
- Renderer.prototype.list = function(body, ordered, start) {
992
- var type = ordered ? 'ol' : 'ul',
993
- startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
994
- return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
995
- };
996
-
997
- Renderer.prototype.listitem = function(text) {
998
- return '<li>' + text + '</li>\n';
999
- };
1000
-
1001
- Renderer.prototype.checkbox = function(checked) {
1002
- return '<input '
1003
- + (checked ? 'checked="" ' : '')
1004
- + 'disabled="" type="checkbox"'
1005
- + (this.options.xhtml ? ' /' : '')
1006
- + '> ';
1007
- };
1008
-
1009
- Renderer.prototype.paragraph = function(text) {
1010
- return '<p>' + text + '</p>\n';
1011
- };
1012
-
1013
- Renderer.prototype.table = function(header, body) {
1014
- if (body) body = '<tbody>' + body + '</tbody>';
1015
-
1016
- return '<table>\n'
1017
- + '<thead>\n'
1018
- + header
1019
- + '</thead>\n'
1020
- + body
1021
- + '</table>\n';
1022
- };
1023
-
1024
- Renderer.prototype.tablerow = function(content) {
1025
- return '<tr>\n' + content + '</tr>\n';
1026
- };
1027
-
1028
- Renderer.prototype.tablecell = function(content, flags) {
1029
- var type = flags.header ? 'th' : 'td';
1030
- var tag = flags.align
1031
- ? '<' + type + ' align="' + flags.align + '">'
1032
- : '<' + type + '>';
1033
- return tag + content + '</' + type + '>\n';
1034
- };
1035
-
1036
- // span level renderer
1037
- Renderer.prototype.strong = function(text) {
1038
- return '<strong>' + text + '</strong>';
1039
- };
1040
-
1041
- Renderer.prototype.em = function(text) {
1042
- return '<em>' + text + '</em>';
1043
- };
1044
-
1045
- Renderer.prototype.codespan = function(text) {
1046
- return '<code>' + text + '</code>';
1047
- };
1048
-
1049
- Renderer.prototype.br = function() {
1050
- return this.options.xhtml ? '<br/>' : '<br>';
1051
- };
1052
-
1053
- Renderer.prototype.del = function(text) {
1054
- return '<del>' + text + '</del>';
1055
- };
1056
-
1057
- Renderer.prototype.link = function(href, title, text) {
1058
- href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1059
- if (href === null) {
1060
- return text;
1061
- }
1062
- var out = '<a href="' + escape(href) + '"';
1063
- if (title) {
1064
- out += ' title="' + title + '"';
1065
- }
1066
- out += '>' + text + '</a>';
1067
- return out;
1068
- };
1069
-
1070
- Renderer.prototype.image = function(href, title, text) {
1071
- href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1072
- if (href === null) {
1073
- return text;
1074
- }
1244
+ if (cap = this.rules.autolink.exec(src)) {
1245
+ src = src.substring(cap[0].length);
1075
1246
 
1076
- var out = '<img src="' + href + '" alt="' + text + '"';
1077
- if (title) {
1078
- out += ' title="' + title + '"';
1079
- }
1080
- out += this.options.xhtml ? '/>' : '>';
1081
- return out;
1082
- };
1247
+ if (cap[2] === '@') {
1248
+ text = escape$3(this.mangle(cap[1]));
1249
+ href = 'mailto:' + text;
1250
+ } else {
1251
+ text = escape$3(cap[1]);
1252
+ href = text;
1253
+ }
1083
1254
 
1084
- Renderer.prototype.text = function(text) {
1085
- return text;
1086
- };
1255
+ out += this.renderer.link(href, null, text);
1256
+ continue;
1257
+ } // url (gfm)
1087
1258
 
1088
- /**
1089
- * TextRenderer
1090
- * returns only the textual part of the token
1091
- */
1092
1259
 
1093
- function TextRenderer() {}
1260
+ if (!this.inLink && (cap = this.rules.url.exec(src))) {
1261
+ if (cap[2] === '@') {
1262
+ text = escape$3(cap[0]);
1263
+ href = 'mailto:' + text;
1264
+ } else {
1265
+ // do extended autolink path validation
1266
+ do {
1267
+ prevCapZero = cap[0];
1268
+ cap[0] = this.rules._backpedal.exec(cap[0])[0];
1269
+ } while (prevCapZero !== cap[0]);
1270
+
1271
+ text = escape$3(cap[0]);
1272
+
1273
+ if (cap[1] === 'www.') {
1274
+ href = 'http://' + text;
1275
+ } else {
1276
+ href = text;
1277
+ }
1278
+ }
1094
1279
 
1095
- // no need for block level renderers
1280
+ src = src.substring(cap[0].length);
1281
+ out += this.renderer.link(href, null, text);
1282
+ continue;
1283
+ } // text
1096
1284
 
1097
- TextRenderer.prototype.strong =
1098
- TextRenderer.prototype.em =
1099
- TextRenderer.prototype.codespan =
1100
- TextRenderer.prototype.del =
1101
- TextRenderer.prototype.text = function(text) {
1102
- return text;
1103
- };
1104
1285
 
1105
- TextRenderer.prototype.link =
1106
- TextRenderer.prototype.image = function(href, title, text) {
1107
- return '' + text;
1108
- };
1286
+ if (cap = this.rules.text.exec(src)) {
1287
+ src = src.substring(cap[0].length);
1109
1288
 
1110
- TextRenderer.prototype.br = function() {
1111
- return '';
1112
- };
1289
+ if (this.inRawBlock) {
1290
+ out += this.renderer.text(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]);
1291
+ } else {
1292
+ out += this.renderer.text(escape$3(this.smartypants(cap[0])));
1293
+ }
1113
1294
 
1114
- /**
1115
- * Parsing & Compiling
1116
- */
1295
+ continue;
1296
+ }
1117
1297
 
1118
- function Parser(options) {
1119
- this.tokens = [];
1120
- this.token = null;
1121
- this.options = options || marked.defaults;
1122
- this.options.renderer = this.options.renderer || new Renderer();
1123
- this.renderer = this.options.renderer;
1124
- this.renderer.options = this.options;
1125
- this.slugger = new Slugger();
1126
- }
1298
+ if (src) {
1299
+ throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
1300
+ }
1301
+ }
1127
1302
 
1128
- /**
1129
- * Static Parse Method
1130
- */
1303
+ return out;
1304
+ };
1131
1305
 
1132
- Parser.parse = function(src, options) {
1133
- var parser = new Parser(options);
1134
- return parser.parse(src);
1135
- };
1306
+ InlineLexer.escapes = function escapes(text) {
1307
+ return text ? text.replace(InlineLexer.rules._escapes, '$1') : text;
1308
+ }
1309
+ /**
1310
+ * Compile Link
1311
+ */
1312
+ ;
1313
+
1314
+ _proto.outputLink = function outputLink(cap, link) {
1315
+ var href = link.href,
1316
+ title = link.title ? escape$3(link.title) : null;
1317
+ return cap[0].charAt(0) !== '!' ? this.renderer.link(href, title, this.output(cap[1])) : this.renderer.image(href, title, escape$3(cap[1]));
1318
+ }
1319
+ /**
1320
+ * Smartypants Transformations
1321
+ */
1322
+ ;
1323
+
1324
+ _proto.smartypants = function smartypants(text) {
1325
+ if (!this.options.smartypants) return text;
1326
+ return text // em-dashes
1327
+ .replace(/---/g, "\u2014") // en-dashes
1328
+ .replace(/--/g, "\u2013") // opening singles
1329
+ .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
1330
+ .replace(/'/g, "\u2019") // opening doubles
1331
+ .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
1332
+ .replace(/"/g, "\u201D") // ellipses
1333
+ .replace(/\.{3}/g, "\u2026");
1334
+ }
1335
+ /**
1336
+ * Mangle Links
1337
+ */
1338
+ ;
1339
+
1340
+ _proto.mangle = function mangle(text) {
1341
+ if (!this.options.mangle) return text;
1342
+ var l = text.length;
1343
+ var out = '',
1344
+ i = 0,
1345
+ ch;
1136
1346
 
1137
- /**
1138
- * Parse Loop
1139
- */
1347
+ for (; i < l; i++) {
1348
+ ch = text.charCodeAt(i);
1140
1349
 
1141
- Parser.prototype.parse = function(src) {
1142
- this.inline = new InlineLexer(src.links, this.options);
1143
- // use an InlineLexer with a TextRenderer to extract pure text
1144
- this.inlineText = new InlineLexer(
1145
- src.links,
1146
- merge({}, this.options, { renderer: new TextRenderer() })
1147
- );
1148
- this.tokens = src.reverse();
1149
-
1150
- var out = '';
1151
- while (this.next()) {
1152
- out += this.tok();
1153
- }
1350
+ if (Math.random() > 0.5) {
1351
+ ch = 'x' + ch.toString(16);
1352
+ }
1154
1353
 
1155
- return out;
1156
- };
1354
+ out += '&#' + ch + ';';
1355
+ }
1157
1356
 
1158
- /**
1159
- * Next Token
1160
- */
1357
+ return out;
1358
+ };
1161
1359
 
1162
- Parser.prototype.next = function() {
1163
- this.token = this.tokens.pop();
1164
- return this.token;
1165
- };
1360
+ _createClass(InlineLexer, null, [{
1361
+ key: "rules",
1362
+ get: function get() {
1363
+ return inline$1;
1364
+ }
1365
+ }]);
1166
1366
 
1167
- /**
1168
- * Preview Next Token
1169
- */
1367
+ return InlineLexer;
1368
+ }();
1170
1369
 
1171
- Parser.prototype.peek = function() {
1172
- return this.tokens[this.tokens.length - 1] || 0;
1173
- };
1370
+ /**
1371
+ * TextRenderer
1372
+ * returns only the textual part of the token
1373
+ */
1374
+ var TextRenderer_1 = /*#__PURE__*/function () {
1375
+ function TextRenderer() {}
1174
1376
 
1175
- /**
1176
- * Parse Text Tokens
1177
- */
1377
+ var _proto = TextRenderer.prototype;
1178
1378
 
1179
- Parser.prototype.parseText = function() {
1180
- var body = this.token.text;
1379
+ // no need for block level renderers
1380
+ _proto.strong = function strong(text) {
1381
+ return text;
1382
+ };
1181
1383
 
1182
- while (this.peek().type === 'text') {
1183
- body += '\n' + this.next().text;
1184
- }
1384
+ _proto.em = function em(text) {
1385
+ return text;
1386
+ };
1185
1387
 
1186
- return this.inline.output(body);
1187
- };
1388
+ _proto.codespan = function codespan(text) {
1389
+ return text;
1390
+ };
1188
1391
 
1189
- /**
1190
- * Parse Current Token
1191
- */
1392
+ _proto.del = function del(text) {
1393
+ return text;
1394
+ };
1192
1395
 
1193
- Parser.prototype.tok = function() {
1194
- switch (this.token.type) {
1195
- case 'space': {
1396
+ _proto.html = function html(text) {
1397
+ return text;
1398
+ };
1399
+
1400
+ _proto.text = function text(_text) {
1401
+ return _text;
1402
+ };
1403
+
1404
+ _proto.link = function link(href, title, text) {
1405
+ return '' + text;
1406
+ };
1407
+
1408
+ _proto.image = function image(href, title, text) {
1409
+ return '' + text;
1410
+ };
1411
+
1412
+ _proto.br = function br() {
1196
1413
  return '';
1414
+ };
1415
+
1416
+ return TextRenderer;
1417
+ }();
1418
+
1419
+ var defaults$4 = defaults.defaults;
1420
+ var merge$2 = helpers.merge,
1421
+ unescape$1 = helpers.unescape;
1422
+ /**
1423
+ * Parsing & Compiling
1424
+ */
1425
+
1426
+ var Parser_1 = /*#__PURE__*/function () {
1427
+ function Parser(options) {
1428
+ this.tokens = [];
1429
+ this.token = null;
1430
+ this.options = options || defaults$4;
1431
+ this.options.renderer = this.options.renderer || new Renderer_1();
1432
+ this.renderer = this.options.renderer;
1433
+ this.renderer.options = this.options;
1434
+ this.slugger = new Slugger_1();
1197
1435
  }
1198
- case 'hr': {
1199
- return this.renderer.hr();
1200
- }
1201
- case 'heading': {
1202
- return this.renderer.heading(
1203
- this.inline.output(this.token.text),
1204
- this.token.depth,
1205
- unescape(this.inlineText.output(this.token.text)),
1206
- this.slugger);
1207
- }
1208
- case 'code': {
1209
- return this.renderer.code(this.token.text,
1210
- this.token.lang,
1211
- this.token.escaped);
1212
- }
1213
- case 'table': {
1214
- var header = '',
1215
- body = '',
1216
- i,
1217
- row,
1218
- cell,
1219
- j;
1220
-
1221
- // header
1222
- cell = '';
1223
- for (i = 0; i < this.token.header.length; i++) {
1224
- cell += this.renderer.tablecell(
1225
- this.inline.output(this.token.header[i]),
1226
- { header: true, align: this.token.align[i] }
1227
- );
1228
- }
1229
- header += this.renderer.tablerow(cell);
1436
+ /**
1437
+ * Static Parse Method
1438
+ */
1230
1439
 
1231
- for (i = 0; i < this.token.cells.length; i++) {
1232
- row = this.token.cells[i];
1233
1440
 
1234
- cell = '';
1235
- for (j = 0; j < row.length; j++) {
1236
- cell += this.renderer.tablecell(
1237
- this.inline.output(row[j]),
1238
- { header: false, align: this.token.align[j] }
1239
- );
1240
- }
1441
+ Parser.parse = function parse(tokens, options) {
1442
+ var parser = new Parser(options);
1443
+ return parser.parse(tokens);
1444
+ };
1241
1445
 
1242
- body += this.renderer.tablerow(cell);
1243
- }
1244
- return this.renderer.table(header, body);
1245
- }
1246
- case 'blockquote_start': {
1247
- body = '';
1446
+ var _proto = Parser.prototype;
1248
1447
 
1249
- while (this.next().type !== 'blockquote_end') {
1250
- body += this.tok();
1251
- }
1448
+ /**
1449
+ * Parse Loop
1450
+ */
1451
+ _proto.parse = function parse(tokens) {
1452
+ this.inline = new InlineLexer_1(tokens.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text
1252
1453
 
1253
- return this.renderer.blockquote(body);
1254
- }
1255
- case 'list_start': {
1256
- body = '';
1257
- var ordered = this.token.ordered,
1258
- start = this.token.start;
1454
+ this.inlineText = new InlineLexer_1(tokens.links, merge$2({}, this.options, {
1455
+ renderer: new TextRenderer_1()
1456
+ }));
1457
+ this.tokens = tokens.reverse();
1458
+ var out = '';
1259
1459
 
1260
- while (this.next().type !== 'list_end') {
1261
- body += this.tok();
1460
+ while (this.next()) {
1461
+ out += this.tok();
1262
1462
  }
1263
1463
 
1264
- return this.renderer.list(body, ordered, start);
1265
- }
1266
- case 'list_item_start': {
1267
- body = '';
1268
- var loose = this.token.loose;
1269
- var checked = this.token.checked;
1270
- var task = this.token.task;
1271
-
1272
- if (this.token.task) {
1273
- body += this.renderer.checkbox(checked);
1274
- }
1464
+ return out;
1465
+ };
1275
1466
 
1276
- while (this.next().type !== 'list_item_end') {
1277
- body += !loose && this.token.type === 'text'
1278
- ? this.parseText()
1279
- : this.tok();
1280
- }
1281
- return this.renderer.listitem(body, task, checked);
1282
- }
1283
- case 'html': {
1284
- // TODO parse inline content if parameter markdown=1
1285
- return this.renderer.html(this.token.text);
1286
- }
1287
- case 'paragraph': {
1288
- return this.renderer.paragraph(this.inline.output(this.token.text));
1289
- }
1290
- case 'text': {
1291
- return this.renderer.paragraph(this.parseText());
1292
- }
1293
- default: {
1294
- var errMsg = 'Token with "' + this.token.type + '" type was not found.';
1295
- if (this.options.silent) {
1296
- console.log(errMsg);
1297
- } else {
1298
- throw new Error(errMsg);
1299
- }
1300
- }
1301
- }
1302
- };
1467
+ /**
1468
+ * Next Token
1469
+ */
1470
+ _proto.next = function next() {
1471
+ this.token = this.tokens.pop();
1472
+ return this.token;
1473
+ };
1303
1474
 
1304
- /**
1305
- * Slugger generates header id
1306
- */
1475
+ /**
1476
+ * Preview Next Token
1477
+ */
1478
+ _proto.peek = function peek() {
1479
+ return this.tokens[this.tokens.length - 1] || 0;
1480
+ };
1307
1481
 
1308
- function Slugger() {
1309
- this.seen = {};
1310
- }
1482
+ /**
1483
+ * Parse Text Tokens
1484
+ */
1485
+ _proto.parseText = function parseText() {
1486
+ var body = this.token.text;
1311
1487
 
1312
- /**
1313
- * Convert string to unique id
1314
- */
1488
+ while (this.peek().type === 'text') {
1489
+ body += '\n' + this.next().text;
1490
+ }
1315
1491
 
1316
- Slugger.prototype.slug = function(value) {
1317
- var slug = value
1318
- .toLowerCase()
1319
- .trim()
1320
- .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
1321
- .replace(/\s/g, '-');
1322
-
1323
- if (this.seen.hasOwnProperty(slug)) {
1324
- var originalSlug = slug;
1325
- do {
1326
- this.seen[originalSlug]++;
1327
- slug = originalSlug + '-' + this.seen[originalSlug];
1328
- } while (this.seen.hasOwnProperty(slug));
1329
- }
1330
- this.seen[slug] = 0;
1492
+ return this.inline.output(body);
1493
+ };
1331
1494
 
1332
- return slug;
1333
- };
1495
+ /**
1496
+ * Parse Current Token
1497
+ */
1498
+ _proto.tok = function tok() {
1499
+ var body = '';
1334
1500
 
1335
- /**
1336
- * Helpers
1337
- */
1501
+ switch (this.token.type) {
1502
+ case 'space':
1503
+ {
1504
+ return '';
1505
+ }
1338
1506
 
1339
- function escape(html, encode) {
1340
- if (encode) {
1341
- if (escape.escapeTest.test(html)) {
1342
- return html.replace(escape.escapeReplace, function(ch) { return escape.replacements[ch]; });
1343
- }
1344
- } else {
1345
- if (escape.escapeTestNoEncode.test(html)) {
1346
- return html.replace(escape.escapeReplaceNoEncode, function(ch) { return escape.replacements[ch]; });
1347
- }
1348
- }
1507
+ case 'hr':
1508
+ {
1509
+ return this.renderer.hr();
1510
+ }
1349
1511
 
1350
- return html;
1351
- }
1352
-
1353
- escape.escapeTest = /[&<>"']/;
1354
- escape.escapeReplace = /[&<>"']/g;
1355
- escape.replacements = {
1356
- '&': '&amp;',
1357
- '<': '&lt;',
1358
- '>': '&gt;',
1359
- '"': '&quot;',
1360
- "'": '&#39;'
1361
- };
1362
-
1363
- escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
1364
- escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
1365
-
1366
- function unescape(html) {
1367
- // explicitly match decimal, hex, and named HTML entities
1368
- return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) {
1369
- n = n.toLowerCase();
1370
- if (n === 'colon') return ':';
1371
- if (n.charAt(0) === '#') {
1372
- return n.charAt(1) === 'x'
1373
- ? String.fromCharCode(parseInt(n.substring(2), 16))
1374
- : String.fromCharCode(+n.substring(1));
1375
- }
1376
- return '';
1377
- });
1378
- }
1379
-
1380
- function edit(regex, opt) {
1381
- regex = regex.source || regex;
1382
- opt = opt || '';
1383
- return {
1384
- replace: function(name, val) {
1385
- val = val.source || val;
1386
- val = val.replace(/(^|[^\[])\^/g, '$1');
1387
- regex = regex.replace(name, val);
1388
- return this;
1389
- },
1390
- getRegex: function() {
1391
- return new RegExp(regex, opt);
1392
- }
1393
- };
1394
- }
1512
+ case 'heading':
1513
+ {
1514
+ return this.renderer.heading(this.inline.output(this.token.text), this.token.depth, unescape$1(this.inlineText.output(this.token.text)), this.slugger);
1515
+ }
1395
1516
 
1396
- function cleanUrl(sanitize, base, href) {
1397
- if (sanitize) {
1398
- try {
1399
- var prot = decodeURIComponent(unescape(href))
1400
- .replace(/[^\w:]/g, '')
1401
- .toLowerCase();
1402
- } catch (e) {
1403
- return null;
1404
- }
1405
- if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
1406
- return null;
1407
- }
1408
- }
1409
- if (base && !originIndependentUrl.test(href)) {
1410
- href = resolveUrl(base, href);
1411
- }
1412
- try {
1413
- href = encodeURI(href).replace(/%25/g, '%');
1414
- } catch (e) {
1415
- return null;
1416
- }
1417
- return href;
1418
- }
1419
-
1420
- function resolveUrl(base, href) {
1421
- if (!baseUrls[' ' + base]) {
1422
- // we can ignore everything in base after the last slash of its path component,
1423
- // but we might need to add _that_
1424
- // https://tools.ietf.org/html/rfc3986#section-3
1425
- if (/^[^:]+:\/*[^/]*$/.test(base)) {
1426
- baseUrls[' ' + base] = base + '/';
1427
- } else {
1428
- baseUrls[' ' + base] = rtrim(base, '/', true);
1429
- }
1430
- }
1431
- base = baseUrls[' ' + base];
1432
-
1433
- if (href.slice(0, 2) === '//') {
1434
- return base.replace(/:[\s\S]*/, ':') + href;
1435
- } else if (href.charAt(0) === '/') {
1436
- return base.replace(/(:\/*[^/]*)[\s\S]*/, '$1') + href;
1437
- } else {
1438
- return base + href;
1439
- }
1440
- }
1441
- var baseUrls = {};
1442
- var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
1443
-
1444
- function noop() {}
1445
- noop.exec = noop;
1446
-
1447
- function merge(obj) {
1448
- var i = 1,
1449
- target,
1450
- key;
1451
-
1452
- for (; i < arguments.length; i++) {
1453
- target = arguments[i];
1454
- for (key in target) {
1455
- if (Object.prototype.hasOwnProperty.call(target, key)) {
1456
- obj[key] = target[key];
1457
- }
1458
- }
1459
- }
1517
+ case 'code':
1518
+ {
1519
+ return this.renderer.code(this.token.text, this.token.lang, this.token.escaped);
1520
+ }
1460
1521
 
1461
- return obj;
1462
- }
1463
-
1464
- function splitCells(tableRow, count) {
1465
- // ensure that every cell-delimiting pipe has a space
1466
- // before it to distinguish it from an escaped pipe
1467
- var row = tableRow.replace(/\|/g, function(match, offset, str) {
1468
- var escaped = false,
1469
- curr = offset;
1470
- while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
1471
- if (escaped) {
1472
- // odd number of slashes means | is escaped
1473
- // so we leave it alone
1474
- return '|';
1475
- } else {
1476
- // add space before unescaped |
1477
- return ' |';
1478
- }
1479
- }),
1480
- cells = row.split(/ \|/),
1481
- i = 0;
1482
-
1483
- if (cells.length > count) {
1484
- cells.splice(count);
1485
- } else {
1486
- while (cells.length < count) cells.push('');
1487
- }
1522
+ case 'table':
1523
+ {
1524
+ var header = '',
1525
+ i,
1526
+ row,
1527
+ cell,
1528
+ j; // header
1488
1529
 
1489
- for (; i < cells.length; i++) {
1490
- // leading or trailing whitespace is ignored per the gfm spec
1491
- cells[i] = cells[i].trim().replace(/\\\|/g, '|');
1492
- }
1493
- return cells;
1494
- }
1495
-
1496
- // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
1497
- // /c*$/ is vulnerable to REDOS.
1498
- // invert: Remove suffix of non-c chars instead. Default falsey.
1499
- function rtrim(str, c, invert) {
1500
- if (str.length === 0) {
1501
- return '';
1502
- }
1530
+ cell = '';
1503
1531
 
1504
- // Length of suffix matching the invert condition.
1505
- var suffLen = 0;
1532
+ for (i = 0; i < this.token.header.length; i++) {
1533
+ cell += this.renderer.tablecell(this.inline.output(this.token.header[i]), {
1534
+ header: true,
1535
+ align: this.token.align[i]
1536
+ });
1537
+ }
1506
1538
 
1507
- // Step left until we fail to match the invert condition.
1508
- while (suffLen < str.length) {
1509
- var currChar = str.charAt(str.length - suffLen - 1);
1510
- if (currChar === c && !invert) {
1511
- suffLen++;
1512
- } else if (currChar !== c && invert) {
1513
- suffLen++;
1514
- } else {
1515
- break;
1516
- }
1517
- }
1539
+ header += this.renderer.tablerow(cell);
1518
1540
 
1519
- return str.substr(0, str.length - suffLen);
1520
- }
1541
+ for (i = 0; i < this.token.cells.length; i++) {
1542
+ row = this.token.cells[i];
1543
+ cell = '';
1521
1544
 
1522
- function findClosingBracket(str, b) {
1523
- if (str.indexOf(b[1]) === -1) {
1524
- return -1;
1525
- }
1526
- var level = 0;
1527
- for (var i = 0; i < str.length; i++) {
1528
- if (str[i] === '\\') {
1529
- i++;
1530
- } else if (str[i] === b[0]) {
1531
- level++;
1532
- } else if (str[i] === b[1]) {
1533
- level--;
1534
- if (level < 0) {
1535
- return i;
1536
- }
1537
- }
1538
- }
1539
- return -1;
1540
- }
1545
+ for (j = 0; j < row.length; j++) {
1546
+ cell += this.renderer.tablecell(this.inline.output(row[j]), {
1547
+ header: false,
1548
+ align: this.token.align[j]
1549
+ });
1550
+ }
1541
1551
 
1542
- /**
1543
- * Marked
1544
- */
1552
+ body += this.renderer.tablerow(cell);
1553
+ }
1545
1554
 
1546
- function marked(src, opt, callback) {
1547
- // throw error in case of non string input
1548
- if (typeof src === 'undefined' || src === null) {
1549
- throw new Error('marked(): input parameter is undefined or null');
1550
- }
1551
- if (typeof src !== 'string') {
1552
- throw new Error('marked(): input parameter is of type '
1553
- + Object.prototype.toString.call(src) + ', string expected');
1554
- }
1555
+ return this.renderer.table(header, body);
1556
+ }
1555
1557
 
1556
- if (callback || typeof opt === 'function') {
1557
- if (!callback) {
1558
- callback = opt;
1559
- opt = null;
1560
- }
1558
+ case 'blockquote_start':
1559
+ {
1560
+ body = '';
1561
1561
 
1562
- opt = merge({}, marked.defaults, opt || {});
1562
+ while (this.next().type !== 'blockquote_end') {
1563
+ body += this.tok();
1564
+ }
1563
1565
 
1564
- var highlight = opt.highlight,
1565
- tokens,
1566
- pending,
1567
- i = 0;
1566
+ return this.renderer.blockquote(body);
1567
+ }
1568
1568
 
1569
- try {
1570
- tokens = Lexer.lex(src, opt);
1571
- } catch (e) {
1572
- return callback(e);
1573
- }
1569
+ case 'list_start':
1570
+ {
1571
+ body = '';
1572
+ var ordered = this.token.ordered,
1573
+ start = this.token.start;
1574
1574
 
1575
- pending = tokens.length;
1575
+ while (this.next().type !== 'list_end') {
1576
+ body += this.tok();
1577
+ }
1576
1578
 
1577
- var done = function(err) {
1578
- if (err) {
1579
- opt.highlight = highlight;
1580
- return callback(err);
1581
- }
1579
+ return this.renderer.list(body, ordered, start);
1580
+ }
1582
1581
 
1583
- var out;
1582
+ case 'list_item_start':
1583
+ {
1584
+ body = '';
1585
+ var loose = this.token.loose;
1586
+ var checked = this.token.checked;
1587
+ var task = this.token.task;
1588
+
1589
+ if (this.token.task) {
1590
+ if (loose) {
1591
+ if (this.peek().type === 'text') {
1592
+ var nextToken = this.peek();
1593
+ nextToken.text = this.renderer.checkbox(checked) + ' ' + nextToken.text;
1594
+ } else {
1595
+ this.tokens.push({
1596
+ type: 'text',
1597
+ text: this.renderer.checkbox(checked)
1598
+ });
1599
+ }
1600
+ } else {
1601
+ body += this.renderer.checkbox(checked);
1602
+ }
1603
+ }
1604
+
1605
+ while (this.next().type !== 'list_item_end') {
1606
+ body += !loose && this.token.type === 'text' ? this.parseText() : this.tok();
1607
+ }
1608
+
1609
+ return this.renderer.listitem(body, task, checked);
1610
+ }
1584
1611
 
1585
- try {
1586
- out = Parser.parse(tokens, opt);
1587
- } catch (e) {
1588
- err = e;
1589
- }
1612
+ case 'html':
1613
+ {
1614
+ // TODO parse inline content if parameter markdown=1
1615
+ return this.renderer.html(this.token.text);
1616
+ }
1617
+
1618
+ case 'paragraph':
1619
+ {
1620
+ return this.renderer.paragraph(this.inline.output(this.token.text));
1621
+ }
1622
+
1623
+ case 'text':
1624
+ {
1625
+ return this.renderer.paragraph(this.parseText());
1626
+ }
1590
1627
 
1591
- opt.highlight = highlight;
1628
+ default:
1629
+ {
1630
+ var errMsg = 'Token with "' + this.token.type + '" type was not found.';
1592
1631
 
1593
- return err
1594
- ? callback(err)
1595
- : callback(null, out);
1632
+ if (this.options.silent) {
1633
+ console.log(errMsg);
1634
+ } else {
1635
+ throw new Error(errMsg);
1636
+ }
1637
+ }
1638
+ }
1596
1639
  };
1597
1640
 
1598
- if (!highlight || highlight.length < 3) {
1599
- return done();
1641
+ return Parser;
1642
+ }();
1643
+
1644
+ var merge$3 = helpers.merge,
1645
+ checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation,
1646
+ escape$4 = helpers.escape;
1647
+ var getDefaults = defaults.getDefaults,
1648
+ changeDefaults = defaults.changeDefaults,
1649
+ defaults$5 = defaults.defaults;
1650
+ /**
1651
+ * Marked
1652
+ */
1653
+
1654
+ function marked(src, opt, callback) {
1655
+ // throw error in case of non string input
1656
+ if (typeof src === 'undefined' || src === null) {
1657
+ throw new Error('marked(): input parameter is undefined or null');
1600
1658
  }
1601
1659
 
1602
- delete opt.highlight;
1660
+ if (typeof src !== 'string') {
1661
+ throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
1662
+ }
1603
1663
 
1604
- if (!pending) return done();
1664
+ if (callback || typeof opt === 'function') {
1665
+ var _ret = function () {
1666
+ if (!callback) {
1667
+ callback = opt;
1668
+ opt = null;
1669
+ }
1605
1670
 
1606
- for (; i < tokens.length; i++) {
1607
- (function(token) {
1608
- if (token.type !== 'code') {
1609
- return --pending || done();
1671
+ opt = merge$3({}, marked.defaults, opt || {});
1672
+ checkSanitizeDeprecation$1(opt);
1673
+ var highlight = opt.highlight;
1674
+ var tokens,
1675
+ pending,
1676
+ i = 0;
1677
+
1678
+ try {
1679
+ tokens = Lexer_1.lex(src, opt);
1680
+ } catch (e) {
1681
+ return {
1682
+ v: callback(e)
1683
+ };
1610
1684
  }
1611
- return highlight(token.text, token.lang, function(err, code) {
1612
- if (err) return done(err);
1613
- if (code == null || code === token.text) {
1614
- return --pending || done();
1685
+
1686
+ pending = tokens.length;
1687
+
1688
+ var done = function done(err) {
1689
+ if (err) {
1690
+ opt.highlight = highlight;
1691
+ return callback(err);
1615
1692
  }
1616
- token.text = code;
1617
- token.escaped = true;
1618
- --pending || done();
1619
- });
1620
- })(tokens[i]);
1621
- }
1622
1693
 
1623
- return;
1624
- }
1625
- try {
1626
- if (opt) opt = merge({}, marked.defaults, opt);
1627
- return Parser.parse(Lexer.lex(src, opt), opt);
1628
- } catch (e) {
1629
- e.message += '\nPlease report this to https://github.com/markedjs/marked.';
1630
- if ((opt || marked.defaults).silent) {
1631
- return '<p>An error occurred:</p><pre>'
1632
- + escape(e.message + '', true)
1633
- + '</pre>';
1634
- }
1635
- throw e;
1636
- }
1637
- }
1694
+ var out;
1638
1695
 
1639
- /**
1640
- * Options
1641
- */
1696
+ try {
1697
+ out = Parser_1.parse(tokens, opt);
1698
+ } catch (e) {
1699
+ err = e;
1700
+ }
1642
1701
 
1643
- marked.options =
1644
- marked.setOptions = function(opt) {
1645
- merge(marked.defaults, opt);
1646
- return marked;
1647
- };
1648
-
1649
- marked.getDefaults = function() {
1650
- return {
1651
- baseUrl: null,
1652
- breaks: false,
1653
- gfm: true,
1654
- headerIds: true,
1655
- headerPrefix: '',
1656
- highlight: null,
1657
- langPrefix: 'language-',
1658
- mangle: true,
1659
- pedantic: false,
1660
- renderer: new Renderer(),
1661
- sanitize: false,
1662
- sanitizer: null,
1663
- silent: false,
1664
- smartLists: false,
1665
- smartypants: false,
1666
- tables: true,
1667
- xhtml: false
1668
- };
1669
- };
1702
+ opt.highlight = highlight;
1703
+ return err ? callback(err) : callback(null, out);
1704
+ };
1670
1705
 
1671
- marked.defaults = marked.getDefaults();
1706
+ if (!highlight || highlight.length < 3) {
1707
+ return {
1708
+ v: done()
1709
+ };
1710
+ }
1672
1711
 
1673
- /**
1674
- * Expose
1675
- */
1712
+ delete opt.highlight;
1713
+ if (!pending) return {
1714
+ v: done()
1715
+ };
1676
1716
 
1677
- marked.Parser = Parser;
1678
- marked.parser = Parser.parse;
1717
+ for (; i < tokens.length; i++) {
1718
+ (function (token) {
1719
+ if (token.type !== 'code') {
1720
+ return --pending || done();
1721
+ }
1679
1722
 
1680
- marked.Renderer = Renderer;
1681
- marked.TextRenderer = TextRenderer;
1723
+ return highlight(token.text, token.lang, function (err, code) {
1724
+ if (err) return done(err);
1682
1725
 
1683
- marked.Lexer = Lexer;
1684
- marked.lexer = Lexer.lex;
1726
+ if (code == null || code === token.text) {
1727
+ return --pending || done();
1728
+ }
1685
1729
 
1686
- marked.InlineLexer = InlineLexer;
1687
- marked.inlineLexer = InlineLexer.output;
1730
+ token.text = code;
1731
+ token.escaped = true;
1732
+ --pending || done();
1733
+ });
1734
+ })(tokens[i]);
1735
+ }
1736
+
1737
+ return {
1738
+ v: void 0
1739
+ };
1740
+ }();
1741
+
1742
+ if (typeof _ret === "object") return _ret.v;
1743
+ }
1744
+
1745
+ try {
1746
+ opt = merge$3({}, marked.defaults, opt || {});
1747
+ checkSanitizeDeprecation$1(opt);
1748
+ return Parser_1.parse(Lexer_1.lex(src, opt), opt);
1749
+ } catch (e) {
1750
+ e.message += '\nPlease report this to https://github.com/markedjs/marked.';
1688
1751
 
1689
- marked.Slugger = Slugger;
1752
+ if ((opt || marked.defaults).silent) {
1753
+ return '<p>An error occurred:</p><pre>' + escape$4(e.message + '', true) + '</pre>';
1754
+ }
1690
1755
 
1691
- marked.parse = marked;
1756
+ throw e;
1757
+ }
1758
+ }
1759
+ /**
1760
+ * Options
1761
+ */
1762
+
1763
+
1764
+ marked.options = marked.setOptions = function (opt) {
1765
+ merge$3(marked.defaults, opt);
1766
+ changeDefaults(marked.defaults);
1767
+ return marked;
1768
+ };
1692
1769
 
1693
- if (typeof module !== 'undefined' && typeof exports === 'object') {
1694
- module.exports = marked;
1695
- } else if (typeof define === 'function' && define.amd) {
1696
- define(function() { return marked; });
1697
- } else {
1698
- root.marked = marked;
1699
- }
1700
- })(this || (typeof window !== 'undefined' ? window : global));
1770
+ marked.getDefaults = getDefaults;
1771
+ marked.defaults = defaults$5;
1772
+ /**
1773
+ * Expose
1774
+ */
1775
+
1776
+ marked.Parser = Parser_1;
1777
+ marked.parser = Parser_1.parse;
1778
+ marked.Renderer = Renderer_1;
1779
+ marked.TextRenderer = TextRenderer_1;
1780
+ marked.Lexer = Lexer_1;
1781
+ marked.lexer = Lexer_1.lex;
1782
+ marked.InlineLexer = InlineLexer_1;
1783
+ marked.inlineLexer = InlineLexer_1.output;
1784
+ marked.Slugger = Slugger_1;
1785
+ marked.parse = marked;
1786
+ var marked_1 = marked;
1787
+
1788
+ return marked_1;
1789
+
1790
+ })));