Skip to main content

Crate giallo

Crate giallo 

Source
Expand description

A syntax highlighting library using TextMate grammars and themes and producing the same output as VSCode.

§Example

ⓘ
use giallo::{HighlightOptions, HtmlRenderer, Options, Registry, ThemeVariant};

// Using the `dump` feature and loading the prebuilt assets
let registry = Registry::load_from_file("builtin.zst")?;
let code = "let x = 42;";

let options = HighlightOptions::new("javascript", ThemeVariant::Single("catppuccin-frappe"));
let highlighted = registry.highlight(code, options)?;

let render_options = Options {
    show_line_numbers: true,
    ..Default::default()
};
let html = HtmlRenderer::default().render(&highlighted, &render_options);

Structs§

Color
RGBA color with 8-bit components
CompiledTheme
Compiled theme optimized for fast lookups
ExtraHtmlContent
Extra HTML content to include in the <pre> block.
FontStyle
A compressed representation of all available textmate font styles
HighlightOptions
Options for highlighting by the registry, NOT rendering.
HighlightedCode
Highlighted code with language, theme, and tokens
HighlightedText
A token with associated styling information
HtmlRenderer
A renderer that will output proper HTML code
ParsedFence
A parsed code block parameters
Registry
The main struct in giallo.
RenderOptions
All options you can select across renderers
Style
A complete, concrete, style with foreground, background colors and font styling
TerminalRenderer
Terminal renderer via ANSI escape codes. Requires a terminal that supports truecolor

Enums§

DataAttrPosition
Where to put the additional attributes
Error
Errors that can occur during giallo usage
ThemeVariant
Generic enum for single or dual (light/dark) theme values

Constants§

GIALLO_CSS
The CSS needed for the line number gutter to display properly
PLAIN_GRAMMAR_NAME
The default grammar name, where nothing is highlighted

Functions§

parse_markdown_fence
Parses a markdown fence in the same shape as Zola’s.