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