|
|
@ -8,10 +8,8 @@ |
|
|
|
|
|
|
|
import { assign, unescapeAll, escapeHtml } from './common/utils.mjs' |
|
|
|
|
|
|
|
|
|
|
|
const default_rules = {} |
|
|
|
|
|
|
|
|
|
|
|
default_rules.code_inline = function (tokens, idx, options, env, slf) { |
|
|
|
const token = tokens[idx] |
|
|
|
|
|
|
@ -20,7 +18,6 @@ default_rules.code_inline = function (tokens, idx, options, env, slf) { |
|
|
|
'</code>' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
default_rules.code_block = function (tokens, idx, options, env, slf) { |
|
|
|
const token = tokens[idx] |
|
|
|
|
|
|
@ -29,7 +26,6 @@ default_rules.code_block = function (tokens, idx, options, env, slf) { |
|
|
|
'</code></pre>\n' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
default_rules.fence = function (tokens, idx, options, env, slf) { |
|
|
|
const token = tokens[idx] |
|
|
|
const info = token.info ? unescapeAll(token.info).trim() : '' |
|
|
@ -78,7 +74,6 @@ default_rules.fence = function (tokens, idx, options, env, slf) { |
|
|
|
return `<pre><code${slf.renderAttrs(token)}>${highlighted}</code></pre>\n` |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
default_rules.image = function (tokens, idx, options, env, slf) { |
|
|
|
const token = tokens[idx] |
|
|
|
|
|
|
@ -93,7 +88,6 @@ default_rules.image = function (tokens, idx, options, env, slf) { |
|
|
|
return slf.renderToken(tokens, idx, options) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
default_rules.hardbreak = function (tokens, idx, options /*, env */) { |
|
|
|
return options.xhtmlOut ? '<br />\n' : '<br>\n' |
|
|
|
} |
|
|
@ -101,12 +95,10 @@ default_rules.softbreak = function (tokens, idx, options /*, env */) { |
|
|
|
return options.breaks ? (options.xhtmlOut ? '<br />\n' : '<br>\n') : '\n' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
default_rules.text = function (tokens, idx /*, options, env */) { |
|
|
|
return escapeHtml(tokens[idx].content) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
default_rules.html_block = function (tokens, idx /*, options, env */) { |
|
|
|
return tokens[idx].content |
|
|
|
} |
|
|
@ -114,14 +106,12 @@ default_rules.html_inline = function (tokens, idx /*, options, env */) { |
|
|
|
return tokens[idx].content |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* new Renderer() |
|
|
|
* |
|
|
|
* Creates new [[Renderer]] instance and fill [[Renderer#rules]] with defaults. |
|
|
|
**/ |
|
|
|
function Renderer () { |
|
|
|
|
|
|
|
/** |
|
|
|
* Renderer#rules -> Object |
|
|
|
* |
|
|
@ -153,7 +143,6 @@ function Renderer () { |
|
|
|
this.rules = assign({}, default_rules) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Renderer.renderAttrs(token) -> String |
|
|
|
* |
|
|
@ -173,7 +162,6 @@ Renderer.prototype.renderAttrs = function renderAttrs (token) { |
|
|
|
return result |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Renderer.renderToken(tokens, idx, options) -> String |
|
|
|
* - tokens (Array): list of tokens |
|
|
@ -227,7 +215,6 @@ Renderer.prototype.renderToken = function renderToken (tokens, idx, options) { |
|
|
|
// Block-level tag containing an inline tag.
|
|
|
|
//
|
|
|
|
needLf = false |
|
|
|
|
|
|
|
} else if (nextToken.nesting === -1 && nextToken.tag === token.tag) { |
|
|
|
// Opening tag + closing tag of the same type. E.g. `<li></li>`.
|
|
|
|
//
|
|
|
@ -242,7 +229,6 @@ Renderer.prototype.renderToken = function renderToken (tokens, idx, options) { |
|
|
|
return result |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Renderer.renderInline(tokens, options, env) -> String |
|
|
|
* - tokens (Array): list on block tokens to render |
|
|
@ -268,7 +254,6 @@ Renderer.prototype.renderInline = function (tokens, options, env) { |
|
|
|
return result |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** internal |
|
|
|
* Renderer.renderInlineAsText(tokens, options, env) -> String |
|
|
|
* - tokens (Array): list on block tokens to render |
|
|
@ -295,7 +280,6 @@ Renderer.prototype.renderInlineAsText = function (tokens, options, env) { |
|
|
|
return result |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Renderer.render(tokens, options, env) -> String |
|
|
|
* - tokens (Array): list on block tokens to render |
|
|
|