|
|
@ -226,20 +226,16 @@ Renderer.prototype.renderToken = function renderToken(tokens, idx, options) { |
|
|
|
**/ |
|
|
|
Renderer.prototype.renderInline = function (tokens, options, env) { |
|
|
|
var type, |
|
|
|
result = '', |
|
|
|
rules = this.rules; |
|
|
|
|
|
|
|
for (var i = 0, len = tokens.length; i < len; i++) { |
|
|
|
type = tokens[i].type; |
|
|
|
return tokens.map(function(token, i) { |
|
|
|
type = token.type; |
|
|
|
|
|
|
|
if (typeof rules[type] !== 'undefined') { |
|
|
|
result += rules[type](tokens, i, options, env, this); |
|
|
|
} else { |
|
|
|
result += this.renderToken(tokens, i, options); |
|
|
|
} |
|
|
|
} |
|
|
|
return rules[type](tokens, i, options, env, this); |
|
|
|
|
|
|
|
return result; |
|
|
|
return this.renderToken(tokens, i, options); |
|
|
|
}, this); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -279,23 +275,40 @@ Renderer.prototype.renderInlineAsText = function (tokens, options, env) { |
|
|
|
* this method directly. |
|
|
|
**/ |
|
|
|
Renderer.prototype.render = function (tokens, options, env) { |
|
|
|
var i, len, type, |
|
|
|
return this.renderTokens(tokens, options, env).reduce(function(collector, token) { |
|
|
|
return collector + token; |
|
|
|
}, ''); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Renderer.renderTokens(tokens, options, env) -> String |
|
|
|
* - tokens (Array): list on block tokens to renter |
|
|
|
* - options (Object): params of parser instance |
|
|
|
* - env (Object): additional data from parsed input (references, for example) |
|
|
|
* |
|
|
|
* Takes token stream and generates html-like tokens. Probably, you will never need to call |
|
|
|
* this method directly. |
|
|
|
**/ |
|
|
|
Renderer.prototype.renderTokens = function (tokens, options, env) { |
|
|
|
var len, type, |
|
|
|
result = '', |
|
|
|
rules = this.rules; |
|
|
|
|
|
|
|
for (i = 0, len = tokens.length; i < len; i++) { |
|
|
|
type = tokens[i].type; |
|
|
|
return tokens.reduce(function(collector, token, i) { |
|
|
|
type = token.type; |
|
|
|
|
|
|
|
if (type === 'inline') { |
|
|
|
result += this.renderInline(tokens[i].children, options, env); |
|
|
|
} else if (typeof rules[type] !== 'undefined') { |
|
|
|
result += rules[tokens[i].type](tokens, i, options, env, this); |
|
|
|
} else { |
|
|
|
result += this.renderToken(tokens, i, options, env); |
|
|
|
if (type === 'inline') |
|
|
|
return collector.concat(this.renderInline(token.children, options, env)); |
|
|
|
|
|
|
|
if (typeof rules[type] !== 'undefined') { |
|
|
|
collector.push(rules[type](tokens, i, options, env, this)); |
|
|
|
return collector; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
collector.push(this.renderToken(tokens, i, options, env)); |
|
|
|
return collector; |
|
|
|
}.bind(this), []); |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = Renderer; |
|
|
|