Browse Source

Merge 0ccc687367 into ff643c5bf5

pull/259/merge
Christopher 8 years ago
committed by GitHub
parent
commit
e852525e7d
  1. 5
      lib/renderer.js
  2. 24
      lib/token.js

5
lib/renderer.js

@ -37,7 +37,10 @@ default_rules.code_block = function (tokens, idx, options, env, slf) {
default_rules.fence = function (tokens, idx, options, env, slf) {
var token = tokens[idx],
// We will make modifications of the attributes object of this
// token while processing, so we obtain a shallow clone as to
// prevent modifying the token in the token list.
var token = tokens[idx].clone(),
info = token.info ? unescapeAll(token.info).trim() : '',
langName = '',
highlighted, i, tmpAttrs, tmpToken;

24
lib/token.js

@ -194,4 +194,28 @@ Token.prototype.attrJoin = function attrJoin(name, value) {
};
/**
* Token.clone()
*
* Obtain a shallow clone of the token. You can use this while rendering to
* prevent modifying the token list while rendering.
*/
Token.prototype.clone = function clone() {
var token = new Token(this.type, this.tag, this.nesting);
token.attrs = this.attrs;
token.level = this.level;
token.children = this.children;
token.content = this.content;
token.map = this.map;
token.markup = this.markup;
token.info = this.info;
token.meta = this.meta;
token.block = this.block;
token.hidden = this.hidden;
return token;
};
module.exports = Token;

Loading…
Cancel
Save