|
@ -55,16 +55,29 @@ rules.code = function (tokens, idx /*, options, env */) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rules.fence = function (tokens, idx, options /*, env */) { |
|
|
rules.fence = function (tokens, idx, options, env, self) { |
|
|
var token = tokens[idx]; |
|
|
var token = tokens[idx]; |
|
|
var langClass = ''; |
|
|
var langClass = ''; |
|
|
var langPrefix = options.langPrefix; |
|
|
var langPrefix = options.langPrefix; |
|
|
var params, langName = ''; |
|
|
var langName = '', fenceName; |
|
|
var highlighted; |
|
|
var highlighted; |
|
|
|
|
|
|
|
|
if (token.params) { |
|
|
if (token.params) { |
|
|
params = token.params.split(/ +/g); |
|
|
|
|
|
langName = escapeHtml(replaceEntities(unescapeMd(params[0]))); |
|
|
//
|
|
|
|
|
|
// ```foo bar
|
|
|
|
|
|
//
|
|
|
|
|
|
// Try custom renderer "foo" first. That will simplify overwrite
|
|
|
|
|
|
// for diagrams, latex, and any other fenced block with custom look
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
fenceName = token.params.split(/\s+/g)[0]; |
|
|
|
|
|
|
|
|
|
|
|
if (self.rules.fence_custom.hasOwnProperty(fenceName)) { |
|
|
|
|
|
return self.rules.fence_custom[fenceName](tokens, idx, options, env, self); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
langName = escapeHtml(replaceEntities(unescapeMd(fenceName))); |
|
|
langClass = ' class="' + langPrefix + langName + '"'; |
|
|
langClass = ' class="' + langPrefix + langName + '"'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -80,6 +93,7 @@ rules.fence = function (tokens, idx, options /*, env */) { |
|
|
+ '</code></pre>' + getBreak(tokens, idx); |
|
|
+ '</code></pre>' + getBreak(tokens, idx); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
rules.fence_custom = {}; |
|
|
|
|
|
|
|
|
rules.heading_open = function (tokens, idx /*, options, env */) { |
|
|
rules.heading_open = function (tokens, idx /*, options, env */) { |
|
|
return '<h' + tokens[idx].hLevel + '>'; |
|
|
return '<h' + tokens[idx].hLevel + '>'; |
|
@ -310,6 +324,8 @@ rules.dd_close = function() { |
|
|
function Renderer() { |
|
|
function Renderer() { |
|
|
// Clone rules object to allow local modifications
|
|
|
// Clone rules object to allow local modifications
|
|
|
this.rules = assign({}, rules); |
|
|
this.rules = assign({}, rules); |
|
|
|
|
|
// exported helper, for custom rules only
|
|
|
|
|
|
this.getBreak = getBreak; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -318,7 +334,7 @@ Renderer.prototype.renderInline = function (tokens, options, env) { |
|
|
_rules = this.rules; |
|
|
_rules = this.rules; |
|
|
|
|
|
|
|
|
for (var i = 0, len = tokens.length; i < len; i++) { |
|
|
for (var i = 0, len = tokens.length; i < len; i++) { |
|
|
result += _rules[tokens[i].type](tokens, i, options, env); |
|
|
result += _rules[tokens[i].type](tokens, i, options, env, this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return result; |
|
|
return result; |
|
@ -334,7 +350,7 @@ Renderer.prototype.render = function (tokens, options, env) { |
|
|
if (tokens[i].type === 'inline') { |
|
|
if (tokens[i].type === 'inline') { |
|
|
result += this.renderInline(tokens[i].children, options, env); |
|
|
result += this.renderInline(tokens[i].children, options, env); |
|
|
} else { |
|
|
} else { |
|
|
result += _rules[tokens[i].type](tokens, i, options, env); |
|
|
result += _rules[tokens[i].type](tokens, i, options, env, this); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|