fix(literalMidWordAsterisks): fix option no longer treat punctuation as word character

Closes #398
This commit is contained in:
Estevao Soares dos Santos 2017-08-05 02:52:03 +01:00
parent 7332582db3
commit 8f05be7788
10 changed files with 47 additions and 15 deletions

12
dist/showdown.js vendored
View File

@ -2342,14 +2342,14 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
// Now parse asterisks
if (options.literalMidWordAsterisks) {
text = text.trim().replace(/(?:^| +)\*{3}(\S[\s\S]*?)\*{3}(?: +|$)/g, function (wm, txt) {
return parseInside (txt, ' <strong><em>', '</em></strong> ');
text = text.trim().replace(/(^| )\*{3}(\S[\s\S]*?)\*{3}([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
return parseInside (txt, lead + '<strong><em>', '</em></strong>' + trail);
});
text = text.trim().replace(/(?:^| +)\*{2}(\S[\s\S]*?)\*{2}(?: +|$)/g, function (wm, txt) {
return parseInside (txt, ' <strong>', '</strong> ');
text = text.trim().replace(/(^| )\*{2}(\S[\s\S]*?)\*{2}([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
return parseInside (txt, lead + '<strong>', '</strong>' + trail);
});
text = text.trim().replace(/(?:^| +)\*{1}(\S[\s\S]*?)\*{1}(?: +|$)/g, function (wm, txt) {
return parseInside (txt, ' <em>', '</em>' + (wm.slice(-1) === ' ' ? ' ' : ''));
text = text.trim().replace(/(^| )\*(\S[\s\S]*?)\*([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
return parseInside (txt, lead + '<em>', '</em>' + trail);
});
} else {
text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {

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

@ -40,14 +40,14 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
// Now parse asterisks
if (options.literalMidWordAsterisks) {
text = text.trim().replace(/(?:^| +)\*{3}(\S[\s\S]*?)\*{3}(?: +|$)/g, function (wm, txt) {
return parseInside (txt, ' <strong><em>', '</em></strong> ');
text = text.trim().replace(/(^| )\*{3}(\S[\s\S]*?)\*{3}([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
return parseInside (txt, lead + '<strong><em>', '</em></strong>' + trail);
});
text = text.trim().replace(/(?:^| +)\*{2}(\S[\s\S]*?)\*{2}(?: +|$)/g, function (wm, txt) {
return parseInside (txt, ' <strong>', '</strong> ');
text = text.trim().replace(/(^| )\*{2}(\S[\s\S]*?)\*{2}([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
return parseInside (txt, lead + '<strong>', '</strong>' + trail);
});
text = text.trim().replace(/(?:^| +)\*{1}(\S[\s\S]*?)\*{1}(?: +|$)/g, function (wm, txt) {
return parseInside (txt, ' <em>', '</em>' + (wm.slice(-1) === ' ' ? ' ' : ''));
text = text.trim().replace(/(^| )\*(\S[\s\S]*?)\*([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
return parseInside (txt, lead + '<em>', '</em>' + trail);
});
} else {
text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {

View File

@ -0,0 +1 @@
<p>strippers, <strong>hitler</strong>, and stalin</p>

View File

@ -0,0 +1 @@
strippers, **hitler**, and stalin

View File

@ -0,0 +1,9 @@
<p>some <em>foo</em> yeah</p>
<p>some <strong>foo</strong> yeah</p>
<p>some <strong><em>foo</em></strong> yeah</p>
<p>some word_foo_yeah</p>
<p>some word__foo__yeah</p>
<p>some word___foo___yeah</p>
<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>

View File

@ -0,0 +1,17 @@
some _foo_ yeah
some __foo__ yeah
some ___foo___ yeah
some word_foo_yeah
some word__foo__yeah
some word___foo___yeah
strippers, _hitler_, and stalin
strippers, __hitler__, and stalin
strippers, ___hitler___, and stalin

View File

@ -22,6 +22,8 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({headerLevelStart: 3});
} else if (testsuite[i].name === '#164.1.simple-autolink' || testsuite[i].name === '#204.certain-links-with-at-and-dot-break-url') {
converter = new showdown.Converter({simplifiedAutoLink: true});
} else if (testsuite[i].name === 'literalMidWordUnderscores') {
converter = new showdown.Converter({literalMidWordUnderscores: true});
} else if (testsuite[i].name === '#164.2.disallow-underscore-emphasis-mid-word') {
converter = new showdown.Converter({literalMidWordUnderscores: true});
} else if (testsuite[i].name === '#164.3.strikethrough' || testsuite[i].name === '#214.escaped-markdown-chars-break-strikethrough') {
@ -84,6 +86,8 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({backslashEscapesHTMLTags: true});
} else if (testsuite[i].name === '#379.openLinksInNewWindow-breaks-em-markdup') {
converter = new showdown.Converter({openLinksInNewWindow: true});
} else if (testsuite[i].name === '#398.literalMidWordAsterisks-treats-non-word-characters-as-characters') {
converter = new showdown.Converter({literalMidWordAsterisks: true});
} else {
converter = new showdown.Converter();
}