fix(literalMidWordAsterisks): no longer treats colon as alphanumeric char

Closes #461
This commit is contained in:
Estevao Soares dos Santos 2017-11-17 15:23:23 +00:00
parent dd7efb5a8a
commit 21194c8a03
14 changed files with 62 additions and 6 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

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,8 @@
**Bold:**
**Bold**
**Bold**:
- **Bold**
- Tier 2

View File

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

View File

@ -0,0 +1,8 @@
__Bold:__
__Bold__
__Bold__:
- __Bold__
- Tier 2

View File

@ -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 () {
@ -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,