Skip to content
Open
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
9 changes: 9 additions & 0 deletions content/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ pre:has(> code.mermaid) {
height: 100%;
}

/*fix: allow <br> line breaks inside mermaid node labels
The github theme sets `code br { display: none }` which hides <br> inside
mermaid `<code>` elements, preventing multi-line node labels from rendering.
See: https://github.com/simov/markdown-viewer/issues/263 */
.markdown-body code.mermaid br,
.markdown-theme code.mermaid br {
display: inline !important;
}

/*mermaid text bold effect*/
svg[id^=mermaid] text {
stroke: none !important;
Expand Down
15 changes: 14 additions & 1 deletion content/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ var mmd = (() => {
var walk = (regex, string, result = [], match = regex.exec(string)) =>
!match ? result : walk(regex, string, result.concat(match[1]))

var fixMermaidViewBox = () => {
document.querySelectorAll('pre code.mermaid svg').forEach((svg) => {
var bbox = svg.getBBox()
if (bbox.height > 0) {
var pad = 16
svg.setAttribute('viewBox',
(bbox.x - pad) + ' ' + (bbox.y - pad) + ' ' +
(bbox.width + pad * 2) + ' ' + (bbox.height + pad * 2))
}
})
}

return {
render: () => {
if (loaded) {
Expand All @@ -19,7 +31,7 @@ var mmd = (() => {
state._themes[state.theme] === 'dark' ||
(state._themes[state.theme] === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches)
? 'dark' : 'default'
mermaid.initialize({theme})
mermaid.initialize({theme, securityLevel: 'loose'})
mermaid.init({theme}, 'code.mermaid')
loaded = true

Expand All @@ -28,6 +40,7 @@ var mmd = (() => {
var svg = Array.from(document.querySelectorAll('pre code.mermaid svg'))
if (diagrams.length === svg.length) {
clearInterval(timeout)
setTimeout(fixMermaidViewBox, 100)
svg.forEach((diagram) => {
var panzoom = Panzoom(diagram, {canvas: true})
diagram.parentElement.parentElement.addEventListener('wheel', (e) => {
Expand Down