fix(underline): Make underline lazy

fix underline if literalMidwordUnderscores option is enabled
it should end at the nearest closing underscores, not the furthest
This commit is contained in:
Vladimir Vuksanovic 2018-10-21 15:20:39 +02:00
parent 4da93e8e13
commit 81edc70da7
7 changed files with 11 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

@ -8,11 +8,17 @@ showdown.subParser('makehtml.underline', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.underline.before', text, options, globals).getText();
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;
});
}

View File

@ -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>

View File

@ -5,3 +5,5 @@ __an underlined sentence__
___three underscores are fine___
_single_ underscores are left alone
__multiple__ underlines in a __paragraph__