pub struct SyntaxHighlighter { /* private fields */ }Expand description
Syntax highlighter for highlighting code
Implementations§
Source§impl SyntaxHighlighter
impl SyntaxHighlighter
Sourcepub fn with_theme(theme: SyntaxTheme) -> Self
pub fn with_theme(theme: SyntaxTheme) -> Self
Create a new syntax highlighter with a specific theme
Sourcepub fn highlight(&self, code: &str, language: &str) -> Result<String>
pub fn highlight(&self, code: &str, language: &str) -> Result<String>
Highlight code and return HTML
§Errors
Returns Error::UnsupportedLanguage when the language name is not
recognized or its lang-* feature is disabled.
Sourcepub fn highlight_with_lang(
&self,
code: &str,
language: &Language,
) -> Result<String>
pub fn highlight_with_lang( &self, code: &str, language: &Language, ) -> Result<String>
Highlight code with a known language
Sourcepub fn highlight_or_fallback(&self, code: &str, language: &str) -> String
pub fn highlight_or_fallback(&self, code: &str, language: &str) -> String
Highlight code, falling back to a plain (escaped) <pre><code> block
when the language is unknown or unsupported.
Sourcepub fn theme(&self) -> SyntaxTheme
pub fn theme(&self) -> SyntaxTheme
Get the current theme
Sourcepub fn set_theme(&mut self, theme: SyntaxTheme)
pub fn set_theme(&mut self, theme: SyntaxTheme)
Set the theme
Sourcepub fn is_language_supported(&self, language: &str) -> bool
pub fn is_language_supported(&self, language: &str) -> bool
Check if a language is supported
Sourcepub fn supported_languages(&self) -> Vec<&'static str>
pub fn supported_languages(&self) -> Vec<&'static str>
Get list of supported languages
Sourcepub fn generate_stylesheet(&self) -> String
pub fn generate_stylesheet(&self) -> String
Generate CSS stylesheet for the current theme
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SyntaxHighlighter
impl RefUnwindSafe for SyntaxHighlighter
impl Send for SyntaxHighlighter
impl Sync for SyntaxHighlighter
impl Unpin for SyntaxHighlighter
impl UnsafeUnpin for SyntaxHighlighter
impl UnwindSafe for SyntaxHighlighter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more