1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/ReactNativeClient/lib/joplin-renderer/MdToHtml/rules/mermaid.ts
Laurent Cozic 1d14c8a706 Desktop, Mobile: Resolves #2001: Added Mermaid diagrams support
commit ae8a0641ab3681a3b25f6dc4ac40f20d52aaeb4d
Author: Laurent Cozic <laurent@cozic.net>
Date:   Tue Feb 11 17:58:08 2020 +0000

    Fixed plugin asset

commit 03adf7fc7c878f82f6a43515d37fd5e3dd59390f
Author: Laurent Cozic <laurent@cozic.net>
Date:   Mon Feb 10 22:09:18 2020 +0000

    Desktop: Adding Mermaid support
2020-02-11 22:28:43 +00:00

33 lines
1.0 KiB
TypeScript

function addContextAssets(context) {
if ('mermaid' in context.pluginAssets) return;
context.pluginAssets['mermaid'] = [
{ name: 'mermaid.min.js' },
{ name: 'mermaid_render.js' },
{
inline: true,
text: '.mermaid { background-color: white }',
mime: 'text/css',
},
];
}
function installRule(markdownIt:any, mdOptions:any, ruleOptions:any, context:any) {
const defaultRender:Function = markdownIt.renderer.rules.fence || function(tokens:any[], idx:number, options:any, env:any, self:any) {
return self.renderToken(tokens, idx, options, env, self);
};
markdownIt.renderer.rules.fence = function(tokens:any[], idx:number, options:{}, env:any, self:any) {
const token = tokens[idx];
if (token.info !== 'mermaid') return defaultRender(tokens, idx, options, env, self);
addContextAssets(context);
return `<div class="mermaid">${token.content}</div>`;
};
}
export default function(context:any, ruleOptions:any) {
return function(md:any, mdOptions:any) {
installRule(md, mdOptions, ruleOptions, context);
};
}