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
3 changes: 2 additions & 1 deletion codeview/assets/LICENSE.mermaid
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mermaid 10.9.8 — MIT License
mermaid 12.2.0 and @mermaid-js/layout-elk 1.0.1 — MIT License
(layout-elk bundles elkjs, licensed under EPL-2.0: https://github.com/kieler/elkjs)

The MIT License (MIT)

Expand Down
4,578 changes: 3,664 additions & 914 deletions codeview/assets/mermaid.min.js

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions codeview/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,31 @@ def _sub_mermaid(m):
toc = "" if safe else _toc(getattr(md, "toc_tokens", []))
body = f'<div class="markdown-body">{toc}{html_content}</div>'

# build.py が書き出した同梱の mermaid を読む。通常のスクリプトなので file:// でも動く
# build.py が書き出した同梱の mermaid を読む。通常のスクリプトなので file:// でも動く。
# ESM でしか配られない layout-elk を IIFE にまとめて同じファイルの末尾につなぎ、
# mermaidLayoutElk として公開している。GitHub と同じく、書いた順を保って ELK で配置する
from codeview import build

script = (
f'<script src="{build.MERMAID_HREF}"></script>\n'
"""<script>
mermaid.initialize({ startOnLoad: false, theme: 'dark' });
mermaid.registerLayoutLoaders(mermaidLayoutElk);
mermaid.initialize({
startOnLoad: false,
theme: 'dark',
layout: 'elk',
elk: { considerModelOrder: 'NODES_AND_EDGES', nodePlacementStrategy: 'BRANDES_KOEPF' },
themeVariables: {
primaryColor: '#222222',
primaryBorderColor: '#7a7a7a',
mainBkg: '#222222',
nodeBorder: '#7a7a7a',
primaryTextColor: '#e6e6e6',
lineColor: '#bdbdbd',
fontSize: '14px'
},
flowchart: { wrappingWidth: 130, nodeSpacing: 40, rankSpacing: 50, padding: 22 }
});
mermaid.run({ nodes: document.querySelectorAll('.mermaid') }).catch(function (e) {
console.error('Mermaid render error:', e);
});
Expand Down
6 changes: 6 additions & 0 deletions codeview/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@
/* mermaid は図の箱の中に一時の div を作って文字を測る。狭い画面ではその幅で測って
軸の題が目盛りに重なるので、描いた後の大きさ(既定の 700px)で測らせる */
.mermaid > div[id^="d"] { width: 700px; }
/* .markdown-body pre の背景に負けないよう、同じ詳細度以上で指定する */
.markdown-body pre.mermaid { background: #151617; border-color: var(--line-soft); }
.mermaid .node rect,
.mermaid .node polygon,
.mermaid .node circle,
.mermaid .node path { filter: drop-shadow(2px 3px 2px rgba(0, 0, 0, .55)); }
.imgfile {
display: block;
max-width: 100%;
Expand Down
Loading