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
pull/619/head
Vladimir Vuksanovic 2018-10-24 04:23:28 +02:00 committed by Estevão Soares dos Santos
parent e0fc6f8d6b
commit 4378abb4fa
9 changed files with 97 additions and 70 deletions

126
dist/showdown.js vendored
View File

@ -1,5 +1,5 @@
;/*! showdown v 2.0.0-alpha1 - 25-09-2018 */
(function(){
;/*! showdown v 2.0.0-alpha1 - 21-10-2018 */
(function(){
/**
* Created by Tivie on 13-07-2015.
*/
@ -187,7 +187,7 @@ function allOptionsOn () {
}
return ret;
}
/**
* Created by Tivie on 06-01-2015.
*/
@ -567,7 +567,7 @@ showdown.validateExtension = function (ext) {
}
return true;
};
/**
* showdownjs helper functions
*/
@ -2255,7 +2255,7 @@ showdown.helper.emojis = {
'octocat': '<img width="20" height="20" align="absmiddle" src="https://assets-cdn.github.com/images/icons/emoji/octocat.png">',
'showdown': '<img width="20" height="20" align="absmiddle" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAS1BMVEX///8jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS3b1q3b1q3b1q3b1q3b1q3b1q3b1q3b1q0565CIAAAAGXRSTlMAQHCAYCCw/+DQwPCQUBAwoHCAEP+wwFBgS2fvBgAAAUZJREFUeAHs1cGy7BAUheFFsEDw/k97VTq3T6ge2EmdM+pvrP6Iwd74XV9Kb52xuMU4/uc1YNgZLFOeV8FGdhGrNk5SEgUyPxAEdj4LlMRDyhVAMVEa2M7TBSeVZAFPdqHgzSZJwPKgcLFLAooHDJo4EDCw4gAtBoJA5UFj4Ng5LOGLwVXZuoIlji/jeQHFk7+baHxrCjeUwB9+s88KndvlhcyBN5BSkYNQIVVb4pV+Npm7hhuKDs/uMP5KxT3WzSNNLIuuoDpMmuAVMruMSeDyQBi24DTr43LAY7ILA1QYaWkgfHzFthYYzg67SQsCbB8GhJUEGCtO9n0rSaCLxgJQjS/JSgMTg2eBDEHAJ+H350AsjYNYscrErgI2e/l+mdR967TCX/v6N0EhPECYCP0i+IAoYQOE8BogNhQMEMdrgAQWHaMAAGi5I5euoY9NAAAAAElFTkSuQmCC">'
};
/**
* These are all the transformations that form block-level
* tags like paragraphs, headers, and list items.
@ -2288,7 +2288,7 @@ showdown.subParser('makehtml.blockGamut', function (text, options, globals) {
return text;
});
showdown.subParser('makehtml.blockQuotes', function (text, options, globals) {
'use strict';
@ -2331,7 +2331,7 @@ showdown.subParser('makehtml.blockQuotes', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.blockQuotes.after', text, options, globals).getText();
return text;
});
/**
* Process Markdown `<pre><code>` blocks.
*/
@ -2370,7 +2370,7 @@ showdown.subParser('makehtml.codeBlocks', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.codeBlocks.after', text, options, globals).getText();
return text;
});
/**
*
* * Backtick quotes are used for <code></code> spans.
@ -2419,7 +2419,7 @@ showdown.subParser('makehtml.codeSpans', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.codeSpans.after', text, options, globals).getText();
return text;
});
/**
* Turn Markdown link shortcuts into XHTML <a> tags.
*/
@ -2482,7 +2482,7 @@ showdown.subParser('makehtml.completeHTMLDocument', function (text, options, glo
text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals).getText();
return text;
});
/**
* Convert all tabs to spaces
*/
@ -2516,7 +2516,7 @@ showdown.subParser('makehtml.detab', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.detab.after', text, options, globals).getText();
return text;
});
showdown.subParser('makehtml.ellipsis', function (text, options, globals) {
'use strict';
@ -2528,7 +2528,7 @@ showdown.subParser('makehtml.ellipsis', function (text, options, globals) {
return text;
});
/**
* These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items.
@ -2555,7 +2555,7 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
return text;
});
/**
* Smart processing for ampersands and angle brackets that need to be encoded.
*/
@ -2579,7 +2579,7 @@ showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, glob
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.after', text, options, globals).getText();
return text;
});
/**
* Returns the string, with after processing the following backslash escape sequences.
*
@ -2601,7 +2601,7 @@ showdown.subParser('makehtml.encodeBackslashEscapes', function (text, options, g
text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.after', text, options, globals).getText();
return text;
});
/**
* Encode/escape certain characters inside Markdown code runs.
* The point is that in code, these characters are literals,
@ -2625,7 +2625,7 @@ showdown.subParser('makehtml.encodeCode', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.encodeCode.after', text, options, globals).getText();
return text;
});
/**
* Within tags -- meaning between < and > -- encode [\ ` * _ ~ =] so they
* don't conflict with their use in Markdown for code, italics and strong.
@ -2652,7 +2652,7 @@ showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (t
text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.after', text, options, globals).getText();
return text;
});
/**
* Handle github codeblocks prior to running HashHTML so that
* HTML contained within the codeblock gets escaped properly
@ -2699,7 +2699,7 @@ showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals
return globals.converter._dispatch('makehtml.githubCodeBlocks.after', text, options, globals).getText();
});
showdown.subParser('makehtml.hashBlock', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('makehtml.hashBlock.before', text, options, globals).getText();
@ -2708,7 +2708,7 @@ showdown.subParser('makehtml.hashBlock', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.hashBlock.after', text, options, globals).getText();
return text;
});
/**
* Hash and escape <code> elements that should not be parsed as markdown
*/
@ -2727,7 +2727,7 @@ showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals).getText();
return text;
});
showdown.subParser('makehtml.hashElement', function (text, options, globals) {
'use strict';
@ -2747,7 +2747,7 @@ showdown.subParser('makehtml.hashElement', function (text, options, globals) {
return blockText;
};
});
showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('makehtml.hashHTMLBlocks.before', text, options, globals).getText();
@ -2846,7 +2846,7 @@ showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals)
text = globals.converter._dispatch('makehtml.hashHTMLBlocks.after', text, options, globals).getText();
return text;
});
/**
* Hash span elements that should not be parsed as markdown
*/
@ -2905,7 +2905,7 @@ showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals)
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals).getText();
return text;
});
/**
* Hash and escape <pre><code> elements that should not be parsed as markdown
*/
@ -2925,7 +2925,7 @@ showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals)
text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals).getText();
return text;
});
showdown.subParser('makehtml.headers', function (text, options, globals) {
'use strict';
@ -3052,7 +3052,7 @@ showdown.subParser('makehtml.headers', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.headers.after', text, options, globals).getText();
return text;
});
/**
* Turn Markdown link shortcuts into XHTML <a> tags.
*/
@ -3068,7 +3068,7 @@ showdown.subParser('makehtml.horizontalRule', function (text, options, globals)
text = globals.converter._dispatch('makehtml.horizontalRule.after', text, options, globals).getText();
return text;
});
/**
* Turn Markdown image shortcuts into <img> tags.
*/
@ -3173,7 +3173,7 @@ showdown.subParser('makehtml.images', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.images.after', text, options, globals).getText();
return text;
});
showdown.subParser('makehtml.italicsAndBold', function (text, options, globals) {
'use strict';
@ -3189,10 +3189,10 @@ showdown.subParser('makehtml.italicsAndBold', function (text, options, globals)
// Parse underscores
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 parseInside (txt, '<strong><em>', '</em></strong>');
});
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 parseInside (txt, '<strong>', '</strong>');
});
text = text.replace(/\b_(\S[\s\S]*?)_\b/g, function (wm, txt) {
@ -3240,7 +3240,7 @@ showdown.subParser('makehtml.italicsAndBold', function (text, options, globals)
text = globals.converter._dispatch('makehtml.italicsAndBold.after', text, options, globals).getText();
return text;
});
////
// makehtml/links.js
// Copyright (c) 2018 ShowdownJS
@ -3660,7 +3660,7 @@ showdown.subParser('makehtml.italicsAndBold', function (text, options, globals)
return text;
});
})();
/**
* Form HTML ordered (numbered) and unordered (bulleted) lists.
*/
@ -3877,7 +3877,7 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.lists.after', text, options, globals).getText();
return text;
});
/**
* Parse metadata at the top of the document
*/
@ -3927,7 +3927,7 @@ showdown.subParser('makehtml.metadata', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.metadata.after', text, options, globals).getText();
return text;
});
/**
* Remove one level of line-leading tabs or spaces
*/
@ -3945,7 +3945,7 @@ showdown.subParser('makehtml.outdent', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.outdent.after', text, options, globals).getText();
return text;
});
/**
*
*/
@ -4016,7 +4016,7 @@ showdown.subParser('makehtml.paragraphs', function (text, options, globals) {
text = text.replace(/\n+$/g, '');
return globals.converter._dispatch('makehtml.paragraphs.after', text, options, globals).getText();
});
/**
* Run extension
*/
@ -4037,7 +4037,7 @@ showdown.subParser('makehtml.runExtension', function (ext, text, options, global
return text;
});
/**
* These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items.
@ -4088,7 +4088,7 @@ showdown.subParser('makehtml.spanGamut', function (text, options, globals) {
text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals).getText();
return text;
});
showdown.subParser('makehtml.strikethrough', function (text, options, globals) {
'use strict';
@ -4100,7 +4100,7 @@ showdown.subParser('makehtml.strikethrough', function (text, options, globals) {
return text;
});
/**
* Strips link definitions from text, stores the URLs and titles in
* hash references.
@ -4154,7 +4154,7 @@ showdown.subParser('makehtml.stripLinkDefinitions', function (text, options, glo
return text;
});
showdown.subParser('makehtml.tables', function (text, options, globals) {
'use strict';
@ -4298,7 +4298,7 @@ showdown.subParser('makehtml.tables', function (text, options, globals) {
return text;
});
showdown.subParser('makehtml.underline', function (text, options, globals) {
'use strict';
@ -4325,7 +4325,7 @@ showdown.subParser('makehtml.underline', function (text, options, globals) {
return text;
});
/**
* Swap back in all the special characters we've hidden.
*/
@ -4341,7 +4341,7 @@ showdown.subParser('makehtml.unescapeSpecialChars', function (text, options, glo
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.after', text, options, globals).getText();
return text;
});
showdown.subParser('makeMarkdown.blockquote', function (node, globals) {
'use strict';
@ -4364,7 +4364,7 @@ showdown.subParser('makeMarkdown.blockquote', function (node, globals) {
txt = '> ' + txt.split('\n').join('\n> ');
return txt;
});
showdown.subParser('makeMarkdown.codeBlock', function (node, globals) {
'use strict';
@ -4372,13 +4372,13 @@ showdown.subParser('makeMarkdown.codeBlock', function (node, globals) {
num = node.getAttribute('precodenum');
return '```' + lang + '\n' + globals.preList[num] + '\n```';
});
showdown.subParser('makeMarkdown.codeSpan', function (node) {
'use strict';
return '`' + node.innerHTML + '`';
});
showdown.subParser('makeMarkdown.emphasis', function (node, globals) {
'use strict';
@ -4394,7 +4394,7 @@ showdown.subParser('makeMarkdown.emphasis', function (node, globals) {
}
return txt;
});
showdown.subParser('makeMarkdown.header', function (node, globals, headerLevel) {
'use strict';
@ -4412,13 +4412,13 @@ showdown.subParser('makeMarkdown.header', function (node, globals, headerLevel)
}
return txt;
});
showdown.subParser('makeMarkdown.hr', function () {
'use strict';
return '---';
});
showdown.subParser('makeMarkdown.image', function (node) {
'use strict';
@ -4437,7 +4437,7 @@ showdown.subParser('makeMarkdown.image', function (node) {
}
return txt;
});
showdown.subParser('makeMarkdown.links', function (node, globals) {
'use strict';
@ -4458,7 +4458,7 @@ showdown.subParser('makeMarkdown.links', function (node, globals) {
}
return txt;
});
showdown.subParser('makeMarkdown.list', function (node, globals, type) {
'use strict';
@ -4490,7 +4490,7 @@ showdown.subParser('makeMarkdown.list', function (node, globals, type) {
return txt.trim();
});
showdown.subParser('makeMarkdown.listItem', function (node, globals) {
'use strict';
@ -4516,7 +4516,7 @@ showdown.subParser('makeMarkdown.listItem', function (node, globals) {
return listItemTxt;
});
showdown.subParser('makeMarkdown.node', function (node, globals, spansOnly) {
@ -4637,7 +4637,7 @@ showdown.subParser('makeMarkdown.node', function (node, globals, spansOnly) {
return txt;
});
showdown.subParser('makeMarkdown.paragraph', function (node, globals) {
'use strict';
@ -4655,14 +4655,14 @@ showdown.subParser('makeMarkdown.paragraph', function (node, globals) {
return txt;
});
showdown.subParser('makeMarkdown.pre', function (node, globals) {
'use strict';
var num = node.getAttribute('prenum');
return '<pre>' + globals.preList[num] + '</pre>';
});
showdown.subParser('makeMarkdown.strikethrough', function (node, globals) {
'use strict';
@ -4678,7 +4678,7 @@ showdown.subParser('makeMarkdown.strikethrough', function (node, globals) {
}
return txt;
});
showdown.subParser('makeMarkdown.strong', function (node, globals) {
'use strict';
@ -4694,7 +4694,7 @@ showdown.subParser('makeMarkdown.strong', function (node, globals) {
}
return txt;
});
showdown.subParser('makeMarkdown.table', function (node, globals) {
'use strict';
@ -4765,7 +4765,7 @@ showdown.subParser('makeMarkdown.table', function (node, globals) {
return txt.trim();
});
showdown.subParser('makeMarkdown.tableCell', function (node, globals) {
'use strict';
@ -4781,7 +4781,7 @@ showdown.subParser('makeMarkdown.tableCell', function (node, globals) {
}
return txt.trim();
});
showdown.subParser('makeMarkdown.txt', function (node) {
'use strict';
@ -4825,7 +4825,7 @@ showdown.subParser('makeMarkdown.txt', function (node) {
return txt;
});
/**
* Created by Estevao on 31-05-2015.
*/
@ -5428,7 +5428,7 @@ showdown.Converter = function (converterOptions) {
metadata.raw = raw;
};
};
var root = this;
// AMD Loader
@ -5446,6 +5446,6 @@ if (typeof define === 'function' && define.amd) {
} else {
root.showdown = showdown;
}
}).call(this);
}).call(this);
//# sourceMappingURL=showdown.js.map
//# sourceMappingURL=showdown.js.map

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

@ -13,10 +13,10 @@ showdown.subParser('makehtml.italicsAndBold', function (text, options, globals)
// Parse underscores
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 parseInside (txt, '<strong><em>', '</em></strong>');
});
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 parseInside (txt, '<strong>', '</strong>');
});
text = text.replace(/\b_(\S[\s\S]*?)_\b/g, function (wm, txt) {

View File

@ -7,3 +7,6 @@
<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>
<p><strong><em>multiple</em></strong> italics and bolds in a <strong><em>paragraph</em></strong></p>
<p><strong>multiple</strong> bolds in a <strong>paragraph</strong></p>
<p><em>multiple</em> italics in a <em>paragraph</em></p>

View File

@ -15,3 +15,9 @@ strippers, _hitler_, and stalin
strippers, __hitler__, and stalin
strippers, ___hitler___, and stalin
___multiple___ italics and bolds in a ___paragraph___
__multiple__ bolds in a __paragraph__
_multiple_ italics in a _paragraph_

View File

@ -37,3 +37,9 @@
<p>this is <strong><a href="//google.com">imbued link with strong</a></strong></p>
<p>this is <strong><a href="//google.com">imbued link with strong</a></strong></p>
<p>this link has underscore <a href="http://www.google.com/some_link">some_link</a></p>
<p><strong><em>multiple</em></strong> italics and bolds with underscores in a <strong><em>paragraph</em></strong></p>
<p><strong><em>multiple</em></strong> italics and bolds with asterisks in a <strong><em>paragraph</em></strong></p>
<p><strong>multiple</strong> bolds with underscores in a <strong>paragraph</strong></p>
<p><strong>multiple</strong> bolds with asterisks in a <strong>paragraph</strong></p>
<p><em>multiple</em> italics with underscores in a <em>paragraph</em></p>
<p><em>multiple</em> italics with asterisks in a <em>paragraph</em></p>

View File

@ -74,3 +74,15 @@ this is **<a href="//google.com">imbued link with strong</a>**
this is __<a href="//google.com">imbued link with strong</a>__
this link has underscore [some_link](http://www.google.com/some_link)
___multiple___ italics and bolds with underscores in a ___paragraph___
***multiple*** italics and bolds with asterisks in a ***paragraph***
__multiple__ bolds with underscores in a __paragraph__
**multiple** bolds with asterisks in a **paragraph**
_multiple_ italics with underscores in a _paragraph_
_multiple_ italics with asterisks in a _paragraph_