Skip to content

Commit f8d556a

Browse files
authored
Merge pull request #1383 from RomanGotsiy/master
Fix emphasis followed by a punctuation
2 parents 939b637 + 2e7c9b5 commit f8d556a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-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}/;

test/specs/marked/marked-spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,17 @@ describe('Marked Table cells', function() {
8787
messenger.test(spec, section, ignore);
8888
});
8989
});
90+
91+
describe('Emphasis extra tests', function() {
92+
var section = 'Emphasis extra tests';
93+
94+
var shouldPassButFails = [];
95+
96+
var willNotBeAttemptedByCoreTeam = [];
97+
98+
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
99+
100+
markedSpec.forEach(function(spec) {
101+
messenger.test(spec, section, ignore);
102+
});
103+
});

test/specs/marked/marked.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,11 @@
9494
"markdown": "**[email protected]**",
9595
"html": "<p><strong><a href=\"mailto:[email protected]\">[email protected]</a></strong></p>",
9696
"example": 1327
97+
},
98+
{
99+
"section": "Emphasis extra tests",
100+
"markdown": "_test_. _test_: _test_! _test_? _test_-",
101+
"html": "<p><em>test</em>. <em>test</em>: <em>test</em>! <em>test</em>? <em>test</em>-</p>",
102+
"example": 15
97103
}
98104
]

0 commit comments

Comments
 (0)