fix async code.

This commit is contained in:
Christopher Jeffrey 2013-05-21 18:56:13 -05:00
parent d6a5062087
commit f7d36a715b

View File

@ -1029,9 +1029,9 @@ function marked(src, opt, callback) {
if (opt) opt = merge({}, marked.defaults, opt); if (opt) opt = merge({}, marked.defaults, opt);
var tokens = Lexer.lex(tokens, opt) var tokens = Lexer.lex(src, opt)
, highlight = opt.highlight , highlight = opt.highlight
, pending = 0 , pending = tokens.length
, l = tokens.length , l = tokens.length
, i = 0; , i = 0;
@ -1046,10 +1046,13 @@ function marked(src, opt, callback) {
return callback(null, out); return callback(null, out);
}; };
if (!pending) return done();
for (; i < l; i++) { for (; i < l; i++) {
(function(token) { (function(token) {
if (token.type !== 'code') return; if (token.type !== 'code') {
pending++; return --pending || done();
}
return highlight(token.text, token.lang, function(err, code) { return highlight(token.text, token.lang, function(err, code) {
if (code == null || code === token.text) { if (code == null || code === token.text) {
return --pending || done(); return --pending || done();