Skip to content

Commit 97b3ad8

Browse files
committed
chore: integrate mermaid.js into the build process and update initialization in extra.js
- Added mermaid.min.js to the build output in webpack.common.js. - Updated mermaid initialization in extra.js to use the new API. - Included mermaid.min.js script in foot.ejs, pretty.ejs, and slide.ejs for rendering diagrams. Signed-off-by: Yukai Huang <[email protected]>
1 parent 3c86c65 commit 97b3ad8

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

public/js/extra.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ function replaceExtraTags (html) {
254254
}
255255

256256
if (typeof window.mermaid !== 'undefined' && window.mermaid) {
257-
window.mermaid.startOnLoad = false
257+
window.mermaid.initialize({
258+
startOnLoad: false
259+
})
260+
258261
window.mermaid.parseError = function (err, hash) {
259262
console.warn(err)
260263
}
@@ -433,7 +436,7 @@ export function finishView (view) {
433436
})
434437
// mermaid
435438
const mermaids = view.find('div.mermaid.raw').removeClass('raw')
436-
mermaids.each((key, value) => {
439+
mermaids.each(async (key, value) => {
437440
try {
438441
var $value = $(value)
439442
const $ele = $(value).closest('pre')
@@ -444,7 +447,9 @@ export function finishView (view) {
444447
$ele.addClass('mermaid')
445448
$ele.text(text)
446449
// render the diagram
447-
window.mermaid.init(undefined, $ele)
450+
await window.mermaid.run({
451+
nodes: [$ele[0]]
452+
})
448453
}
449454
} catch (err) {
450455
$value.unwrap()

public/views/codimd/foot.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
<script src="<%- serverURL %>/build/MathJax/MathJax.js" defer></script>
3131
<script src="<%- serverURL %>/build/MathJax/config/TeX-AMS-MML_HTMLorMML.js" defer></script>
3232
<script src="<%- serverURL %>/build/MathJax/config/Safe.js" defer></script>
33+
<script src="<%- serverURL %>/build/mermaid/mermaid.min.js" defer></script>
3334
<%- include('../build/index-pack-scripts') %>
3435
<% } %>

public/views/pretty.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<script src="<%- serverURL %>/build/MathJax/MathJax.js" defer></script>
106106
<script src="<%- serverURL %>/build/MathJax/config/TeX-AMS-MML_HTMLorMML.js" defer></script>
107107
<script src="<%- serverURL %>/build/MathJax/config/Safe.js" defer></script>
108+
<script src="<%- serverURL %>/build/mermaid/mermaid.min.js" defer></script>
108109
<%- include('build/pretty-pack-scripts') %>
109110
<% } %>
110111
<%- include('shared/ga') %>

public/views/slide.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<script src="<%- serverURL %>/build/MathJax/MathJax.js" defer></script>
118118
<script src="<%- serverURL %>/build/MathJax/config/TeX-AMS-MML_HTMLorMML.js" defer></script>
119119
<script src="<%- serverURL %>/build/MathJax/config/Safe.js" defer></script>
120+
<script src="<%- serverURL %>/build/mermaid/mermaid.min.js" defer></script>
120121
<%- include('build/slide-pack-scripts') %>
121122
<% } %>
122123
</body>

webpack.common.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ module.exports = {
205205
context: path.join(__dirname, 'node_modules/fork-awesome'),
206206
from: 'css',
207207
to: 'fork-awesome/css'
208+
},
209+
{
210+
context: path.join(__dirname, 'node_modules/mermaid'),
211+
from: 'dist/mermaid.min.js',
212+
to: 'mermaid/mermaid.min.js'
208213
}
209214
]),
210215
new MiniCssExtractPlugin(
@@ -295,7 +300,6 @@ module.exports = {
295300
'script-loader!jquery-ui-resizable',
296301
'bootstrap-validator',
297302
'expose-loader?jsyaml!js-yaml',
298-
'script-loader!mermaid',
299303
'expose-loader?moment!moment',
300304
'script-loader!handlebars',
301305
'expose-loader?hljs!highlight.js',
@@ -340,7 +344,6 @@ module.exports = {
340344
'pretty-pack': [
341345
'babel-polyfill',
342346
'expose-loader?jsyaml!js-yaml',
343-
'script-loader!mermaid',
344347
'expose-loader?moment!moment',
345348
'script-loader!handlebars',
346349
'expose-loader?hljs!highlight.js',
@@ -383,7 +386,6 @@ module.exports = {
383386
'imports-loader?$=jquery!jquery-mousewheel',
384387
'bootstrap-tooltip',
385388
'expose-loader?jsyaml!js-yaml',
386-
'script-loader!mermaid',
387389
'expose-loader?moment!moment',
388390
'script-loader!handlebars',
389391
'expose-loader?hljs!highlight.js',
@@ -419,7 +421,6 @@ module.exports = {
419421
jqueryTextcomplete: path.join(__dirname, 'public/vendor/jquery-textcomplete/jquery.textcomplete.js'),
420422
codemirrorInlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/codemirror.inline-attachment.js'),
421423
ot: path.join(__dirname, 'public/vendor/ot/ot.min.js'),
422-
mermaid: path.join(__dirname, 'node_modules/mermaid/dist/mermaid.min.js'),
423424
handlebars: path.join(__dirname, 'node_modules/handlebars/dist/handlebars.min.js'),
424425
'jquery-ui-resizable': path.join(__dirname, 'public/vendor/jquery-ui/jquery-ui.min.js'),
425426
'gist-embed': path.join(__dirname, 'node_modules/gist-embed/gist-embed.min.js'),

0 commit comments

Comments
 (0)