fix(italicsAndBold): Make italicsAndBold lazy (#608)

fix italicsAndBold if literalMidwordUnderscores option is enabled
it should end at the nearest closing underscores, not the furthest

Closes #544
This commit is contained in:
Vladimir Vuksanovic 2018-10-24 04:23:28 +02:00 committed by Estevão Soares dos Santos
parent e0fc6f8d6b
commit 4378abb4fa
9 changed files with 29 additions and 2 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ showdown.subParser('makehtml.italicsAndBold', function (text, options, globals)
// Parse underscores
if (options.literalMidWordUnderscores) {
text = text.replace(/\b___(\S[\s\S]*)___\b/g, function (wm, txt) {
text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) {
return parseInside (txt, '<strong><em>', '</em></strong>');
});
text = text.replace(/\b__(\S[\s\S]*)__\b/g, function (wm, txt) {
text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) {
return parseInside (txt, '<strong>', '</strong>');
});
text = text.replace(/\b_(\S[\s\S]*?)_\b/g, function (wm, txt) {

View File

@ -7,3 +7,6 @@
<p>strippers, <em>hitler</em>, and stalin</p>
<p>strippers, <strong>hitler</strong>, and stalin</p>
<p>strippers, <strong><em>hitler</em></strong>, and stalin</p>
<p><strong><em>multiple</em></strong> italics and bolds in a <strong><em>paragraph</em></strong></p>
<p><strong>multiple</strong> bolds in a <strong>paragraph</strong></p>
<p><em>multiple</em> italics in a <em>paragraph</em></p>

View File

@ -15,3 +15,9 @@ strippers, _hitler_, and stalin
strippers, __hitler__, and stalin
strippers, ___hitler___, and stalin
___multiple___ italics and bolds in a ___paragraph___
__multiple__ bolds in a __paragraph__
_multiple_ italics in a _paragraph_

View File

@ -37,3 +37,9 @@
<p>this is <strong><a href="//google.com">imbued link with strong</a></strong></p>
<p>this is <strong><a href="//google.com">imbued link with strong</a></strong></p>
<p>this link has underscore <a href="http://www.google.com/some_link">some_link</a></p>
<p><strong><em>multiple</em></strong> italics and bolds with underscores in a <strong><em>paragraph</em></strong></p>
<p><strong><em>multiple</em></strong> italics and bolds with asterisks in a <strong><em>paragraph</em></strong></p>
<p><strong>multiple</strong> bolds with underscores in a <strong>paragraph</strong></p>
<p><strong>multiple</strong> bolds with asterisks in a <strong>paragraph</strong></p>
<p><em>multiple</em> italics with underscores in a <em>paragraph</em></p>
<p><em>multiple</em> italics with asterisks in a <em>paragraph</em></p>

View File

@ -74,3 +74,15 @@ this is **<a href="//google.com">imbued link with strong</a>**
this is __<a href="//google.com">imbued link with strong</a>__
this link has underscore [some_link](http://www.google.com/some_link)
___multiple___ italics and bolds with underscores in a ___paragraph___
***multiple*** italics and bolds with asterisks in a ***paragraph***
__multiple__ bolds with underscores in a __paragraph__
**multiple** bolds with asterisks in a **paragraph**
_multiple_ italics with underscores in a _paragraph_
_multiple_ italics with asterisks in a _paragraph_