1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-02 22:49:09 +02:00

More refactoring to easily handle multiple renderers

This commit is contained in:
Laurent Cozic
2019-07-16 19:05:47 +01:00
parent fbb0ac5892
commit 38e8a881d5
20 changed files with 115 additions and 29 deletions

View File

@@ -0,0 +1,35 @@
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];
}
render(markupLanguage, markup, theme, options) {
return this.renderer(markupLanguage).render(markup, theme, options);
}
}
module.exports = MarkupToHtml;