marked 1.2.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/marked.esm.js +133 -144
- package/lib/marked.js +135 -131
- package/marked.min.js +2 -2
- package/package.json +14 -14
- package/src/Lexer.js +47 -26
- package/src/Renderer.js +2 -0
- package/src/Tokenizer.js +58 -57
- package/src/rules.js +22 -55
package/src/rules.js
CHANGED
|
@@ -8,8 +8,8 @@ const {
|
|
|
8
8
|
* Block-Level Grammar
|
|
9
9
|
*/
|
|
10
10
|
const block = {
|
|
11
|
-
newline:
|
|
12
|
-
code: /^( {4}[^\n]
|
|
11
|
+
newline: /^(?: *(?:\n|$))+/,
|
|
12
|
+
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
|
|
13
13
|
fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
|
|
14
14
|
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
|
|
15
15
|
heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
|
|
@@ -31,7 +31,7 @@ const block = {
|
|
|
31
31
|
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
32
32
|
// regex template, placeholders will be replaced according to different paragraph
|
|
33
33
|
// interruption rules of commonmark and the original markdown spec:
|
|
34
|
-
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
|
|
34
|
+
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html| +\n)[^\n]+)*)/,
|
|
35
35
|
text: /^[^\n]+/
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -173,74 +173,41 @@ const inline = {
|
|
|
173
173
|
reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
|
|
174
174
|
nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
|
|
175
175
|
reflinkSearch: 'reflink|nolink(?!\\()',
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
em: {
|
|
183
|
-
start: /^(?:(\*(?=[punctuation]))|\*)(?![*\s])|_/, // (1) returns if starts w/ punctuation
|
|
184
|
-
middle: /^\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*$|^_(?![_\s])(?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?_$/,
|
|
185
|
-
endAst: /[^punctuation\s]\*(?!\*)|[punctuation]\*(?!\*)(?:(?=[punctuation_\s]|$))/, // last char can't be punct, or final * must also be followed by punct (or endline)
|
|
186
|
-
endUnd: /[^\s]_(?!_)(?:(?=[punctuation*\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
|
|
176
|
+
emStrong: {
|
|
177
|
+
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
|
|
178
|
+
// (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
|
|
179
|
+
// () Skip other delimiter (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
|
|
180
|
+
rDelimAst: /\_\_[^_]*?\*[^_]*?\_\_|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
|
|
181
|
+
rDelimUnd: /\*\*[^*]*?\_[^*]*?\*\*|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
|
|
187
182
|
},
|
|
188
183
|
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
189
184
|
br: /^( {2,}|\\)\n(?!\s*$)/,
|
|
190
185
|
del: noopTest,
|
|
191
|
-
text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n)))/,
|
|
192
|
-
punctuation: /^([\
|
|
186
|
+
text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
|
|
187
|
+
punctuation: /^([\spunctuation])/
|
|
193
188
|
};
|
|
194
189
|
|
|
195
|
-
// list of punctuation marks from
|
|
196
|
-
// without * and _ to
|
|
190
|
+
// list of punctuation marks from CommonMark spec
|
|
191
|
+
// without * and _ to handle the different emphasis markers * and _
|
|
197
192
|
inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
|
|
198
193
|
inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex();
|
|
199
194
|
|
|
200
195
|
// sequences em should skip over [title](link), `code`, <html>
|
|
201
|
-
inline.
|
|
202
|
-
inline.
|
|
196
|
+
inline.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
|
|
197
|
+
inline.escapedEmSt = /\\\*|\\_/g;
|
|
203
198
|
|
|
204
199
|
inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
|
|
205
200
|
|
|
206
|
-
inline.
|
|
207
|
-
.replace(/
|
|
208
|
-
.getRegex();
|
|
209
|
-
|
|
210
|
-
inline.em.middle = edit(inline.em.middle)
|
|
211
|
-
.replace(/punctuation/g, inline._punctuation)
|
|
212
|
-
.replace(/overlapSkip/g, inline._overlapSkip)
|
|
213
|
-
.getRegex();
|
|
214
|
-
|
|
215
|
-
inline.em.endAst = edit(inline.em.endAst, 'g')
|
|
216
|
-
.replace(/punctuation/g, inline._punctuation)
|
|
217
|
-
.getRegex();
|
|
218
|
-
|
|
219
|
-
inline.em.endUnd = edit(inline.em.endUnd, 'g')
|
|
220
|
-
.replace(/punctuation/g, inline._punctuation)
|
|
221
|
-
.getRegex();
|
|
222
|
-
|
|
223
|
-
inline.strong.start = edit(inline.strong.start)
|
|
224
|
-
.replace(/punctuation/g, inline._punctuation)
|
|
225
|
-
.getRegex();
|
|
226
|
-
|
|
227
|
-
inline.strong.middle = edit(inline.strong.middle)
|
|
228
|
-
.replace(/punctuation/g, inline._punctuation)
|
|
229
|
-
.replace(/overlapSkip/g, inline._overlapSkip)
|
|
230
|
-
.getRegex();
|
|
231
|
-
|
|
232
|
-
inline.strong.endAst = edit(inline.strong.endAst, 'g')
|
|
233
|
-
.replace(/punctuation/g, inline._punctuation)
|
|
234
|
-
.getRegex();
|
|
235
|
-
|
|
236
|
-
inline.strong.endUnd = edit(inline.strong.endUnd, 'g')
|
|
237
|
-
.replace(/punctuation/g, inline._punctuation)
|
|
201
|
+
inline.emStrong.lDelim = edit(inline.emStrong.lDelim)
|
|
202
|
+
.replace(/punct/g, inline._punctuation)
|
|
238
203
|
.getRegex();
|
|
239
204
|
|
|
240
|
-
inline.
|
|
205
|
+
inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, 'g')
|
|
206
|
+
.replace(/punct/g, inline._punctuation)
|
|
241
207
|
.getRegex();
|
|
242
208
|
|
|
243
|
-
inline.
|
|
209
|
+
inline.emStrong.rDelimUnd = edit(inline.emStrong.rDelimUnd, 'g')
|
|
210
|
+
.replace(/punct/g, inline._punctuation)
|
|
244
211
|
.getRegex();
|
|
245
212
|
|
|
246
213
|
inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
|
|
@@ -319,7 +286,7 @@ inline.gfm = merge({}, inline.normal, {
|
|
|
319
286
|
url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
|
|
320
287
|
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
|
|
321
288
|
del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
|
|
322
|
-
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
|
|
289
|
+
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
|
|
323
290
|
});
|
|
324
291
|
|
|
325
292
|
inline.gfm.url = edit(inline.gfm.url, 'i')
|