marked 1.2.9 → 2.0.3

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/src/rules.js CHANGED
@@ -48,7 +48,7 @@ block.item = edit(block.item, 'gm')
48
48
  .replace(/bull/g, block.bullet)
49
49
  .getRegex();
50
50
 
51
- block.listItemStart = edit(/^( *)(bull)/)
51
+ block.listItemStart = edit(/^( *)(bull) */)
52
52
  .replace('bull', block.bullet)
53
53
  .getRegex();
54
54
 
@@ -173,74 +173,41 @@ const inline = {
173
173
  reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
174
174
  nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
175
175
  reflinkSearch: 'reflink|nolink(?!\\()',
176
- strong: {
177
- start: /^(?:(\*\*(?=[*punctuation]))|\*\*)(?![\s])|__/, // (1) returns if starts w/ punctuation
178
- middle: /^\*\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*\*$|^__(?![\s])((?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?)__$/,
179
- endAst: /[^punctuation\s]\*\*(?!\*)|[punctuation]\*\*(?!\*)(?:(?=[punctuation_\s]|$))/, // last char can't be punct, or final * must also be followed by punct (or endline)
180
- endUnd: /[^\s]__(?!_)(?:(?=[punctuation*\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
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: /^([\s*punctuation])/
186
+ text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
187
+ punctuation: /^([\spunctuation])/
193
188
  };
194
189
 
195
- // list of punctuation marks from common mark spec
196
- // without * and _ to workaround cases with double emphasis
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._blockSkip = '\\[[^\\]]*?\\]\\([^\\)]*?\\)|`[^`]*?`|<[^>]*?>';
202
- inline._overlapSkip = '__[^_]*?__|\\*\\*\\[^\\*\\]*?\\*\\*';
196
+ inline.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
197
+ inline.escapedEmSt = /\\\*|\\_/g;
203
198
 
204
199
  inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
205
200
 
206
- inline.em.start = edit(inline.em.start)
207
- .replace(/punctuation/g, inline._punctuation)
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.blockSkip = edit(inline._blockSkip, 'g')
205
+ inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, 'g')
206
+ .replace(/punct/g, inline._punctuation)
241
207
  .getRegex();
242
208
 
243
- inline.overlapSkip = edit(inline._overlapSkip, 'g')
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')