mirror of
https://github.com/laurent22/joplin.git
synced 2026-10-25 02:47:28 +00:00
Plugins: Added a renderMarkup command to render MD or HTML markup to HTML
This commit is contained in:
1 parent
a2d0908eb6
commit
ff09937ca2
14 files changed
+91
-51
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import BaseModel from '../BaseModel';
|
||||
import Note from '../models/Note';
|
||||
import Resource from '../models/Resource';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
let resourceCache_: any = {};
|
||||
|
||||
export function clearResourceCache() {
|
||||
resourceCache_ = {};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
export default async function attachedResources(noteBody: string): Promise<any> {
|
||||
if (!noteBody) return {};
|
||||
const resourceIds = await Note.linkedItemIdsByType(BaseModel.TYPE_RESOURCE, noteBody);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
const output: any = {};
|
||||
for (let i = 0; i < resourceIds.length; i++) {
|
||||
const id = resourceIds[i];
|
||||
|
||||
if (resourceCache_[id]) {
|
||||
output[id] = resourceCache_[id];
|
||||
} else {
|
||||
const resource = await Resource.load(id);
|
||||
const localState = await Resource.localState(resource);
|
||||
|
||||
const o = {
|
||||
item: resource,
|
||||
localState: localState,
|
||||
};
|
||||
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
resourceCache_[id] = o;
|
||||
output[id] = o;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { MarkupLanguageUtils as BaseMarkupLanguageUtils } from '../markupLanguageUtils';
|
||||
import { PluginStates } from '../services/plugins/reducer';
|
||||
import { contentScriptsToRendererRules } from '../services/plugins/utils/loadContentScripts';
|
||||
import { Options } from '@joplin/renderer/MarkupToHtml';
|
||||
|
||||
class MarkupLanguageUtils extends BaseMarkupLanguageUtils {
|
||||
|
||||
public newMarkupToHtml(plugins: PluginStates = null, options: Options = null) {
|
||||
plugins = plugins || {};
|
||||
|
||||
return super.newMarkupToHtml(null, {
|
||||
extraRendererRules: contentScriptsToRendererRules(plugins),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const markupLanguageUtils = new MarkupLanguageUtils();
|
||||
|
||||
export default markupLanguageUtils;
|
||||
Reference in new issue
Block a user