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