2020-01-30 23:05:23 +02:00
|
|
|
const MdToHtml = require('./MdToHtml');
|
|
|
|
const HtmlToHtml = require('./HtmlToHtml');
|
|
|
|
|
|
|
|
class MarkupToHtml {
|
|
|
|
constructor(options) {
|
|
|
|
this.options_ = Object.assign({}, {
|
|
|
|
ResourceModel: {
|
|
|
|
isResourceUrl: () => false,
|
|
|
|
},
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
this.renderers_ = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer(markupLanguage) {
|
|
|
|
if (this.renderers_[markupLanguage]) return this.renderers_[markupLanguage];
|
|
|
|
|
|
|
|
let RendererClass = null;
|
|
|
|
|
|
|
|
if (markupLanguage === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN) {
|
|
|
|
RendererClass = MdToHtml;
|
|
|
|
} else if (markupLanguage === MarkupToHtml.MARKUP_LANGUAGE_HTML) {
|
|
|
|
RendererClass = HtmlToHtml;
|
|
|
|
} else {
|
|
|
|
throw new Error(`Invalid markup language: ${markupLanguage}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.renderers_[markupLanguage] = new RendererClass(this.options_);
|
|
|
|
return this.renderers_[markupLanguage];
|
|
|
|
}
|
|
|
|
|
|
|
|
injectedJavaScript() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2020-02-14 01:59:23 +02:00
|
|
|
async render(markupLanguage, markup, theme, options) {
|
2020-01-30 23:05:23 +02:00
|
|
|
return this.renderer(markupLanguage).render(markup, theme, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN = 1;
|
|
|
|
MarkupToHtml.MARKUP_LANGUAGE_HTML = 2;
|
|
|
|
|
|
|
|
module.exports = MarkupToHtml;
|