Crate streamdown_syntax

Crate streamdown_syntax 

Source
Expand description

Streamdown Syntax

This crate provides syntax highlighting for code blocks using the syntect library. It’s designed to work with streaming input (line-by-line) for real-time rendering.

§Features

  • Streaming highlighting - Maintain state across lines for multi-line tokens
  • Language aliases - Map common names (py, js, ts) to proper syntax definitions
  • Background override - Override theme background for consistent code block styling
  • ANSI output - Generate 24-bit true color terminal escape codes

§Example

use streamdown_syntax::Highlighter;

let highlighter = Highlighter::new();

// Highlight a complete code block
let code = "fn main() {\n    println!(\"Hello!\");\n}";
let highlighted = highlighter.highlight_block(code, "rust");

// For streaming, use HighlightState
use streamdown_syntax::HighlightState;
let mut hl = Highlighter::new();
let mut state = hl.new_highlight_state("rust");
let line1 = hl.highlight_line_with_state("fn main() {", &mut state);
let line2 = hl.highlight_line_with_state("    println!(\"Hello!\");", &mut state);

Structs§

HighlightState
State for streaming syntax highlighting.
Highlighter
Syntax highlighter for code blocks.

Statics§

LANGUAGE_ALIASES
Static mapping of language aliases.

Functions§

aliases_for
Get all aliases that map to a specific syntax name.
all_aliases
Get all known language aliases.
language_alias
Look up the canonical syntax name for a language alias.
override_theme_background
Create a theme with overridden background color.