|
|
@ -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 langClass = ''; |
|
|
|
var langPrefix = options.langPrefix; |
|
|
|
var params, langName = ''; |
|
|
|
var langName = '', fenceName; |
|
|
|
var highlighted; |
|
|
|
|
|
|
|
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 + '"'; |
|
|
|
} |
|
|
|
|
|
|
@ -80,6 +93,7 @@ rules.fence = function (tokens, idx, options /*, env */) { |
|
|
|
+ '</code></pre>' + getBreak(tokens, idx); |
|
|
|
}; |
|
|
|
|
|
|
|
rules.fence_custom = {}; |
|
|
|
|
|
|
|
rules.heading_open = function (tokens, idx /*, options, env */) { |
|
|
|
return '<h' + tokens[idx].hLevel + '>'; |
|
|
@ -310,6 +324,8 @@ rules.dd_close = function() { |
|
|
|
function Renderer() { |
|
|
|
// Clone rules object to allow local modifications
|
|
|
|
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; |
|
|
|
|
|
|
|
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; |
|
|
@ -334,7 +350,7 @@ Renderer.prototype.render = function (tokens, options, env) { |
|
|
|
if (tokens[i].type === 'inline') { |
|
|
|
result += this.renderInline(tokens[i].children, options, env); |
|
|
|
} else { |
|
|
|
result += _rules[tokens[i].type](tokens, i, options, env); |
|
|
|
result += _rules[tokens[i].type](tokens, i, options, env, this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|