mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(italicsAndBold): fiz inconsistency in italicsAndBold parsing
The way showdown parsed cases suchs as this: ``` **foo **bar __foo __bar *foo *bar _foo _bar ``` was inconsistent. This established that `__` or `**` preceeding a word would not be parsed as em or strong. Closes #332
This commit is contained in:
parent
e4c43ea433
commit
a4f05d4693
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.
|
@ -12,16 +12,26 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
|
|||
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)([^\r]*?\S[*]*)\*\*/g, '<strong>$1</strong>');
|
||||
text = text.replace(/(\*)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
|
||||
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, '<strong>$1</strong>');
|
||||
text = text.replace(/\*\*(\S[\s\S]*?)\*\*/g, '<strong>$1</strong>');
|
||||
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, '<em>$1</em>');
|
||||
text = text.replace(/\*(\S[\s\S]*?)\*/g, '<em>$1</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;
|
||||
});
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('italicsAndBold.after', text, options, globals);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<p>foo *bar *baz</p>
|
||||
<p>foo **bar **baz</p>
|
||||
<p>foo _bar _baz</p>
|
||||
<p>foo __bar __baz</p>
|
||||
<p>foo *bar *baz *bazinga</p>
|
||||
<p>foo **bar **baz **bazinga</p>
|
||||
<p>foo _bar _baz __bazinga</p>
|
||||
<p>foo __bar __baz __bazinga</p>
|
||||
<p><em>f</em></p>
|
||||
<p><strong>f</strong></p>
|
||||
<p><em>f</em></p>
|
||||
<p><strong>f</strong></p>
|
||||
<p>foo **bar **baz <strong>bazinga bla</strong></p>
|
||||
<p>foo <strong>bar **baz **bazinga bla</strong></p>
|
||||
<p>foo <strong>**bar **baz **bazinga bla</strong></p>
|
|
@ -0,0 +1,29 @@
|
|||
foo *bar *baz
|
||||
|
||||
foo **bar **baz
|
||||
|
||||
foo _bar _baz
|
||||
|
||||
foo __bar __baz
|
||||
|
||||
foo *bar *baz *bazinga
|
||||
|
||||
foo **bar **baz **bazinga
|
||||
|
||||
foo _bar _baz __bazinga
|
||||
|
||||
foo __bar __baz __bazinga
|
||||
|
||||
*f*
|
||||
|
||||
**f**
|
||||
|
||||
_f_
|
||||
|
||||
__f__
|
||||
|
||||
foo **bar **baz **bazinga bla**
|
||||
|
||||
foo __bar **baz **bazinga bla__
|
||||
|
||||
foo __**bar **baz **bazinga bla__
|
Loading…
Reference in New Issue
Block a user