var _utils = require('./utils'); var escape = _utils.escape; var unescape = _utils.unescape; /** * Renderer */ var defaultOptions = { langPrefix: 'lang-', smartypants: false, headerPrefix: '', headerAutoId: true, xhtml: false, }; function Renderer(options) { this.options = options || defaultOptions; } Renderer.prototype.code = function(code, lang, escaped) { if (this.options.highlight) { var out = this.options.highlight(code, lang); if (out != null && out !== code) { escaped = true; code = out; } } if (!lang) { return '
'
      + (escaped ? code : escape(code, true))
      + '\n
'; } return '
'
    + (escaped ? code : escape(code, true))
    + '\n
\n'; }; Renderer.prototype.blockquote = function(quote) { return '
\n' + quote + '
\n'; }; Renderer.prototype.html = function(html) { return html; }; Renderer.prototype._createId = function(str) { // replace " " and all punctuation characters to "-" str = str.toLowerCase().replace(/[\s\]\[\!\"\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\_\`\{\|\}\~\-]+/g, '-'); try { str = encodeURIComponent(str); } catch (e) { str = str.replace(/[^\w]+/g, '-'); } return str.replace(/-$/, ''); }; Renderer.prototype.heading = function(text, level, raw) { var id = /({#)(.+)(})/g.exec(raw); id = id? id[2] : null; if (!id && this.options.headerAutoId !== false) id = this._createId(raw) return '' + text.replace(/{#.+}/g, '') + '\n'; }; Renderer.prototype.hr = function() { return this.options.xhtml ? '
\n' : '
\n'; }; Renderer.prototype.list = function(body, ordered) { var type = ordered ? 'ol' : 'ul'; return '<' + type + '>\n' + body + '\n'; }; Renderer.prototype.listitem = function(text) { return '
  • ' + text + '
  • \n'; }; Renderer.prototype.paragraph = function(text) { return '

    ' + text + '

    \n'; }; Renderer.prototype.table = function(header, body) { return '\n' + '\n' + header + '\n' + '\n' + body + '\n' + '
    \n'; }; Renderer.prototype.tablerow = function(content) { return '\n' + content + '\n'; }; Renderer.prototype.tablecell = function(content, flags) { var type = flags.header ? 'th' : 'td'; var tag = flags.align ? '<' + type + ' style="text-align:' + flags.align + '">' : '<' + type + '>'; return tag + content + '\n'; }; Renderer.prototype.math = function(content, language, display) { mode = display ? '; mode=display' : ''; return ''; } // span level renderer Renderer.prototype.strong = function(text) { return '' + text + ''; }; Renderer.prototype.em = function(text) { return '' + text + ''; }; Renderer.prototype.codespan = function(text) { return '' + text + ''; }; Renderer.prototype.br = function() { return this.options.xhtml ? '
    ' : '
    '; }; Renderer.prototype.del = function(text) { return '' + text + ''; }; Renderer.prototype.reffn = function(refname) { return '' + refname + '' } Renderer.prototype.footnote = function(refname, text) { return '
    \n' + '' + refname + '. ' + text + '\n' + '
    \n'; } Renderer.prototype.link = function(href, title, text) { if (this.options.sanitize) { try { var prot = decodeURIComponent(unescape(href)) .replace(/[^\w:]/g, '') .toLowerCase(); } catch (e) { return ''; } if (prot.indexOf('javascript:') === 0) { return ''; } } var out = ''; return out; }; Renderer.prototype.image = function(href, title, text) { var out = '' + text + '' : '>'; return out; }; module.exports = Renderer;