Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions public/js/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ function replaceExtraTags (html) {
}

if (typeof window.mermaid !== 'undefined' && window.mermaid) {
window.mermaid.startOnLoad = false
window.mermaid.initialize({
startOnLoad: false
})

window.mermaid.parseError = function (err, hash) {
console.warn(err)
}
Expand Down Expand Up @@ -433,22 +436,26 @@ export function finishView (view) {
})
// mermaid
const mermaids = view.find('div.mermaid.raw').removeClass('raw')
mermaids.each((key, value) => {
mermaids.each(async (key, value) => {
const $value = $(value)
const $ele = $value.closest('pre')
try {
var $value = $(value)
const $ele = $(value).closest('pre')

const text = $value.text()
// validate the syntax first
if (window.mermaid.parse(text)) {
$ele.addClass('mermaid')
$ele.text(text)
// render the diagram
window.mermaid.init(undefined, $ele)
const id = `mermaid-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
const { svg, bindFunctions } = await window.mermaid.render(id, text, $ele[0])
$ele.html(svg)
if (bindFunctions) {
bindFunctions($ele[0])
}
}
} catch (err) {
$value.unwrap()
$value.parent().append(`<div class="alert alert-warning">${escapeHTML(err.str)}</div>`)
$ele.append(`<div class="alert alert-warning">${escapeHTML(err)}</div>`)
console.warn(err)
}
})
Expand Down
1 change: 1 addition & 0 deletions public/views/codimd/foot.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
<script src="<%- serverURL %>/build/MathJax/MathJax.js" defer></script>
<script src="<%- serverURL %>/build/MathJax/config/TeX-AMS-MML_HTMLorMML.js" defer></script>
<script src="<%- serverURL %>/build/MathJax/config/Safe.js" defer></script>
<script src="<%- serverURL %>/build/mermaid/mermaid.min.js" defer></script>
<%- include('../build/index-pack-scripts') %>
<% } %>
1 change: 1 addition & 0 deletions public/views/pretty.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<script src="<%- serverURL %>/build/MathJax/MathJax.js" defer></script>
<script src="<%- serverURL %>/build/MathJax/config/TeX-AMS-MML_HTMLorMML.js" defer></script>
<script src="<%- serverURL %>/build/MathJax/config/Safe.js" defer></script>
<script src="<%- serverURL %>/build/mermaid/mermaid.min.js" defer></script>
<%- include('build/pretty-pack-scripts') %>
<% } %>
<%- include('shared/ga') %>
1 change: 1 addition & 0 deletions public/views/slide.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<script src="<%- serverURL %>/build/MathJax/MathJax.js" defer></script>
<script src="<%- serverURL %>/build/MathJax/config/TeX-AMS-MML_HTMLorMML.js" defer></script>
<script src="<%- serverURL %>/build/MathJax/config/Safe.js" defer></script>
<script src="<%- serverURL %>/build/mermaid/mermaid.min.js" defer></script>
<%- include('build/slide-pack-scripts') %>
<% } %>
</body>
Expand Down
9 changes: 5 additions & 4 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ module.exports = {
context: path.join(__dirname, 'node_modules/fork-awesome'),
from: 'css',
to: 'fork-awesome/css'
},
{
context: path.join(__dirname, 'node_modules/mermaid'),
from: 'dist/mermaid.min.js',
to: 'mermaid/mermaid.min.js'
}
]),
new MiniCssExtractPlugin(
Expand Down Expand Up @@ -295,7 +300,6 @@ module.exports = {
'script-loader!jquery-ui-resizable',
'bootstrap-validator',
'expose-loader?jsyaml!js-yaml',
'script-loader!mermaid',
'expose-loader?moment!moment',
'script-loader!handlebars',
'expose-loader?hljs!highlight.js',
Expand Down Expand Up @@ -340,7 +344,6 @@ module.exports = {
'pretty-pack': [
'babel-polyfill',
'expose-loader?jsyaml!js-yaml',
'script-loader!mermaid',
'expose-loader?moment!moment',
'script-loader!handlebars',
'expose-loader?hljs!highlight.js',
Expand Down Expand Up @@ -383,7 +386,6 @@ module.exports = {
'imports-loader?$=jquery!jquery-mousewheel',
'bootstrap-tooltip',
'expose-loader?jsyaml!js-yaml',
'script-loader!mermaid',
'expose-loader?moment!moment',
'script-loader!handlebars',
'expose-loader?hljs!highlight.js',
Expand Down Expand Up @@ -419,7 +421,6 @@ module.exports = {
jqueryTextcomplete: path.join(__dirname, 'public/vendor/jquery-textcomplete/jquery.textcomplete.js'),
codemirrorInlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/codemirror.inline-attachment.js'),
ot: path.join(__dirname, 'public/vendor/ot/ot.min.js'),
mermaid: path.join(__dirname, 'node_modules/mermaid/dist/mermaid.min.js'),
handlebars: path.join(__dirname, 'node_modules/handlebars/dist/handlebars.min.js'),
'jquery-ui-resizable': path.join(__dirname, 'public/vendor/jquery-ui/jquery-ui.min.js'),
'gist-embed': path.join(__dirname, 'node_modules/gist-embed/gist-embed.min.js'),
Expand Down