Oak Syntax Highlighter
A powerful syntax highlighter supporting multiple programming languages, built on oak-core for accurate tokenization and beautiful code presentation.
🎯 Overview
Oak of highlight is a comprehensive syntax highlighter designed to provide beautiful and accurate code highlighting for multiple programming languages. Built on the solid foundation of oak-core, it offers detailed tokenization, customizable themes, and efficient rendering for various output formats.
✨ Features
- Multi-Language Support: Highlight code in 100+ programming languages
- Customizable Themes: Built-in themes with custom theme support
- Accurate Tokenization: Precise lexical analysis using oak-core parsers
- Multiple Output Formats: HTML, ANSI terminal colors, LaTeX
- Performance Optimized: Fast highlighting with minimal allocations
- Language Detection: Automatic language detection from file extensions
🚀 Quick Start
Basic example:
use ;
📋 Highlighting Examples
Rust Code
use ;
let highlighter = new;
let rust_code = r#"use std::collections::HashMap;
fn process_data(items: Vec<&str>) -> Result<HashMap<String, usize>, Error> {
let mut counts = HashMap::new();
for item in items {
*counts.entry(item.to_string()).or_insert(0) += 1;
}
Ok(counts)
}
#[derive(Debug)]
struct Config {
debug: bool,
timeout: Duration,
}"#;
let highlighted = highlighter.highlight?;
println!;
Python Code
use ;
let highlighter = new;
let python_code = r#"import asyncio
import aiohttp
from typing import List, Optional
async def fetch_data(urls: List[str]) -> List[str]:
"""Fetch data from multiple URLs concurrently."""
async with aiohttp.ClientSession() as session:
tasks = [fetch_single(session, url) for url in urls]
results = await asyncio.gather(*tasks)
return results
async def fetch_single(session: aiohttp.ClientSession, url: str) -> Optional[str]:
try:
async with session.get(url) as response:
return await response.text()
except aiohttp.ClientError as e:
print(f"Error fetching {url}: {e}")
return None"#;
let highlighted = highlighter.highlight_format?;
println!;
JavaScript Code
use ;
let highlighter = new;
let js_code = r#"class ApiClient {
constructor(baseURL) {
this.baseURL = baseURL;
this.headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
};
}
async get(endpoint) {
const response = await fetch(`${this.baseURL}${endpoint}`, {
method: 'GET',
headers: this.headers
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
}
async post(endpoint, data) {
return fetch(`${this.baseURL}${endpoint}`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify(data)
});
}
}"#;
let highlighted = highlighter.highlight?;
println!;
🔧 Advanced Features
Custom Themes
use ;
let mut highlighter = new;
// Create a custom theme
let custom_theme = Custom ;
let code = "fn main() { println!(\"Hello\"); }";
let highlighted = highlighter.highlight?;
Language Detection
use ;
let highlighter = new;
let detector = new;
// Detect language from file extension
let language = detector.detect_from_extension?;
println!;
// Detect language from code content
let code = "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)";
let language = detector.detect_from_content?;
println!;
Batch Processing
use ;
use HashMap;
let highlighter = new;
let mut processor = new;
let mut files = new;
files.insert;
files.insert;
files.insert;
let results = processor.highlight_batch?;
for in results
Performance Monitoring
use ;
let mut highlighter = new;
highlighter.enable_performance_monitoring;
let code = r#"fn main() {
let numbers = vec![1, 2, 3, 4, 5];
for n in numbers {
println!("Number: {}", n);
}
}"#;
let highlighted = highlighter.highlight?;
if let Some = highlighter.get_performance_stats
🏗️ Supported Languages
Oak of highlight supports syntax highlighting for 100+ programming languages including:
- Systems Languages: Rust, C, C++, Go, Zig
- Web Technologies: JavaScript, TypeScript, HTML, CSS, JSON
- Scripting Languages: Python, Ruby, Perl, Bash, PowerShell
- Functional Languages: Haskell, OCaml, F#, Elixir
- JVM Languages: Java, Kotlin, Scala, Groovy
- .NET Languages: C#, F#, VB.NET
- Mobile Development: Swift, Kotlin, Dart
- Data Formats: JSON, YAML, TOML, XML, SQL
- Configuration: Dockerfile, Makefile, Git configs
📊 Performance
- Fast Tokenization: Optimized lexers for each language
- Efficient Rendering: Minimal allocations during highlighting
- Caching: Intelligent caching of tokenized results
- Streaming: Support for large files with streaming
🔗 Integration
Oak of highlight integrates seamlessly with:
- Documentation Generators: Highlight code examples in docs
- Blog Platforms: Syntax highlighting for code in blog posts
- IDE Plugins: Code highlighting for editors
- Static Site Generators: Highlight code in generated websites
- Terminal Applications: Colorful code display in terminals
📚 Examples
Check out the examples directory for comprehensive examples:
- Basic syntax highlighting for different languages
- Custom theme creation and application
- HTML and terminal output generation
- Batch processing multiple files
- Performance optimization techniques
🤝 Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Pex Syntax Highlighter - Beautiful code highlighting for every language 🚀