2020-10-21 01:23:55 +02:00
|
|
|
export default {
|
2020-03-23 02:47:25 +02:00
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
assets: function() {
|
|
|
|
return [
|
|
|
|
{ name: 'mermaid.min.js' },
|
|
|
|
{ name: 'mermaid_render.js' },
|
|
|
|
{
|
|
|
|
inline: true,
|
|
|
|
// Note: Mermaid is buggy when rendering below a certain width (500px?)
|
|
|
|
// so set an arbitrarily high width here for the container. Once the
|
|
|
|
// diagram is rendered it will be reset to 100% in mermaid_render.js
|
|
|
|
text: '.mermaid { background-color: white; width: 640px; }',
|
|
|
|
mime: 'text/css',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
2020-02-12 00:27:34 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
plugin: function(markdownIt: any) {
|
|
|
|
const defaultRender: Function = markdownIt.renderer.rules.fence || function(tokens: any[], idx: number, options: any, env: any, self: any) {
|
2020-10-21 01:23:55 +02:00
|
|
|
return self.renderToken(tokens, idx, options, env, self);
|
|
|
|
};
|
2020-02-12 00:27:34 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
markdownIt.renderer.rules.fence = function(tokens: any[], idx: number, options: {}, env: any, self: any) {
|
2020-10-21 01:23:55 +02:00
|
|
|
const token = tokens[idx];
|
|
|
|
if (token.info !== 'mermaid') return defaultRender(tokens, idx, options, env, self);
|
|
|
|
const contentHtml = markdownIt.utils.escapeHtml(token.content);
|
2021-03-15 18:31:11 +02:00
|
|
|
// Note: The mermaid script (`contentHtml`) needs to be wrapped
|
|
|
|
// in a `pre` tag, otherwise in WYSIWYG mode TinyMCE removes
|
|
|
|
// all the white space from it, which causes mermaid to fail.
|
|
|
|
// See PR #4670 https://github.com/laurent22/joplin/pull/4670
|
2020-10-21 01:23:55 +02:00
|
|
|
return `
|
|
|
|
<div class="joplin-editable">
|
|
|
|
<pre class="joplin-source" data-joplin-language="mermaid" data-joplin-source-open="\`\`\`mermaid " data-joplin-source-close=" \`\`\` ">${contentHtml}</pre>
|
2021-03-15 18:31:11 +02:00
|
|
|
<pre class="mermaid">${contentHtml}</pre>
|
2020-10-21 01:23:55 +02:00
|
|
|
</div>
|
|
|
|
`;
|
2020-03-23 02:47:25 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|