markdown: Avoid needless code duplication.

We only need to loop through the preprocessors
once, and we should use the options passed
in to the parser, not the default options
from the original setOptions call.

The first loop here was doing nothing.
This commit is contained in:
Steve Howell 2022-04-04 15:11:11 +00:00 committed by Tim Abbott
parent a77bf90601
commit 093eba077a
1 changed files with 2 additions and 5 deletions

View File

@ -1416,9 +1416,6 @@ function marked(src, opt, callback) {
htmlStashCounter = 0; htmlStashCounter = 0;
htmlStash = []; htmlStash = [];
for (var k = 0; k < opt.preprocessors.length; k++) {
src = opt.preprocessors[k](src);
}
try { try {
tokens = Lexer.lex(src, opt) tokens = Lexer.lex(src, opt)
@ -1480,8 +1477,8 @@ function marked(src, opt, callback) {
if (opt) opt = merge({}, marked.defaults, opt); if (opt) opt = merge({}, marked.defaults, opt);
htmlStashCounter = 0; htmlStashCounter = 0;
htmlStash = []; htmlStash = [];
for (var i = 0; i < marked.defaults.preprocessors.length; i++) { for (var i = 0; i < opt.preprocessors.length; i++) {
src = marked.defaults.preprocessors[i](src); src = opt.preprocessors[i](src);
} }
return Parser.parse(Lexer.lex(src, opt), opt); return Parser.parse(Lexer.lex(src, opt), opt);
} catch (e) { } catch (e) {