-
-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: improve Mermaid diagram implementation #1214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
c2c76cb to
137e68c
Compare
This commit addresses multiple issues with Mermaid diagram rendering and adds significant improvements to the user experience. ## Bug Fixes - Fix `<br/>` tags rendering as literal text instead of line breaks - Fix flash of raw mermaid code before diagram renders - Fix Gantt chart rendering issues in dark mode - Fix diagrams briefly showing during theme switch re-render - Fix expand modal showing diagram left-aligned before centering ## New Features - Add fullscreen expand modal with pan/zoom functionality - Add toolbar with zoom controls (zoom in/out, reset, fit to screen) - Add keyboard support (Escape to close modal) - Add per-diagram transparent background via `%%transparent%%` directive - Add comprehensive configuration options: - `look`: classic or handDrawn (sketch style) - `lightTheme`/`darkTheme`: theme selection per mode - `lightThemeVariables`/`darkThemeVariables`: custom theme colors - `securityLevel`, `htmlLabels`, `maxTextSize`, `maxEdges` - `fontSize`, `fontFamily`, `curve`, `logLevel` ## Performance Improvements - Switch from ESM to UMD bundle for faster initial load (~1s vs 2s+) - Lazy-load panzoom library only when expand modal is opened - Pre-render alternate theme during idle time for instant theme switching - Cache rendered diagrams to avoid re-rendering on theme toggle ## Code Quality - Move all inline CSS to article.scss using SCSS nesting - Extract helper functions for better maintainability - Use data attributes and event delegation for cleaner handlers - Reduce mermaid.html from 411 to 177 lines (57% reduction) ## Documentation - Add comprehensive mermaid-diagrams example post with all diagram types - Document all configuration options in hugo.yaml
137e68c to
958592b
Compare
|
~600 of the 990 lines are documentation in a new markdown post. Everything else is as compact and efficient as I could make it for this to work smoothly with the theme. |
|
Some explanations as why I switched it away from ESM:
The reasons for adding panzoom:
All other changes mainly have to do with matching the site's light / dark theme, allowing all configuration options, and more advanced features of the diagramming. I am super open to feedback for changes here, I am not necessarily a fan of the panzoom UI - but left it as default for now as I didn't want to modify it too much. For the changes related to mermaid, unfortunately, to get it somewhat professional looking (eg: no code flash, theme switching recognition, etc) there was a lot of extra code needed to wrap all of it in. 😞 |
|
I would suggest adding script URLs to https://github.com/CaiJimmy/hugo-theme-stack/blob/master/data/external.yaml |
This commit addresses multiple issues with Mermaid diagram rendering
and adds significant improvements to the user experience.
Bug Fixes
<br/>tags rendering as literal text instead of line breaksNew Features
%%transparent%%directivelook: classic or handDrawn (sketch style)lightTheme/darkTheme: theme selection per modelightThemeVariables/darkThemeVariables: custom theme colorssecurityLevel,htmlLabels,maxTextSize,maxEdgesfontSize,fontFamily,curve,logLevelPerformance Improvements
Code Quality
Documentation
Closes #1213