fix: parser slowness with certain inputs

A bad desinged regex was causing the parser to become extremelly slow
when given some inputs.

Closes #315
This commit is contained in:
Estevao Soares dos Santos 2016-12-19 12:13:30 +00:00
parent 143f324e4e
commit da8fb535c9
8 changed files with 8 additions and 7 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

@ -14,9 +14,9 @@ showdown.subParser('blockGamut', function (text, options, globals) {
// Do Horizontal Rules: // Do Horizontal Rules:
var key = showdown.subParser('hashBlock')('<hr />', options, globals); var key = showdown.subParser('hashBlock')('<hr />', options, globals);
text = text.replace(/^ {0,2}( ?\* ?){3,}[ \t]*$/gm, key); text = text.replace(/^( ?-){3,}[ \t]*$/gm, key);
text = text.replace(/^ {0,2}( ?- ?){3,}[ \t]*$/gm, key); text = text.replace(/^( ?\*){3,}[ \t]*$$/gm, key);
text = text.replace(/^ {0,2}( ?_ ?){3,}[ \t]*$/gm, key); text = text.replace(/^( ?_){3,}[ \t]*$$/gm, key);
text = showdown.subParser('lists')(text, options, globals); text = showdown.subParser('lists')(text, options, globals);
text = showdown.subParser('codeBlocks')(text, options, globals); text = showdown.subParser('codeBlocks')(text, options, globals);

View File

@ -3,7 +3,6 @@
*/ */
showdown.subParser('lists', function (text, options, globals) { showdown.subParser('lists', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('lists.before', text, options, globals); text = globals.converter._dispatch('lists.before', text, options, globals);
/** /**
* Process the contents of a single ordered or unordered list, splitting it * Process the contents of a single ordered or unordered list, splitting it
@ -78,7 +77,7 @@ showdown.subParser('lists', function (text, options, globals) {
// <ul><li>- - a</li></ul> // <ul><li>- - a</li></ul>
// So, to prevent it, we will put a marker (~A)in the beginning of the line // So, to prevent it, we will put a marker (~A)in the beginning of the line
// Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser // Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser
item = item.replace(/^([-*+]|\d\.)[ \t]+[\s\n]*/g, function (wm2) { item = item.replace(/^([-*+]|\d\.)[ \t]+[\S\n ]*/g, function (wm2) {
return '~A' + wm2; return '~A' + wm2;
}); });
@ -101,7 +100,6 @@ showdown.subParser('lists', function (text, options, globals) {
// now we need to remove the marker (~A) // now we need to remove the marker (~A)
item = item.replace('~A', ''); item = item.replace('~A', '');
// we can finally wrap the line in list item tags // we can finally wrap the line in list item tags
item = '<li' + bulletStyle + '>' + item + '</li>\n'; item = '<li' + bulletStyle + '>' + item + '</li>\n';
return item; return item;
@ -180,7 +178,6 @@ showdown.subParser('lists', function (text, options, globals) {
// strip sentinel // strip sentinel
text = text.replace(/~0/, ''); text = text.replace(/~0/, '');
text = globals.converter._dispatch('lists.after', text, options, globals); text = globals.converter._dispatch('lists.after', text, options, globals);
return text; return text;
}); });

View File

@ -0,0 +1,3 @@
<ul>
<li>- - - -- - - - - - - -- - - - - - - - - - - - - - - - - - - - abcd</li>
</ul>

View File

@ -0,0 +1 @@
- - - - -- - - - - - - -- - - - - - - - - - - - - - - - - - - - abcd