Skip to content

Add user-defined CSS themes via themes directory - #56

Merged
patakuti merged 1 commit into
mainfrom
feature/user-defined-css-themes
Jun 19, 2026
Merged

Add user-defined CSS themes via themes directory#56
patakuti merged 1 commit into
mainfrom
feature/user-defined-css-themes

Conversation

@patakuti

@patakuti patakuti commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Closes #55

Summary

  • New internal/themes package manages built-in and user-defined CSS theme files
  • On first launch, writes github.css, simple.css, dark.css to ~/.config/markdown-proxy/themes/ — users can edit or replace them
  • Any .css file placed in the themes directory is automatically listed in the theme dropdown
  • New /_theme/<name>.css endpoint serves CSS files from the themes directory (with path traversal protection and in-memory fallback)

Architecture changes

Area Change
CSS structure Structural layout stays embedded; all visual styling (colors, fonts, syntax highlighting) moves to per-theme CSS files
Theme switching Swaps <link id="theme-css"> href instead of toggling body class — no page reload required
Body class Still set to theme-<name> for Mermaid dark-mode detection; non-theme classes (e.g. toc-visible) are preserved on switch
localStorage validation Saved theme name is checked against MDPROXY_THEMES JS array before applying
Syntax highlighting Chroma CSS is scoped under .chroma in each theme file to avoid polluting global selectors

Test plan

  • Server starts and writes github.css, simple.css, dark.css to ~/.config/markdown-proxy/themes/
  • Theme dropdown shows all three built-in themes
  • Each built-in theme renders correctly (colors, code highlighting, TOC, copy button)
  • Adding a custom .css file to the themes directory and restarting makes it appear in the dropdown
  • Selecting a custom theme applies it without page reload
  • Theme choice persists across page navigations (localStorage)
  • go test ./... passes

🤖 Generated with Claude Code

- New internal/themes package: manages built-in CSS (github, simple, dark)
  and user-defined CSS files in ~/.config/markdown-proxy/themes/
- On first launch, writes built-in theme files to the themes directory so
  users can edit or replace them
- Server scans themes directory at startup and populates theme dropdown
  dynamically (new /_theme/<name>.css endpoint)
- CSS architecture changed: structural layout stays embedded; all visual
  styling (colors, fonts, borders, syntax highlighting) lives in theme files
- Theme switching swaps <link> href instead of toggling body class;
  preserves toc-visible and other non-theme body classes
- Theme names from localStorage are validated against MDPROXY_THEMES list
- Built-in chroma syntax highlight CSS is scoped under .chroma to avoid
  polluting global namespace

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@patakuti
patakuti merged commit 40b794e into main Jun 19, 2026
1 check 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.

Add user-defined CSS themes via themes directory

1 participant