2020-10-21 01:23:55 +02:00
|
|
|
import markdownUtils from 'lib/markdownUtils';
|
|
|
|
import Setting from 'lib/models/Setting';
|
|
|
|
import shim from 'lib/shim';
|
|
|
|
import MarkupToHtml, { MarkupLanguage } from 'lib/joplin-renderer/MarkupToHtml';
|
|
|
|
|
2019-07-14 17:00:02 +02:00
|
|
|
const htmlUtils = require('lib/htmlUtils');
|
2019-12-29 19:58:40 +02:00
|
|
|
const Resource = require('lib/models/Resource');
|
2019-07-14 17:00:02 +02:00
|
|
|
|
|
|
|
class MarkupLanguageUtils {
|
2020-10-21 01:23:55 +02:00
|
|
|
lib_(language:MarkupLanguage) {
|
|
|
|
if (language === MarkupLanguage.Html) return htmlUtils;
|
|
|
|
if (language === MarkupLanguage.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
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
extractImageUrls(language:MarkupLanguage, text:string) {
|
2019-07-14 17:00:02 +02:00
|
|
|
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.
|
2020-10-21 01:23:55 +02:00
|
|
|
newMarkupToHtml(options:any = null) {
|
2019-12-29 19:58:40 +02:00
|
|
|
const subValues = Setting.subValues('markdown.plugin', Setting.toPlainObject());
|
2020-10-21 01:23:55 +02:00
|
|
|
const pluginOptions:any = {};
|
2019-12-29 19:58:40 +02:00
|
|
|
for (const n in subValues) {
|
|
|
|
pluginOptions[n] = { enabled: subValues[n] };
|
|
|
|
}
|
|
|
|
|
|
|
|
options = Object.assign({
|
|
|
|
ResourceModel: Resource,
|
|
|
|
pluginOptions: pluginOptions,
|
2020-03-10 01:24:57 +02:00
|
|
|
tempDir: Setting.value('tempDir'),
|
|
|
|
fsDriver: shim.fsDriver(),
|
2019-12-29 19:58:40 +02:00
|
|
|
}, options);
|
|
|
|
|
|
|
|
return new MarkupToHtml(options);
|
|
|
|
}
|
2019-07-14 17:00:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const markupLanguageUtils = new MarkupLanguageUtils();
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
export default markupLanguageUtils;
|