Browse Source

Splitted .render() methods to simplify monkeypatching

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
2cc37e20d0
  1. 19
      lib/index.js
  2. 13
      lib/renderer.js

19
lib/index.js

@ -68,11 +68,11 @@ Remarkable.prototype.use = function (plugin, opts) {
};
// Main method that does all magic :)
// Parse input string, returns tokens array. Modify `env` with
// definitions data.
//
Remarkable.prototype.render = function (src) {
var tokens, tok, i, l, env = { references: Object.create(null) };
Remarkable.prototype.parse = function (src, env) {
var tokens, tok, i, l;
// Parse blocks
tokens = this.block.parse(src, this.options, env);
@ -84,8 +84,15 @@ Remarkable.prototype.render = function (src) {
}
}
// Render
return this.renderer.render(tokens, this.options, env);
return tokens;
};
// Main method that does all magic :)
//
Remarkable.prototype.render = function (src) {
var env = { references: {} };
return this.renderer.render(this.parse(src, env), this.options, env);
};

13
lib/renderer.js

@ -228,6 +228,17 @@ function Renderer() {
}
Renderer.prototype.renderInline = function (tokens, options) {
var result = '';
for (var i = 0, len = tokens.length; i < len; i++) {
result += rules[tokens[i].type](tokens, i, options);
}
return result;
};
Renderer.prototype.render = function (tokens, options) {
var i, len, name,
result = '',
@ -272,7 +283,7 @@ Renderer.prototype.render = function (tokens, options) {
}
if (tokens[i].type === 'inline') {
result += this.render(tokens[i].children, options);
result += this.renderInline(tokens[i].children, options);
} else {
result += rules[name](tokens, i, options);
}

Loading…
Cancel
Save