mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
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:
parent
143f324e4e
commit
da8fb535c9
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -14,9 +14,9 @@ showdown.subParser('blockGamut', function (text, options, globals) {
|
|||
|
||||
// Do Horizontal Rules:
|
||||
var key = showdown.subParser('hashBlock')('<hr />', options, globals);
|
||||
text = text.replace(/^ {0,2}( ?\* ?){3,}[ \t]*$/gm, key);
|
||||
text = text.replace(/^ {0,2}( ?- ?){3,}[ \t]*$/gm, key);
|
||||
text = text.replace(/^ {0,2}( ?_ ?){3,}[ \t]*$/gm, key);
|
||||
text = text.replace(/^( ?-){3,}[ \t]*$/gm, key);
|
||||
text = text.replace(/^( ?\*){3,}[ \t]*$$/gm, key);
|
||||
text = text.replace(/^( ?_){3,}[ \t]*$$/gm, key);
|
||||
|
||||
text = showdown.subParser('lists')(text, options, globals);
|
||||
text = showdown.subParser('codeBlocks')(text, options, globals);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
showdown.subParser('lists', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('lists.before', text, options, globals);
|
||||
/**
|
||||
* 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>
|
||||
// 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
|
||||
item = item.replace(/^([-*+]|\d\.)[ \t]+[\s\n]*/g, function (wm2) {
|
||||
item = item.replace(/^([-*+]|\d\.)[ \t]+[\S\n ]*/g, function (wm2) {
|
||||
return '~A' + wm2;
|
||||
});
|
||||
|
||||
|
@ -101,7 +100,6 @@ showdown.subParser('lists', function (text, options, globals) {
|
|||
|
||||
// now we need to remove the marker (~A)
|
||||
item = item.replace('~A', '');
|
||||
|
||||
// we can finally wrap the line in list item tags
|
||||
item = '<li' + bulletStyle + '>' + item + '</li>\n';
|
||||
return item;
|
||||
|
@ -180,7 +178,6 @@ showdown.subParser('lists', function (text, options, globals) {
|
|||
|
||||
// strip sentinel
|
||||
text = text.replace(/~0/, '');
|
||||
|
||||
text = globals.converter._dispatch('lists.after', text, options, globals);
|
||||
return text;
|
||||
});
|
||||
|
|
3
test/issues/#312.spaced-dashes-followed-by-char4.html
Normal file
3
test/issues/#312.spaced-dashes-followed-by-char4.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<ul>
|
||||
<li>- - - -- - - - - - - -- - - - - - - - - - - - - - - - - - - - abcd</li>
|
||||
</ul>
|
1
test/issues/#312.spaced-dashes-followed-by-char4.md
Normal file
1
test/issues/#312.spaced-dashes-followed-by-char4.md
Normal file
|
@ -0,0 +1 @@
|
|||
- - - - -- - - - - - - -- - - - - - - - - - - - - - - - - - - - abcd
|
Loading…
Reference in New Issue
Block a user