D2記法のコードブロックに対応 - #185
Open
riiimparm wants to merge 10 commits into
Open
Conversation
@terrastruct/d2 (ブラウザ向けWASM実装) をCDN経由で動的importし、 mermaidと同じパターンでd2コードブロックをSVGに変換するremarkプラグインを追加。 Shikiが"d2"言語を認識できずplaintextにフォールバックしてしまうため、 markdown.syntaxHighlight.excludeLangsでd2のみシンタックスハイライトを無効化。
コンテナにmax-width:80vw、SVGにwidth/height:auto + max-width:100%/max-height:90vhを 指定し、アスペクト比を保ったまま画面内に収まるようCSSのみで制約(img的なreplaced element縮小に任せる)。1024px未満(モバイル)は従来通り制約なし。
横長/縦長のD2図を含む再現用記事。デスクトップ幅での80vw/90vh制約の 証跡として残す。
@terrastruct/d2のJS APIはthemeOverrides的なAPIを持たず、themeIDでは mermaid側の配色(背景#0f172a/ボーダー#38bdf8/ライン#22d3ee/文字#e2e8f0)に 近いものが無かったため、D2のテーマシステムが付与する意味的クラス (N1-N7, B1-B6, AA/AB1-5)をCSSで直接上書きしてmermaidと同じ配色にした。 また、高さ制約(max-height:90vh基準のスケールダウン)をデスクトップ限定の メディアクエリの外に出し、モバイルでも常時適用されるようにした (幅80vwの制約は引き続きデスクトップのみ)。 コンテナはmermaidと同様にflex+justify-content:centerで中央揃えにし、 Tailwindクラス文字列(purge対象外で効かない可能性がある)からinline style指定に変更した。
connectionのfill-B1(矢印先端マーカーのpolygon)とstroke-B1(線本体の path、fill="none")を同一セレクタでまとめてfill/strokeを両方 !important上書きしていたため、線本体のfill="none"が上書きされ、 閉じていないbezierパスがブラウザにより暗黙的に閉じられて塗りつぶされ、 扇状に複数エッジが出る図で特に目立つ太いリボン状の見た目になっていた。 fill-B1とstroke-B1を別々のセレクタに分離し、それぞれの役割(マーカー の塗り/線の色)にのみ対応するプロパティを当てるよう修正。
Open
# Conflicts: # astro.config.mjs
Member
There was a problem hiding this comment.
@riiimparm
style指定を src/layouts/BlogLayout.astro に寄せれないかな
当たらなそうだったらこのままでもOK!
Collaborator
Author
There was a problem hiding this comment.
d2のあるページだけにstyle追加したいのでBlogLayoutには入れないかな。後述コメにてクライアントレンダリングやめるからstyle変わるかも
mermaidと統合したほうがいいのもそうだなぁ、BlogLayoutで統合できるかみてみる
|
|
||
| try { | ||
| const { D2 } = await import( | ||
| "https://esm.sh/@terrastruct/d2@0.1.33" |
Member
There was a problem hiding this comment.
cdnでなく、package.jsonで管理している @terrastruct/d2 使えないかな?
Suggested change
| "https://esm.sh/@terrastruct/d2@0.1.33" | |
| "@terrastruct/d2" |
Collaborator
Author
There was a problem hiding this comment.
@terrastruct/d2による事前レンダリングに変更
Collaborator
Author
There was a problem hiding this comment.
mermaidもcdnなのでテーマ合わせる意味でもこのブランチで一緒に直しちゃったほうがいいか
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
変更内容
D2記法のコードブロックに対応。
@terrastruct/d2をCDNから動的importし、クライアントサイドでd2コードブロックをSVGに変換。配色はmermaidと同じダークテーマpackage.json/pnpm-lock.yaml:@terrastruct/d2を追加テスト用md