1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-27 23:28:38 +02:00

Cleaned up plugin doc

This commit is contained in:
Laurent Cozic
2020-10-21 22:52:58 +01:00
parent c33a8250ee
commit 98f822d89c
6 changed files with 104 additions and 106 deletions

View File

@ -1,22 +1,26 @@
import { PluginStates } from '../reducer';
import { ExtraRendererRule } from 'lib/joplin-renderer/MdToHtml';
import { ContentScriptType } from '../api/types';
export default function contentScriptsToRendererRules(plugins:PluginStates):ExtraRendererRule[] {
const output:ExtraRendererRule[] = [];
for (const pluginId in plugins) {
const plugin = plugins[pluginId];
for (const scriptType in plugin.contentScripts) {
const contentScripts = plugin.contentScripts[scriptType];
for (const contentScript of contentScripts) {
const contentScripts = plugin.contentScripts[ContentScriptType.MarkdownItPlugin];
if (!contentScripts) continue;
const loadedModule = require(contentScript.path).default;
for (const contentScript of contentScripts) {
const module = require(contentScript.path);
if (!module.default || typeof module.default !== 'function') throw new Error(`Content script must export a function under the "default" key: Plugin: ${pluginId}: Script: ${contentScript.id}`);
output.push({
id: contentScript.id,
module: loadedModule({}),
});
}
const loadedModule = module.default({});
if (!loadedModule.plugin) throw new Error(`Content script must export a "plugin" key: Plugin: ${pluginId}: Script: ${contentScript.id}`);
output.push({
id: contentScript.id,
module: loadedModule,
});
}
}