pub struct CodeTheme { /* private fields */ }Expand description
An owned syntax-highlighting theme for fenced code blocks.
Convert a BuiltinCodeTheme into this type, parse TextMate source with
CodeTheme::from_textmate, or load a TextMate file with CodeTheme::from_file. Then pass
the theme to Options::code_theme.
The renderer consults the theme only for fenced code blocks whose language is recognized.
This type hides the syntax-highlighting implementation so applications do not need to depend on its types or version.
Implementations§
Source§impl CodeTheme
impl CodeTheme
Sourcepub fn from_textmate(source: &str) -> Result<Self, CodeThemeLoadError>
pub fn from_textmate(source: &str) -> Result<Self, CodeThemeLoadError>
Parses a TextMate syntax-highlighting theme.
This constructor parses source immediately and does not access the filesystem. The
returned theme owns the parsed data and does not borrow source. Applications can combine
this method with include_str! to compile a theme into their binary.
§Errors
Returns CodeThemeLoadError when source is not a valid TextMate theme.
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, CodeThemeLoadError>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, CodeThemeLoadError>
Loads a TextMate syntax-highlighting theme from disk.
This function reads and parses the file synchronously. The resulting CodeTheme owns the
parsed theme, so rendering does not access the file again. Use CodeTheme::from_textmate
with include_str! when the theme should be compiled into the application instead.
§Errors
Returns CodeThemeLoadError when the file cannot be read or its contents are not a valid
TextMate theme. The error message includes the requested path.
§Example
use tui_markdown::{CodeTheme, Options};
let theme = CodeTheme::from_file("themes/solarized.tmTheme")?;
let options = Options::default().code_theme(theme);Trait Implementations§
Source§impl From<BuiltinCodeTheme> for CodeTheme
impl From<BuiltinCodeTheme> for CodeTheme
Source§fn from(theme: BuiltinCodeTheme) -> Self
fn from(theme: BuiltinCodeTheme) -> Self
Auto Trait Implementations§
impl Freeze for CodeTheme
impl RefUnwindSafe for CodeTheme
impl Send for CodeTheme
impl Sync for CodeTheme
impl Unpin for CodeTheme
impl UnsafeUnpin for CodeTheme
impl UnwindSafe for CodeTheme
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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