Skip to content

Commit

Permalink
fix(italicsAndBold): Make italicsAndBold lazy
Browse files Browse the repository at this point in the history
fix italicsAndBold if literalMidwordUnderscores option is enabled
it should end at the nearest closing underscores, not the furthest

Closes showdownjs#544
  • Loading branch information
VladimirV99 committed Oct 21, 2018
1 parent 4da93e8 commit c858abb
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 70 deletions.
126 changes: 63 additions & 63 deletions dist/showdown.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/subParsers/makehtml/italicsAndBold.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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_
6 changes: 6 additions & 0 deletions test/functional/makehtml/cases/standard/emphasis.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
12 changes: 12 additions & 0 deletions test/functional/makehtml/cases/standard/emphasis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_

0 comments on commit c858abb

Please sign in to comment.