remcohaszing / rehype-mermaid

A rehype plugin to render mermaid diagrams
MIT License
80 stars 8 forks source link

Improvement: generate default theme only once #8

Closed Caellian closed 9 months ago

Caellian commented 9 months ago

NOTE: This is a bit out there as I see themes are bound by IDs.

Currently, the default theme is inserted in every generated svg in the graph. If possible, while generating the first graph with default theme, extract the theme <style> and insert it as a sibling.

By adding a data-theme="name" tag to the <style>, finding whether there's an already existing one in the root of current ast should be easier.

remcohaszing commented 9 months ago

I am aware the generated SVGs are unoptimized. I previously implemented svgo to optimize SVGs, but I removed this, because it turned out to be fragile.

I don’t want to perform any SVG optimizations anymore. If you want this, you can create a new rehype plugin that runs after rehype-mermaid.

Caellian commented 9 months ago

I wasn't referring to svg nodes, only the stylesheet which is duplicated across all diagrams.