You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-03 23:50:33 +02:00
Cleaned up plugin doc
This commit is contained in:
@ -320,36 +320,30 @@ export type Path = string[];
|
||||
|
||||
export enum ContentScriptType {
|
||||
/**
|
||||
* Registers a new Markdown-It plugin, which should follow this template:
|
||||
* Registers a new Markdown-It plugin, which should follow the template below.
|
||||
*
|
||||
* ```javascript
|
||||
* // The module should export an object as below:
|
||||
*
|
||||
* module.exports = {
|
||||
*
|
||||
* // The "context" variable is currently unused but could be used later on to provide
|
||||
* // access to your own plugin so that the content script and plugin can communicate.
|
||||
* default: function(context) {
|
||||
* return {
|
||||
*
|
||||
* // This is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information
|
||||
* // The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/ReactNativeClient/lib/joplin-renderer/MdToHtml.ts), which
|
||||
* // contains a number of options, mostly useful for Joplin's internal code.
|
||||
* plugin: function(markdownIt, options) {
|
||||
* // ...
|
||||
* },
|
||||
*
|
||||
* // You may also specify additional assets such as JS or CSS that should be loaded in the rendered HTML document.
|
||||
* // Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/ReactNativeClient/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to
|
||||
* // see how the data should be structured.
|
||||
* assets: {},
|
||||
* assets: {
|
||||
* // ...
|
||||
* },
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific feature, you
|
||||
* would simply create a file such as this:
|
||||
* - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate.
|
||||
*
|
||||
* - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/ReactNativeClient/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code.
|
||||
*
|
||||
* - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/ReactNativeClient/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured.
|
||||
*
|
||||
* To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this:
|
||||
*
|
||||
* ```javascript
|
||||
* module.exports = {
|
||||
|
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user