2019-07-14 17:00:02 +02:00
|
|
|
const markdownUtils = require('lib/markdownUtils');
|
|
|
|
const htmlUtils = require('lib/htmlUtils');
|
2019-12-29 19:58:40 +02:00
|
|
|
const Setting = require('lib/models/Setting');
|
|
|
|
const Resource = require('lib/models/Resource');
|
2020-01-30 23:05:23 +02:00
|
|
|
const { MarkupToHtml } = require('lib/joplin-renderer');
|
2019-07-14 17:00:02 +02:00
|
|
|
|
|
|
|
class MarkupLanguageUtils {
|
|
|
|
lib_(language) {
|
2019-12-29 19:58:40 +02:00
|
|
|
if (language === MarkupToHtml.MARKUP_LANGUAGE_HTML) return htmlUtils;
|
|
|
|
if (language === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN) return markdownUtils;
|
2019-09-19 23:51:18 +02:00
|
|
|
throw new Error(`Unsupported markup language: ${language}`);
|
2019-07-14 17:00:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extractImageUrls(language, text) {
|
|
|
|
return this.lib_(language).extractImageUrls(text);
|
|
|
|
}
|
2019-12-29 19:58:40 +02:00
|
|
|
|
|
|
|
// Create a new MarkupToHtml instance while injecting options specific to Joplin
|
|
|
|
// desktop and mobile applications.
|
|
|
|
newMarkupToHtml(options = null) {
|
|
|
|
const subValues = Setting.subValues('markdown.plugin', Setting.toPlainObject());
|
|
|
|
const pluginOptions = {};
|
|
|
|
for (const n in subValues) {
|
|
|
|
pluginOptions[n] = { enabled: subValues[n] };
|
|
|
|
}
|
|
|
|
|
|
|
|
options = Object.assign({
|
|
|
|
ResourceModel: Resource,
|
|
|
|
pluginOptions: pluginOptions,
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
return new MarkupToHtml(options);
|
|
|
|
}
|
2019-07-14 17:00:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const markupLanguageUtils = new MarkupLanguageUtils();
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = markupLanguageUtils;
|