mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(literalMidWordUnderscores): Inconsistent behavior of emphasis and strong with literalMidWordUndescores
Closes #333
This commit is contained in:
parent
a4f05d4693
commit
0292ae0dcb
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -6,34 +6,31 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
|
|||
// it's faster to have 2 separate regexes for each case than have just one
|
||||
// because of backtracing, in some cases, it could lead to an exponential effect
|
||||
// called "catastrophic backtrace". Ominous!
|
||||
|
||||
// Parse underscores
|
||||
if (options.literalMidWordUnderscores) {
|
||||
//underscores
|
||||
// Since we are consuming a \s character, we need to add it
|
||||
text = text.replace(/\b__(\S[\s\S]*?)__\b/gm, '<strong>$1</strong>');
|
||||
text = text.replace(/\b_(\S[\s\S]*?)_\b/gm, '<em>$1</em>');
|
||||
//asterisks
|
||||
text = text.replace(/\*\*(?=\S)([\s\S]*?\S[*]*)\*\*/g, '<strong>$1</strong>');
|
||||
text = text.replace(/\*(?=\S)([\s\S]*?\S)\*/g, '<em>$1</em>');
|
||||
|
||||
} else {
|
||||
// <strong> must go first:
|
||||
text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
|
||||
return (/\S$/.test(m)) ? '<strong>' + m + '</strong>' : wm;
|
||||
});
|
||||
text = text.replace(/\*\*(\S[\s\S]*?)\*\*/g, function (wm, m) {
|
||||
return (/\S$/.test(m)) ? '<strong>' + m + '</strong>' : wm;
|
||||
});
|
||||
// now <em>
|
||||
text = text.replace(/_(\S[\s\S]*?)_/g, function (wm, m) {
|
||||
// !/^_[^_]/.test(m) - test if it doesn't start with __ (since it seems redundant, we removed it)
|
||||
return (/\S$/.test(m)) ? '<em>' + m + '</em>' : wm;
|
||||
});
|
||||
text = text.replace(/\*(\S[\s\S]*?)\*/g, function (wm, m) {
|
||||
// !/^\*[^*]/.test(m) - test if it doesn't start with ** (since it seems redundant, we removed it)
|
||||
return (/\S$/.test(m)) ? '<em>' + m + '</em>' : wm;
|
||||
});
|
||||
}
|
||||
|
||||
// Now parse asterisks
|
||||
text = text.replace(/\*\*(\S[\s\S]*?)\*\*/g, function (wm, m) {
|
||||
return (/\S$/.test(m)) ? '<strong>' + m + '</strong>' : wm;
|
||||
});
|
||||
|
||||
text = text.replace(/\*(\S[\s\S]*?)\*/g, function (wm, m) {
|
||||
// !/^\*[^*]/.test(m) - test if it doesn't start with ** (since it seems redundant, we removed it)
|
||||
return (/\S$/.test(m)) ? '<em>' + m + '</em>' : wm;
|
||||
});
|
||||
|
||||
text = globals.converter._dispatch('italicsAndBold.after', text, options, globals);
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<p>pointer *ptr *thing</p>
|
||||
<p>something _else _bla</p>
|
||||
<p>something __else __bla</p>
|
||||
<p>foo *bar *baz</p>
|
||||
<p>foo **bar **baz</p>
|
||||
<p>foo _bar _baz</p>
|
||||
<p>foo __bar __baz</p>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
pointer *ptr *thing
|
||||
foo *bar *baz
|
||||
|
||||
something _else _bla
|
||||
foo **bar **baz
|
||||
|
||||
something __else __bla
|
||||
foo _bar _baz
|
||||
|
||||
foo __bar __baz
|
||||
|
|
Loading…
Reference in New Issue
Block a user