2019-07-16 20:05:47 +02:00
|
|
|
const MdToHtml = require('./MdToHtml');
|
|
|
|
const HtmlToHtml = require('./HtmlToHtml');
|
|
|
|
const Note = require('lib/models/Note');
|
|
|
|
|
|
|
|
class MarkupToHtml {
|
|
|
|
constructor(options) {
|
|
|
|
this.options_ = options;
|
|
|
|
this.renderers_ = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer(markupLanguage) {
|
|
|
|
if (this.renderers_[markupLanguage]) return this.renderers_[markupLanguage];
|
|
|
|
|
|
|
|
let RendererClass = null;
|
|
|
|
|
|
|
|
if (markupLanguage === Note.MARKUP_LANGUAGE_MARKDOWN) {
|
|
|
|
RendererClass = MdToHtml;
|
|
|
|
} else if (markupLanguage === Note.MARKUP_LANGUAGE_HTML) {
|
|
|
|
RendererClass = HtmlToHtml;
|
|
|
|
} else {
|
|
|
|
throw new Error('Invalid markup language: ' + markupLanguage);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.renderers_[markupLanguage] = new RendererClass(this.options_);
|
|
|
|
return this.renderers_[markupLanguage];
|
|
|
|
}
|
|
|
|
|
2019-07-19 18:48:38 +02:00
|
|
|
injectedJavaScript() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-07-16 20:05:47 +02:00
|
|
|
render(markupLanguage, markup, theme, options) {
|
|
|
|
return this.renderer(markupLanguage).render(markup, theme, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = MarkupToHtml;
|