Skip to main content

highlight_code_to_segments

Function highlight_code_to_segments 

Source
pub fn highlight_code_to_segments(
    code: &str,
    language: Option<&str>,
    theme_name: &str,
) -> Vec<(Style, String)>
Expand description

Highlight code and return styled segments

§Arguments

  • code - Source code to highlight
  • language - Optional language hint (auto-detected if None)
  • theme_name - Syntax theme name (use get_active_syntax_theme() for UI theme sync)

§Returns

Vector of (Style, String) tuples for rendering

§Performance

  • Returns None early if input exceeds guardrails
  • Uses cached theme when available