SyntaxHighlighter

Trait SyntaxHighlighter 

Source
pub trait SyntaxHighlighter: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn supported_languages(&self) -> Vec<String>;
    fn available_themes(&self) -> Vec<String>;
    fn highlight(
        &self,
        code: &str,
        language: &str,
        theme: Option<&str>,
    ) -> SyntaxResult<String>;
    fn language_from_extension(&self, extension: &str) -> Option<String>;

    // Provided methods
    fn supports_language(&self, language: &str) -> bool { ... }
    fn has_theme(&self, theme: &str) -> bool { ... }
    fn language_from_filename(&self, filename: &str) -> Option<String> { ... }
}
Expand description

Trait for syntax highlighting backends.

Allows different syntax highlighting implementations to be used interchangeably. Implementations should handle language detection, theme management, and the actual highlighting process.

Required Methods§

Source

fn name(&self) -> &'static str

Get the name of this highlighter backend

Source

fn supported_languages(&self) -> Vec<String>

Get a list of supported languages

Source

fn available_themes(&self) -> Vec<String>

Get a list of available themes

Source

fn highlight( &self, code: &str, language: &str, theme: Option<&str>, ) -> SyntaxResult<String>

Highlight code with the specified language and theme.

§Arguments
  • code - The source code to highlight
  • language - The programming language (case-insensitive)
  • theme - The theme name (case-insensitive, optional)
§Returns

Highlighted HTML string on success

§Errors

Returns an error if the language or theme is unsupported.

Source

fn language_from_extension(&self, extension: &str) -> Option<String>

Detect language from a file extension

Provided Methods§

Source

fn supports_language(&self, language: &str) -> bool

Check if a language is supported

Source

fn has_theme(&self, theme: &str) -> bool

Check if a theme is available

Source

fn language_from_filename(&self, filename: &str) -> Option<String>

Detect language from a filename

Implementors§