Skip to content

Commit

Permalink
fix(literalMidWordAsterisks): no longer treats colon as alphanumeric …
Browse files Browse the repository at this point in the history
…char

Closes #461
  • Loading branch information
tivie committed Nov 17, 2017
1 parent dd7efb5 commit 21194c8
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 17 deletions.
14 changes: 7 additions & 7 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.

4 changes: 2 additions & 2 deletions 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
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,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, lead, txt, trail) {
return parseInside (txt, lead + '<strong><em>', '</em></strong>' + trail);
text = text.replace(/([^*]|^)\B\*\*\*(\S[\s\S]+?)\*\*\*\B(?!\*)/g, function (wm, lead, txt) {
return parseInside (txt, lead + '<strong><em>', '</em></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.replace(/([^*]|^)\B\*\*(\S[\s\S]+?)\*\*\B(?!\*)/g, function (wm, lead, txt) {
return parseInside (txt, lead + '<strong>', '</strong>');
});
text = text.trim().replace(/(^| )\*(\S[\s\S]*?)\*([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
return parseInside (txt, lead + '<em>', '</em>' + trail);
text = text.replace(/([^*]|^)\B\*(\S[\s\S]+?)\*\B(?!\*)/g, function (wm, lead, txt) {
return parseInside (txt, lead + '<em>', '</em>');
});
} else {
text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {
Expand Down
5 changes: 5 additions & 0 deletions test/features/literalMidWordAsterisks/basic.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<p>this is a sentence*with*mid asterisks</p>
<p>this is a sentence**with**two mid asterisks</p>
<p>this is a sentence***with***three mid asterisks</p>
<p>this is double*asterisk*mid word with another**asterisk**word</p>
<p>this is double**asterisk**mid word with another**asterisk**word</p>
<p>this is double***asterisk***mid word with another***asterisk***word</p>
<p>this is double*asterisk**mid word with another***asterisk*word</p>
<p>this is double**asterisk*mid word with another***asterisk**word</p>
<p>this is a sentence with just*one asterisk</p>
<p>this is a sentence with just**one asterisk</p>
<p>this is a sentence with just***one asterisk</p>
Expand Down
10 changes: 10 additions & 0 deletions test/features/literalMidWordAsterisks/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ this is a sentence**with**two mid asterisks

this is a sentence***with***three mid asterisks

this is double*asterisk*mid word with another**asterisk**word

this is double**asterisk**mid word with another**asterisk**word

this is double***asterisk***mid word with another***asterisk***word

this is double*asterisk**mid word with another***asterisk*word

this is double**asterisk*mid word with another***asterisk**word

this is a sentence with just*one asterisk

this is a sentence with just**one asterisk
Expand Down
7 changes: 7 additions & 0 deletions test/features/literalMidWordAsterisks/punctation-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p><strong>Bold:</strong></p>
<p><strong>Bold</strong></p>
<p><strong>Bold</strong>:</p>
<ul>
<li><strong>Bold</strong><ul>
<li>Tier 2</li></ul></li>
</ul>
8 changes: 8 additions & 0 deletions test/features/literalMidWordAsterisks/punctation-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**Bold:**

**Bold**

**Bold**:

- **Bold**
- Tier 2
File renamed without changes.
7 changes: 7 additions & 0 deletions test/features/literalMidWordUnderscores/punctation-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p><strong>Bold:</strong></p>
<p><strong>Bold</strong></p>
<p><strong>Bold</strong>:</p>
<ul>
<li><strong>Bold</strong><ul>
<li>Tier 2</li></ul></li>
</ul>
8 changes: 8 additions & 0 deletions test/features/literalMidWordUnderscores/punctation-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__Bold:__

__Bold__

__Bold__:

- __Bold__
- Tier 2
11 changes: 11 additions & 0 deletions test/node/testsuite.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var bootstrap = require('../bootstrap.js'),
rawPrefixHeaderIdSuite = bootstrap.getTestSuite('test/features/rawPrefixHeaderId/'),
emojisSuite = bootstrap.getTestSuite('test/features/emojis/'),
underlineSuite = bootstrap.getTestSuite('test/features/underline/'),
literalMidWordUnderscoresSuite = bootstrap.getTestSuite('test/features/literalMidWordUnderscores/'),
literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/');

describe('makeHtml() features testsuite', function () {
Expand Down Expand Up @@ -211,6 +212,16 @@ describe('makeHtml() features testsuite', function () {
}
});

/** test literalMidWordUnderscores option **/
describe('literalMidWordUnderscores option', function () {
var converter,
suite = literalMidWordUnderscoresSuite;
for (var i = 0; i < suite.length; ++i) {
converter = new showdown.Converter({literalMidWordUnderscores: true});
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
}
});

/** test literalMidWordAsterisks option **/
describe('literalMidWordAsterisks option', function () {
var converter,
Expand Down

0 comments on commit 21194c8

Please sign in to comment.