Skip to content

Harden the diagram renderer and drop empty diagram links - #14

Merged
sodre merged 2 commits into
mainfrom
t3/diagram-render-hardening
Nov 18, 2026
Merged

sodre merged 2 commits into
mainfrom
t3/diagram-render-hardening

Conversation

@sodre

@sodre sodre commented Nov 18, 2026

Copy link
Copy Markdown
Member

Why

Follow-ups from the code review of #10, which is already merged.

What changed

scripts/render_diagrams.py

  • Colour guard (findings 1, 2): the old guard only matched six-digit hex. fill="white", #333, rgba(...) or rect aqua passed silently and left a light colour in the dark variant. Now any colour literal (hex of any length, rgb()/hsl()/oklch()…, or a named colour in fill, stroke, stop-color, color or background) stops the script with the file and the value:
    • Hand-drawn SVGs must use var(--token).
    • .mmd sources and theme.json must use {token}.
  • Token references (finding 8): theme.json and the .mmd bands now name tokens ("actorBkg": "{actor-fill}", rect {band-request}), resolved once per mode.
    • This replaces deriving the dark theme by reverse-matching hex values.
    • Light values no longer have to be unique, so surface goes back to #ffffff from the #fffffe workaround.
    • theme.json no longer repeats palette hex values.
  • Template escapes (finding 9): palette blocks are inserted with a function, so a backslash in a palette value can't be read as a regex escape.
  • Flags (finding 10): --hand and --mermaid are mutually exclusive. Passing both used to render nothing and exit 0.

theme.json (finding 7)

  • Mermaid's default drop-shadow on band rects is turned off. In the dark variants it showed as a light-grey glow.

Docs (finding 5)

  • The light/dark diagram pairs in architecture.md, integrate.md and operate.md are no longer wrapped in links. The hidden variant used to leave an empty, focusable <a>.
  • Diagrams now render at 1:1, so the click-to-enlarge link wasn't needed.
  • develop.md documents the {token} syntax.

Not changed

Verification

  • Ran the guard on 11 sample snippets covering both allowed and rejected cases. All were classified correctly.
  • --hand --mermaid now exits with an argparse error.
  • Regenerated every diagram and rendered them in both themes. The light variants are unchanged and the dark bands have no glow.
  • mkdocs build --strict passes, and the built pages contain no diagram <img> wrapped in an <a>.

🤖 Generated with Claude Code

sodre and others added 2 commits November 18, 2026 03:25
From the review of #10:
- Reject every colour that bypasses palette.json: short and long hex,
  rgb()/hsl() and friends, and named colours in fill, stroke and other
  paint properties, in hand-drawn SVGs, .mmd sources and theme.json.
- Name palette tokens as {token} in theme.json and .mmd bands and
  resolve them per mode, instead of reverse-matching hex. Light values
  no longer have to be unique, so surface is plain #ffffff again.
- Turn off Mermaid's default band drop shadow, which glowed in dark mode.
- Insert palette blocks with a function, not a regex template.
- Make --hand and --mermaid mutually exclusive.
- Embed light/dark diagram pairs without link wrappers, so the hidden
  variant no longer leaves an empty, focusable link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sodre
sodre merged commit ba16337 into main Nov 18, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant