Skip to content

Commit

Permalink
fix(italicsAndBold): Make italicsAndBold lazy (#608)
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 #544
  • Loading branch information
VladimirV99 authored and tivie committed Nov 10, 2018
1 parent afbaec9 commit 5c0d67e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
10 changes: 8 additions & 2 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.

10 changes: 8 additions & 2 deletions src/subParsers/underline.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ showdown.subParser('underline', function (text, options, globals) {
text = globals.converter._dispatch('underline.before', text, options, globals);

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 '<u>' + txt + '</u>';
});
text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) {
return '<u>' + txt + '</u>';
});
} else {
text = text.replace(/_?__(\S[\s\S]*?)___?/g, function (wm, m) {
text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) {
return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm;
});
text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm;
});
}
Expand Down
1 change: 1 addition & 0 deletions test/features/underline/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
<p><u>an underlined sentence</u></p>
<p><u>three underscores are fine</u></p>
<p>_single_ underscores are left alone</p>
<p><u>multiple</u> underlines in a <u>paragraph</u></p>
2 changes: 2 additions & 0 deletions test/features/underline/simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ __an underlined sentence__
___three underscores are fine___

_single_ underscores are left alone

__multiple__ underlines in a __paragraph__

0 comments on commit 5c0d67e

Please sign in to comment.