mirror of
https://github.com/McShelby/hugo-theme-relearn
synced 2025-04-30 17:48:47 +08:00
Mermaid diagrams can start with yaml front matter, e.g. ``` --- title: Example Diagram --- graph LR A --> B ``` Relearn injects an init directive `%%{init: {"theme":"default"}}%%` at the top of a mermaid block to support theming the mermaid diagram. However this will cause a syntax parser error in mermaid if the init directive comes before the yaml front matter. Valid: ``` %%{init: {"theme":"default"}}%% graph LR A --> B ``` Invalid: ``` %%{init: {"theme":"default"}}%% --- title: Example --- graph LR A --> B ``` To support yaml front matter, we detect if front matter is used, and inject the init directive after the front matter. ``` --- title: Example --- %%{init: {"theme":"default"}}%% graph LR A --> B ```