highlighter #
V Highlighter
Sorry, this version is broken. Try an older version or come back later.
A lightweight, native V module to inject (Prism-compatible css) syntax highlighting into static HTML files at build time. No client-side JavaScript required.
Features
- Native V: No external regex engine dependencies.
- Fast: High-speed scanner (FSM)
- Prism Compatible: Outputs standard
tokenclasses. - Auto-detection: Automatically highlights blocks with
class="language-xxx"or defaults to Bash.
Documentation
Installation
For V Users
v install https://codeberg.org/tamer/highlighter.git
For C Users
make compile_c_linux - Build using GCC from the C file
make compile_c_windows - Build for Win using MinGW from the C file
Usage
As a CLI tool
highlight --verbose --force /var/www
As a Module
import highlighter
mut hl := highlighter.new_manager()
html_output := hl.highlight_html(markdown_generated_html)
Using make
$ make help
make build - Local optimized V build
make c_source - Update standalone highlight_standalone.c
make compile_c_linux - Build using GCC from the C file
make compile_c_windows - Build for Win using MinGW from the C file
make dist - Create optimized Linux, Win, Mac binaries
Structure
.
├── highlighter.v # Logic moved to root
├── v.mod # Module info
├── highlight_standalone.c # Standalone C
├── Makefile
├── lang_data/ # JSON language files
├── cmd/
│ └── main.v # CLI entry point
└── convert.lua # Bootstrap script
License
Distributed under the MIT License. See LICENSE for more information.
Acknowledgements
- Google Gemini: For collaborating on the native V scanner logic and the conversion pipeline.
- Lite XL: For the comprehensive syntax definitions that power the language support.
- Prism CSS: For the beautiful themes and standardized token naming conventions.
fn new_manager #
fn new_manager() Manager
struct Manager #
struct Manager {
pub mut:
cache map[string]SyntaxDef
json_dir string
}
fn (Manager) highlight_html #
fn (mut m Manager) highlight_html(html string) string
struct PatternItem #
struct PatternItem {
pub:
pattern string
@type string @[json: type]
}
struct SyntaxDef #
struct SyntaxDef {
pub:
patterns []PatternItem
symbols map[string]string
comment string
}