Skip to content

Commit fd44548

Browse files
committed
Fix emphasis followed by a punctuation (fixes markedjs#1378)
1 parent 25f91e4 commit fd44548

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/marked.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,18 @@ var inline = {
541541
reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
542542
nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
543543
strong: /^__([^\s])__(?!_)|^\*\*([^\s])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
544-
em: /^_([^\s_])_(?!_)|^\*([^\s*"<\[])\*(?!\*)|^_([^\s][\s\S]*?[^\s_])_(?!_|[^\s.])|^_([^\s_][\s\S]*?[^\s])_(?!_|[^\s.])|^\*([^\s"<\[][\s\S]*?[^\s*])\*(?!\*)|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
544+
em: /^_([^\s_])_(?!_)|^\*([^\s*"<\[])\*(?!\*)|^_([^\s][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s"<\[][\s\S]*?[^\s*])\*(?!\*)|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
545545
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
546546
br: /^( {2,}|\\)\n(?!\s*$)/,
547547
del: noop,
548548
text: /^(`+|[^`])[\s\S]*?(?=[\\<!\[`*]|\b_| {2,}\n|$)/
549549
};
550550

551+
// list of punctuation marks from common mark spec
552+
// without ` and ] to workaround Rule 17 (inline code blocks/links)
553+
inline._punctuation = '!"#$%&\'()*+,\\-./:;<=>?@\\[^_{|}~';
554+
inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
555+
551556
inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
552557

553558
inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;

0 commit comments

Comments
 (0)