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-21 15:20:39 +02:00 committed by Estevao Soares dos Santos
parent afbaec98d9
commit 5c0d67e04a
7 changed files with 22 additions and 7 deletions

10
dist/showdown.js vendored
View File

@ -4450,11 +4450,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;
});
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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;
});
}

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__