Add opt-in ELK layout support for mermaid diagrams#22
Open
fuzzybear3 wants to merge 1 commit into
Open
Conversation
Adds `mermaid_elk` config option (default false). When enabled, loads
@mermaid-js/layout-elk@0.2.1 from CDN and registers it before mermaid
initializes, enabling %%{init: {"layout": "elk"}}%% in diagrams.
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.
Summary
Adds a
mermaid_elkconfig option (defaultfalse). When enabled, the browser preview loads@mermaid-js/layout-elk@0.2.1from jsDelivr and registers it before mermaid initializes, allowing diagrams to use:Why
ELK produces noticeably cleaner layouts for medium/large flowcharts and class diagrams than mermaid's default dagre layout. It's opt-in because it adds ~800 KB on top of what the preview already fetches from CDN, and most diagrams don't need it.
Changes
lua/markdown_preview/init.lua: newmermaid_elkconfig (defaultfalse); substitutes a__MERMAID_ELK__placeholder when writingindex.html, mirroring the existing__BOTTOM_PADDING__pattern.assets/index.html: adds adata-mermaid-elkattribute on<html>; inboot(), conditionally dynamic-imports the ELK layout module and callsmermaid.registerLayoutLoaders(...)before the firstsync().Test plan
mermaid_elk = false(default), preview behaves exactly as before — no extra network request on boot.mermaid_elk = true, a diagram containing%%{init: {"layout": "elk"}}%%renders with the ELK layout.try/catchlogs the error and shows an inline error message rather than a blank preview.