Browse Source

Attrs renderer signature change

pull/82/head
Vitaly Puzrin 10 years ago
parent
commit
917f5dee32
  1. 17
      lib/renderer.js

17
lib/renderer.js

@ -44,7 +44,7 @@ default_rules.fence = function (tokens, idx, options, env, self) {
highlighted = escapeHtml(token.content); highlighted = escapeHtml(token.content);
} }
return '<pre><code' + self.renderAttrs(token.attrs) + '>' return '<pre><code' + self.renderAttrs(token) + '>'
+ highlighted + highlighted
+ '</code></pre>\n'; + '</code></pre>\n';
}; };
@ -126,20 +126,19 @@ function Renderer() {
/** /**
* Renderer.renderAttrs(attrs) -> String * Renderer.renderAttrs(token) -> String
* - attrs (Array): array of token attributes
* *
* Render token attributes to string. * Render token attributes to string.
**/ **/
Renderer.prototype.renderAttrs = function renderAttrs(attrs) { Renderer.prototype.renderAttrs = function renderAttrs(token) {
var i, l, result; var i, l, result;
if (!attrs) { return ''; } if (!token.attrs) { return ''; }
result = ''; result = '';
for (i = 0, l = attrs.length; i < l; i++) { for (i = 0, l = token.attrs.length; i < l; i++) {
result += ' ' + escapeHtml(attrs[i][0]) + '="' + escapeHtml(attrs[i][1]) + '"'; result += ' ' + escapeHtml(token.attrs[i][0]) + '="' + escapeHtml(token.attrs[i][1]) + '"';
} }
return result; return result;
@ -181,9 +180,7 @@ Renderer.prototype.renderToken = function renderToken(tokens, idx, options) {
result += (token.nesting === -1 ? '</' : '<') + token.tag; result += (token.nesting === -1 ? '</' : '<') + token.tag;
// Encode attributes, e.g. `<img src="foo"` // Encode attributes, e.g. `<img src="foo"`
if (typeof token.attrs !== 'undefined') { result += this.renderAttrs(token);
result += this.renderAttrs(token.attrs);
}
// Add a slash for self-closing tags, e.g. `<img src="foo" /` // Add a slash for self-closing tags, e.g. `<img src="foo" /`
if (token.nesting === 0 && options.xhtmlOut) { if (token.nesting === 0 && options.xhtmlOut) {

Loading…
Cancel
Save