From c7557dac1dc3ee7bde857db1b8ad8304f80e63fd Mon Sep 17 00:00:00 2001 From: GenericJam Date: Thu, 27 Aug 2026 13:00:28 -0600 Subject: [PATCH] docs: mermaid diagrams follow the hexdocs light/dark theme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #42. ex_doc marks dark mode by toggling `dark` on (its stylesheet is written against `body.dark`). Reading that class rather than prefers-color-scheme covers all three of ex_doc's settings — light, dark and system — because ex_doc re-toggles the class itself when the OS scheme changes under "system". Three things the naive version gets wrong, all handled here: - The old code replaced each
 with the rendered SVG, discarding the
  diagram source. A theme switch then has nothing to re-render from, so the
  source is captured up front.
- mermaid.render is async, so a fast light→dark→light toggle can land results
  out of order and leave the diagram on the wrong theme. Each pass is stamped
  and stale results are dropped.
- 's class list also churns for search focus and sticky scroll, so a
  bare MutationObserver would re-render diagrams on unrelated DOM activity.
  Only an actual change in dark-ness triggers a re-render.

Supersedes the approach in #35 (closed by its author, "maybe is better other
approach"), which forced the dark theme unconditionally and so broke light
mode. That PR also reported diagrams not rendering at all; that half is
already fixed on master — the generated markup is 

and the existing selector matches it.

Verified in a real browser against the built docs, not just by eye: light
renders (#333 text fill), toggling body.dark re-renders on pass 2 (#ccc),
toggling back re-renders on pass 3 (#333), and adding search-focused /
scroll-sticky does NOT re-render. No orphan mermaid error divs after three
passes, so no failed renders or leaks.

Note this only reaches hexdocs.pm via a published release — doc changes
without a version bump never ship.

Co-Authored-By: Claude Opus 5 (1M context) 
---
 mix.exs | 55 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 11 deletions(-)

diff --git a/mix.exs b/mix.exs
index c3461ced..d5674cb6 100644
--- a/mix.exs
+++ b/mix.exs
@@ -77,18 +77,51 @@ defmodule Mob.MixProject do
     
     
     """