Skip to content
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

feat: support dark mode #44

Merged
merged 13 commits into from
Sep 12, 2024
Merged

Conversation

OnceUponALoop
Copy link
Contributor

@OnceUponALoop OnceUponALoop commented Jul 22, 2024

Added support for dark mode with the auto_dark option to address #33

When this option is set the module will generate a second copy of the diagram in dark mode using the /dsvg server option.

In order to dynamically switch the image choice the module include a javascript file (mkdocs_puml/static/dark.js).

I just submitted a similar PR to the mkdocs_build_plantuml but I have to say, it was a lot easier to do in this project 👍

Some things I would focus on when reviewing:

  • dark.js
    I'm not a webdev by any means so it might need some love.

  • puml.py/_stylize_svg()
    Now uses a css var lookup to set the background instead of fixing it to #ffff

Example Output

Here's an example of the output - I used the 2 cards to show they system state and the user preference so it's easier to follow along with the transition. You can find the whole example in my develop branch.

Note: Example include addition of the skinparam backgroundColor transparent directive to the puml exmaple diagrams.

output

- generate 2 versions of each diagram, one light and one dark
- hide the dark image by default using css
- javascript will detect user pref changes and switch images accordingly
- fixed incorrect parameter in example
- use the svg background using the `(--md-default-bg-color)` var
@OnceUponALoop OnceUponALoop changed the title Feat: Support Dark Mode feat: support dark mode Jul 22, 2024
@MikhailKravets MikhailKravets added the enhancement New feature or request label Jul 22, 2024
@MikhailKravets
Copy link
Owner

That's fantastic @OnceUponALoop! I thought about similar implementation myself recently. Haven't you tried to run the dark theme with C4 diagrams?

I'll take a look more detailed a bit later this week. Anyway, great job and thank you for the contribution 🎉

@OnceUponALoop
Copy link
Contributor Author

@MikhailKravets thank you for the awesome well structured project, it was easy to deal with 👍

I was curious about the C4 diagrams, so I tested it out and i'm happy to report it seems to work with no issue. I think ultimately the support will depend on the theme chosen, I know some themes support dark mode and some don't 🤷

C4 Diagrams Example

You can find the updated develop branch with C4 Diagram example.

output

mkdocs_puml/plugin.py Outdated Show resolved Hide resolved
- fixed mismatch between readme and behavior
mkdocs_puml/puml.py Outdated Show resolved Hide resolved
- remove duplicate return
mkdocs_puml/puml.py Outdated Show resolved Hide resolved
- Use separate light and dark PlantUML instances
- Add output_format parameter to PlantUML class
- Remove dark_mode flag from translate and request methods
- Simplify URL construction in PlantUML class
- Update docstrings to reflect changes

(cherry picked from commit 09358e1)
- remove intermediate list creation `diagram_contents`
- iteration simplified, no placeholder var `_`
- pass diagram values directly to translate method
- update fixtures: (diagram, None) tuples
- assert light/dark puml configs
- extend on_env test: light/dark svg validation
- add auto_dark feature tests
- expand on_post_page scenario coverage
- implement on_post_build tests
- add _replace method tests
- improve existing test assertions
- add assertions for num_workers validation
- add comments to explain test behavior
- fix tuple type annotation
- standardize quotation marks
- remove unused imports and variables
- adjust type annotations and docstrings
@OnceUponALoop
Copy link
Contributor Author

All the formatting changes are in the last commit, only after pushing did I realize I should have probably checked with you first on such a big style-only change.

Please let me know if that's ok and I can roll it back. To make the review less painful you can review the code changes with the commit filter and then review it independently

@MikhailKravets
Copy link
Owner

Hi @OnceUponALoop, yes, this looks nice! Thank you for the contribution. I'll put now everything together for a new release 🎉

@MikhailKravets MikhailKravets changed the base branch from master to 1.4.0 September 12, 2024 07:11
@MikhailKravets MikhailKravets merged commit c449efd into MikhailKravets:1.4.0 Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants