Skip to content

Commit

Permalink
fix(literalMidWordAsterisks): fix option no longer treat punctuation …
Browse files Browse the repository at this point in the history
…as word character

Closes #398
  • Loading branch information
tivie committed Aug 5, 2017
1 parent 7332582 commit 8f05be7
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 15 deletions.
12 changes: 6 additions & 6 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.

12 changes: 6 additions & 6 deletions src/subParsers/italicsAndBold.js
Expand Up @@ -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) {
Expand Down
@@ -0,0 +1 @@
<p>strippers, <strong>hitler</strong>, and stalin</p>
@@ -0,0 +1 @@
strippers, **hitler**, and stalin
9 changes: 9 additions & 0 deletions test/features/literalMidWordUnderscores.html
@@ -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>
17 changes: 17 additions & 0 deletions test/features/literalMidWordUnderscores.md
@@ -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
4 changes: 4 additions & 0 deletions test/node/testsuite.features.js
Expand Up @@ -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') {
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 8f05be7

Please sign in to comment.