Syntax Highlighting
January 17, 2026 · View on GitHub
Full-file syntax highlighting for source code files in Ferrite's raw editor mode.
Overview
Ferrite now supports syntax highlighting for source code files (Rust, Python, JavaScript, etc.) in the raw editor mode. This feature uses the existing syntect library that was previously only used for code blocks in markdown preview.
Supported Languages
The following file extensions are supported:
| Category | Extensions |
|---|---|
| Systems | .rs (Rust), .c, .cpp, .h, .hpp, .go, .swift |
| Web | .js, .ts, .tsx, .jsx, .html, .css, .scss, .sass, .less |
| Scripting | .py, .rb, .php, .lua, .pl, .sh, .bash, .ps1 |
| JVM | .java, .kt, .scala, .clj |
| Data | .json, .yaml, .yml, .toml, .xml |
| Functional | .hs, .ex, .exs, .erl |
| Other | .sql, .vim, .diff, .ini, .cmake, .dockerfile, .makefile |
Usage
Enabling/Disabling
- Open Settings (Ctrl+,)
- Navigate to the Editor section
- Toggle Syntax Highlighting checkbox
The setting is enabled by default.
How It Works
- When you open a source code file, Ferrite detects the language from the file extension
- If syntax highlighting is enabled and the language is recognized, the editor applies colored text formatting
- Syntax colors automatically adapt to light/dark theme (using
base16-ocean.darkfor dark mode andInspiredGitHubfor light mode) - Markdown files are handled separately by the rendered/WYSIWYG editor, so syntax highlighting only affects other file types in raw mode
Implementation Details
Files Modified
| File | Changes |
|---|---|
src/config/settings.rs | Added syntax_highlighting_enabled: bool setting |
src/ui/settings.rs | Added checkbox in Editor section |
src/markdown/syntax.rs | Added language_from_path() and can_highlight_file() helpers |
src/editor/widget.rs | Modified layouter to use syntax highlighting |
src/app.rs | Passed syntax highlighting config to EditorWidget |
Key Components
-
Language Detection:
language_from_path()insyntax.rsmaps file extensions to syntect language identifiers -
Highlighter Integration: The
EditorWidgetlayouter creates a coloredLayoutJobusinghighlight_code()when a language is detected -
Theme Selection: Dark mode uses
base16-ocean.dark, light mode usesInspiredGitHub
Performance Considerations
- Caching: Highlighted output is cached in egui's memory and only regenerated when content changes (detected via content hash). This makes static viewing essentially zero-cost.
- The syntect
SyntaxSetandThemeSetare loaded once globally and reused - Cache is keyed by (editor_id, content_hash, language, dark_mode) for correctness
Testing
- Open a
.rs,.py,.js, or.jsonfile - Verify syntax colors appear (keywords, strings, comments should have distinct colors)
- Toggle setting off in Settings → Editor → Syntax Highlighting
- Colors should disappear (plain text)
- Switch between light/dark theme - colors should adapt
Known Limitations
- Bold/italic font styles from syntect are not applied (egui TextFormat limitation)
- No per-file-type theme customization (uses global dark/light themes)
- Initial highlighting of very large files (>10,000 lines) may take a moment on first open