Skip to main content

SyntaxHighlighter

Struct SyntaxHighlighter 

Source
pub struct SyntaxHighlighter { /* private fields */ }
Expand description

Syntax highlighter for highlighting code

Implementations§

Source§

impl SyntaxHighlighter

Source

pub fn new() -> Self

Create a new syntax highlighter

Source

pub fn with_theme(theme: SyntaxTheme) -> Self

Create a new syntax highlighter with a specific theme

Source

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.

Source

pub fn highlight_with_lang( &self, code: &str, language: &Language, ) -> Result<String>

Highlight code with a known language

Source

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.

Source

pub fn theme(&self) -> SyntaxTheme

Get the current theme

Source

pub fn set_theme(&mut self, theme: SyntaxTheme)

Set the theme

Source

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

Check if a language is supported

Source

pub fn supported_languages(&self) -> Vec<&'static str>

Get list of supported languages

Source

pub fn generate_stylesheet(&self) -> String

Generate CSS stylesheet for the current theme

Trait Implementations§

Source§

impl Default for SyntaxHighlighter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more