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