Mdbook Mermaid dark mode support #35

Closed
opened 2023-06-29 07:01:54 +00:00 by hemeroc · 3 comments
hemeroc commented 2023-06-29 07:01:54 +00:00 (Migrated from github.com)

Expectation:
When switching to a dark theme in mdbook the mermaid diagrams also switch to a dark theme.
image

What happens:
Mermaid diagrams do not honor the theme and render in light mode being not very readable in dark mode.
image

I am happy to help if you point me to the right start.

**Expectation:** When switching to a dark theme in mdbook the mermaid diagrams also switch to a dark theme. <img width="570" alt="image" src="https://github.com/badboy/mdbook-mermaid/assets/193428/c412f795-0c5a-49aa-a79b-6037ed793037"> **What happens:** Mermaid diagrams do not honor the theme and render in light mode being not very readable in dark mode. <img width="470" alt="image" src="https://github.com/badboy/mdbook-mermaid/assets/193428/7fd70227-92d5-43c9-a816-d00bb2c8d35d"> I am happy to help if you point me to the right start.
badboy commented 2023-06-29 10:19:58 +00:00 (Migrated from github.com)

This is more of a styling question and can be done independently of this plugin.
Looks like mermaid doesn't have any auto-switching but it does have theming, so you can build the auto-switch yourself.

This is more of a styling question and can be done independently of this plugin. Looks like [mermaid doesn't have any auto-switching](https://github.com/mermaid-js/mermaid/issues/2644) but it [does have theming](https://mermaid.js.org/config/theming.html), so you can build the auto-switch yourself.
hemeroc commented 2023-06-30 11:59:06 +00:00 (Migrated from github.com)

I think mdbook-mermaid would need to implement a switching that at least provides a default mapping from the default mdbook themes to the light or dark mermaid themes.

I would see mdbook-mermaid as a mermaid bridge for mdbook that should integrate mermaid diagrams into mdbook and not produce diagrams that you can't read in one of the default themes.
Similar as they do it for mermaid-live as described in this comment: https://github.com/mermaid-js/mermaid/issues/2644#issuecomment-1029648289

I would be absolutely willing to implement this if you could hint me in the right direction.

I think mdbook-mermaid would need to implement a switching that at least provides a default mapping from the default mdbook themes to the light or dark mermaid themes. I would see mdbook-mermaid as a mermaid bridge for mdbook that should integrate mermaid diagrams into mdbook and not produce diagrams that you can't read in one of the default themes. Similar as they do it for mermaid-live as described in this comment: https://github.com/mermaid-js/mermaid/issues/2644#issuecomment-1029648289 I would be absolutely willing to implement this if you could hint me in the right direction.
badboy commented 2023-06-30 12:11:17 +00:00 (Migrated from github.com)

mdbook-mermaid currently doesn't handle any theming on its own at all.
mdbook handles theming by applying a class to the <html> event.

You might need to either:

  • Write some JS to watch for that change and apply some mermaid theming
  • Extend the CSS of the theme to apply to mermaid styling as well

Both things can be tried out in your own project by modifying the additional JS or CSS files.
If that leads to a more general solution we might be able to bring this back into this plugin.

mdbook-mermaid currently doesn't handle any theming on its own at all. mdbook handles theming by applying a class to the `<html>` event. You might need to either: * Write some JS to watch for that change and apply some mermaid theming * Extend the CSS of the theme to apply to mermaid styling as well Both things can be tried out in your own project by modifying the additional JS or CSS files. If that leads to a more general solution we might be able to bring this back into this plugin.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jer/mdbook-mermaid#35
No description provided.