|
|
@ -44,9 +44,14 @@ default_rules.fence = function (tokens, idx, options, env, slf) { |
|
|
|
highlighted, i, arr, tmpAttrs, tmpToken; |
|
|
|
|
|
|
|
if (info) { |
|
|
|
arr = info.split(/(\s+)/g); |
|
|
|
langName = arr[0]; |
|
|
|
langAttrs = arr.slice(2).join(''); |
|
|
|
if (!/\s/.test (info)) { |
|
|
|
langName = info; |
|
|
|
langAttrs = ''; |
|
|
|
} else { |
|
|
|
arr = info.split(/(\s+)/g); |
|
|
|
langName = arr[0]; |
|
|
|
langAttrs = arr.slice(2).join(''); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (options.highlight) { |
|
|
@ -55,7 +60,7 @@ default_rules.fence = function (tokens, idx, options, env, slf) { |
|
|
|
highlighted = escapeHtml(token.content); |
|
|
|
} |
|
|
|
|
|
|
|
if (highlighted.indexOf('<pre') === 0) { |
|
|
|
if (highlighted.slice(0, 4) === '<pre') { |
|
|
|
return highlighted + '\n'; |
|
|
|
} |
|
|
|
|
|
|
@ -63,12 +68,12 @@ default_rules.fence = function (tokens, idx, options, env, slf) { |
|
|
|
// May be, one day we will add .deepClone() for token and simplify this part, but
|
|
|
|
// now we prefer to keep things local.
|
|
|
|
if (info) { |
|
|
|
i = token.attrIndex('class'); |
|
|
|
tmpAttrs = token.attrs ? token.attrs.slice() : []; |
|
|
|
i = token.attrIndex('class'); |
|
|
|
|
|
|
|
if (i < 0) { |
|
|
|
tmpAttrs.push([ 'class', options.langPrefix + langName ]); |
|
|
|
tmpAttrs = [ [ 'class', options.langPrefix + langName ] ]; |
|
|
|
} else { |
|
|
|
tmpAttrs = token.attrs.slice(); |
|
|
|
tmpAttrs[i] = tmpAttrs[i].slice(); |
|
|
|
tmpAttrs[i][1] += ' ' + options.langPrefix + langName; |
|
|
|
} |
|
|
@ -78,6 +83,12 @@ default_rules.fence = function (tokens, idx, options, env, slf) { |
|
|
|
attrs: tmpAttrs |
|
|
|
}; |
|
|
|
|
|
|
|
if (i < 0) { |
|
|
|
return '<pre><code' + slf.renderAttrs(token) + slf.renderAttrs(tmpToken) + '>' |
|
|
|
+ highlighted |
|
|
|
+ '</code></pre>\n'; |
|
|
|
} |
|
|
|
|
|
|
|
return '<pre><code' + slf.renderAttrs(tmpToken) + '>' |
|
|
|
+ highlighted |
|
|
|
+ '</code></pre>\n'; |
|
|
@ -293,13 +304,17 @@ Renderer.prototype.renderInline = function (tokens, options, env) { |
|
|
|
* instead of simple escaping. |
|
|
|
**/ |
|
|
|
Renderer.prototype.renderInlineAsText = function (tokens, options, env) { |
|
|
|
var result = ''; |
|
|
|
var type, token, |
|
|
|
result = ''; |
|
|
|
|
|
|
|
for (var i = 0, len = tokens.length; i < len; i++) { |
|
|
|
if (tokens[i].type === 'text') { |
|
|
|
result += tokens[i].content; |
|
|
|
} else if (tokens[i].type === 'image') { |
|
|
|
result += this.renderInlineAsText(tokens[i].children, options, env); |
|
|
|
token = tokens[i]; |
|
|
|
type = token.type; |
|
|
|
|
|
|
|
if (type === 'text') { |
|
|
|
result += token.content; |
|
|
|
} else if (type === 'image') { |
|
|
|
result += this.renderInlineAsText(token.children, options, env); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -317,17 +332,18 @@ Renderer.prototype.renderInlineAsText = function (tokens, options, env) { |
|
|
|
* this method directly. |
|
|
|
**/ |
|
|
|
Renderer.prototype.render = function (tokens, options, env) { |
|
|
|
var i, len, type, |
|
|
|
var i, len, type, token, |
|
|
|
result = '', |
|
|
|
rules = this.rules; |
|
|
|
|
|
|
|
for (i = 0, len = tokens.length; i < len; i++) { |
|
|
|
type = tokens[i].type; |
|
|
|
token = tokens[i]; |
|
|
|
type = token.type; |
|
|
|
|
|
|
|
if (type === 'inline') { |
|
|
|
result += this.renderInline(tokens[i].children, options, env); |
|
|
|
result += this.renderInline(token.children, options, env); |
|
|
|
} else if (typeof rules[type] !== 'undefined') { |
|
|
|
result += rules[tokens[i].type](tokens, i, options, env, this); |
|
|
|
result += rules[type](tokens, i, options, env, this); |
|
|
|
} else { |
|
|
|
result += this.renderToken(tokens, i, options, env); |
|
|
|
} |
|
|
|