Skip to content

Commit 5c0d67e

Browse files
VladimirV99tivie
authored andcommitted
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
1 parent afbaec9 commit 5c0d67e

File tree

7 files changed

+22
-7
lines changed

7 files changed

+22
-7
lines changed

dist/showdown.js

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/subParsers/underline.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ showdown.subParser('underline', function (text, options, globals) {
88
text = globals.converter._dispatch('underline.before', text, options, globals);
99

1010
if (options.literalMidWordUnderscores) {
11-
text = text.replace(/\b_?__(\S[\s\S]*)___?\b/g, function (wm, txt) {
11+
text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) {
12+
return '<u>' + txt + '</u>';
13+
});
14+
text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) {
1215
return '<u>' + txt + '</u>';
1316
});
1417
} else {
15-
text = text.replace(/_?__(\S[\s\S]*?)___?/g, function (wm, m) {
18+
text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) {
19+
return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm;
20+
});
21+
text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
1622
return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm;
1723
});
1824
}

test/features/underline/simple.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
<p><u>an underlined sentence</u></p>
33
<p><u>three underscores are fine</u></p>
44
<p>_single_ underscores are left alone</p>
5+
<p><u>multiple</u> underlines in a <u>paragraph</u></p>

test/features/underline/simple.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ __an underlined sentence__
55
___three underscores are fine___
66

77
_single_ underscores are left alone
8+
9+
__multiple__ underlines in a __paragraph__

0 commit comments

Comments
 (0)