/**
* Renderer
*/
function Renderer(options) {
this.options = options || {};
this.raw = false;
}
/** Invoked when a renderer is marked as raw */
Renderer.prototype.tok = function(tok) {}
Renderer.prototype.tokens = function(tokens) {}
Renderer.prototype.token = function(token, parser) {}
Renderer.prototype.comment = function(tok) {
return tok.raw;
}
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.heading = function(text, level, raw) {
return '\n';
};
Renderer.prototype.hr = function() {
return '
\n';
};
Renderer.prototype.liststart = function(ordered, token, next){};
Renderer.prototype.list = function(body, ordered) {
var type = ordered ? 'ol' : 'ul';
return '<' + type + '>\n' + body + '' + type + '>\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 + '' + type + '>\n';
};
// 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 '
';
};
Renderer.prototype.del = function(text) {
return '' + text + '';
};
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 = '' + text + '';
return out;
};
Renderer.prototype.image = function(href, title, text) {
var out = '
';
return out;
};
module.exports = Renderer;