stacks
stacks copied to clipboard
fix: syntax highlighting doesn't switch dark / light mode when the UI does
Currently, markdown rendering and syntax highlighting are handled in the Rust backend. This might be a mistake, and potentially we should move this responsibility to the webview / Javascript.
Syntax highlighting leverages syntext, as detailed here: https://github.com/cablehead/stacks/blob/main/src-tauri/src/ui.rs#L304-L313
The implementation "bakes" the color scheme directly into the generated HTML. The frontend, which caches this content, doesn't update the syntax highlighting color scheme when the main UI toggles between light and dark modes.
I think there's ~2 solutions:
- Use classes for syntax highlighting elements, avoiding hardcoded color values. This way, CSS classes with variables can adjust to light/dark mode changes in the main UI.
Possible approaches for this solution include:
- Configuring
syntect
to output classes instead of direct color values: https://docs.rs/syntect/latest/syntect/html/struct.ClassedHTMLGenerator.html - Exploring a different Rust crate for this purpose.
- Moving syntax highlighting to the frontend, utilizing a library designed to handle this issue
- Invalidate the frontend's content cache when toggling between light and dark modes.