1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/ReactNativeClient/lib/markupLanguageUtils.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

const markdownUtils = require('lib/markdownUtils');
const htmlUtils = require('lib/htmlUtils');
const Setting = require('lib/models/Setting');
const Resource = require('lib/models/Resource');
const { MarkupToHtml } = require('joplin-renderer');
class MarkupLanguageUtils {
lib_(language) {
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}`);
}
extractImageUrls(language, text) {
return this.lib_(language).extractImageUrls(text);
}
// 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);
}
}
const markupLanguageUtils = new MarkupLanguageUtils();
2019-07-29 15:43:53 +02:00
module.exports = markupLanguageUtils;