You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
All: Allow toggling markdown plugins and added several new plugins (#1347)
* Initial test of enabling plugins * Added support for toggle-able plugins - Also adds some new plugins * Add instructions on adding toggle-plugins * Fix subtle anchor bug - webview was moving itself when scrolling to bottom anchors * Moves the webview hack so that it only applies to anchors * Add plugin descriptions to the README, also removed mermaid from README * rename plugin.* to markdown.plugin.* to be more forward compatible
This commit is contained in:
committed by
Laurent Cozic
parent
496c9ddb91
commit
0c2f2667d3
@ -7,6 +7,7 @@ const { _ } = require('lib/locale');
|
||||
const md5 = require('md5');
|
||||
const StringUtils = require('lib/string-utils.js');
|
||||
const noteStyle = require('./MdToHtml/noteStyle');
|
||||
const Setting = require('./models/Setting.js');
|
||||
const rules = {
|
||||
image: require('./MdToHtml/rules/image'),
|
||||
checkbox: require('./MdToHtml/rules/checkbox'),
|
||||
@ -19,6 +20,20 @@ const rules = {
|
||||
};
|
||||
const setupLinkify = require('./MdToHtml/setupLinkify');
|
||||
const hljs = require('highlight.js');
|
||||
const markdownItAnchor = require('markdown-it-anchor');
|
||||
const markdownItToc = require('markdown-it-toc-done-right');
|
||||
// The keys must match the corresponding entry in Setting.js
|
||||
const plugins = {
|
||||
mark: require('markdown-it-mark'),
|
||||
footnote: require('markdown-it-footnote'),
|
||||
sub: require('markdown-it-sub'),
|
||||
sup: require('markdown-it-sup'),
|
||||
deflist: require('markdown-it-deflist'),
|
||||
abbr: require('markdown-it-abbr'),
|
||||
emoji: require('markdown-it-emoji'),
|
||||
insert: require('markdown-it-ins'),
|
||||
multitable: require('markdown-it-multimd-table'),
|
||||
};
|
||||
|
||||
class MdToHtml {
|
||||
|
||||
@ -76,14 +91,25 @@ class MdToHtml {
|
||||
|
||||
const ruleOptions = Object.assign({}, options, { resourceBaseUrl: this.resourceBaseUrl_ });
|
||||
|
||||
// To add a plugin, there are two options:
|
||||
// To add a plugin, there are three options:
|
||||
//
|
||||
// 1. If the plugin does not need any application specific data, use the standard way:
|
||||
//
|
||||
// const someMarkdownPlugin = require('someMarkdownPlugin');
|
||||
// markdownIt.use(someMarkdownPlugin);
|
||||
//
|
||||
// 2. If the plugin needs application data (in ruleOptions) or needs to pass data (CSS, files to load, etc.) back
|
||||
// 2. If the plugin does not need any application specific data, and you want the user
|
||||
// to be able to toggle the plugin:
|
||||
//
|
||||
// Add the plugin to the plugins object
|
||||
// const plugins = {
|
||||
// plugin: require('someMarkdownPlugin'),
|
||||
// }
|
||||
//
|
||||
// And add a corresponding entry into Setting.js
|
||||
// 'markdown.plugin.mark': {value: true, type: Setting.TYPE_BOOL, section: 'plugins', public: true, appTypes: ['mobile', 'desktop'], label: () => _('Enable ==mark== syntax')},
|
||||
//
|
||||
// 3. If the plugin needs application data (in ruleOptions) or needs to pass data (CSS, files to load, etc.) back
|
||||
// to the application (using the context object), use the application-specific way:
|
||||
//
|
||||
// const imagePlugin = require('./MdToHtml/rules/image');
|
||||
@ -97,9 +123,18 @@ class MdToHtml {
|
||||
markdownIt.use(rules.checkbox(context, ruleOptions));
|
||||
markdownIt.use(rules.link_open(context, ruleOptions));
|
||||
markdownIt.use(rules.html_block(context, ruleOptions));
|
||||
markdownIt.use(rules.katex(context, ruleOptions));
|
||||
if (Setting.value('markdown.plugin.katex'))
|
||||
markdownIt.use(rules.katex(context, ruleOptions));
|
||||
markdownIt.use(rules.highlight_keywords(context, ruleOptions));
|
||||
markdownIt.use(rules.code_inline(context, ruleOptions));
|
||||
markdownIt.use(markdownItAnchor)
|
||||
if (Setting.value('markdown.plugin.toc'))
|
||||
markdownIt.use(markdownItToc, { listType: 'ul' })
|
||||
|
||||
for (let key in plugins) {
|
||||
if (Setting.value('markdown.plugin.' + key))
|
||||
markdownIt.use(plugins[key]);
|
||||
}
|
||||
|
||||
setupLinkify(markdownIt);
|
||||
|
||||
|
Reference in New Issue
Block a user