marked 0.6.1 → 0.8.0

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