You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-24 23:26:50 +02:00
All: Use Lerna to manage monorepo
This commit is contained in:
42
packages/lib/markupLanguageUtils.ts
Normal file
42
packages/lib/markupLanguageUtils.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import markdownUtils from './markdownUtils';
|
||||
import Setting from './models/Setting';
|
||||
import shim from './shim';
|
||||
import MarkupToHtml, { MarkupLanguage } from '@joplinapp/renderer/MarkupToHtml';
|
||||
|
||||
const htmlUtils = require('./htmlUtils');
|
||||
const Resource = require('./models/Resource');
|
||||
|
||||
class MarkupLanguageUtils {
|
||||
lib_(language:MarkupLanguage) {
|
||||
if (language === MarkupLanguage.Html) return htmlUtils;
|
||||
if (language === MarkupLanguage.Markdown) return markdownUtils;
|
||||
throw new Error(`Unsupported markup language: ${language}`);
|
||||
}
|
||||
|
||||
extractImageUrls(language:MarkupLanguage, text:string) {
|
||||
return this.lib_(language).extractImageUrls(text);
|
||||
}
|
||||
|
||||
// Create a new MarkupToHtml instance while injecting options specific to Joplin
|
||||
// desktop and mobile applications.
|
||||
newMarkupToHtml(options:any = null) {
|
||||
const subValues = Setting.subValues('markdown.plugin', Setting.toPlainObject());
|
||||
const pluginOptions:any = {};
|
||||
for (const n in subValues) {
|
||||
pluginOptions[n] = { enabled: subValues[n] };
|
||||
}
|
||||
|
||||
options = Object.assign({
|
||||
ResourceModel: Resource,
|
||||
pluginOptions: pluginOptions,
|
||||
tempDir: Setting.value('tempDir'),
|
||||
fsDriver: shim.fsDriver(),
|
||||
}, options);
|
||||
|
||||
return new MarkupToHtml(options);
|
||||
}
|
||||
}
|
||||
|
||||
const markupLanguageUtils = new MarkupLanguageUtils();
|
||||
|
||||
export default markupLanguageUtils;
|
Reference in New Issue
Block a user