mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-08 12:07:06 +08:00
Optimize mermaid view
This commit is contained in:
6
layout/includes/third-party/math/mermaid.pug
vendored
6
layout/includes/third-party/math/mermaid.pug
vendored
@@ -54,6 +54,11 @@ script.
|
||||
if (!clone.getAttribute('xmlns:xlink') && clone.outerHTML.includes('xlink:')) {
|
||||
clone.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink')
|
||||
}
|
||||
// inject background to match current theme
|
||||
const isDark = document.documentElement.getAttribute('data-theme') === 'dark'
|
||||
const bg = getComputedStyle(document.body).backgroundColor || (isDark ? '#1e1e1e' : '#ffffff')
|
||||
if (!clone.style.background) clone.style.background = bg
|
||||
|
||||
const serializer = new XMLSerializer()
|
||||
const svgSource = serializer.serializeToString(clone)
|
||||
const blob = new Blob([svgSource], { type: 'image/svg+xml;charset=utf-8' })
|
||||
@@ -276,6 +281,7 @@ script.
|
||||
attachMermaidViewerButton(item)
|
||||
}
|
||||
|
||||
|
||||
// mermaid v9 and v10 compatibility
|
||||
typeof renderFn === 'string' ? renderMermaid(renderFn) : renderFn.then(({ svg }) => renderMermaid(svg))
|
||||
})
|
||||
|
||||
@@ -68,6 +68,7 @@ if hexo-config('mermaid.enable')
|
||||
position: relative
|
||||
margin: 0 0 20px
|
||||
text-align: center
|
||||
background: var(--card-bg)
|
||||
|
||||
.mermaid-open-btn
|
||||
position: absolute
|
||||
|
||||
Reference in New Issue
Block a user