Struct SyntectHtmlHandler

Source
pub struct SyntectHtmlHandler<E: From<Error>, H: HtmlHandler<E>> {
    pub syntax_set: SyntaxSet,
    pub theme_set: ThemeSet,
    pub theme: String,
    pub inner: H,
    pub background: IncludeBackground,
    pub error_type: PhantomData<E>,
}
Expand description

Syntect Html Handler

Simple Usage:

use orgize::Org;
use orgize::export::{DefaultHtmlHandler, SyntectHtmlHandler};

let mut handler = SyntectHtmlHandler::new(DefaultHtmlHandler);
let org = Org::parse("src_rust{println!(\"Hello\")}");

let mut vec = vec![];

org.write_html_custom(&mut vec, &mut handler).unwrap();

Customize:

// orgize has re-exported the whole syntect crate
use orgize::syntect::parsing::SyntaxSet;
use orgize::export::{DefaultHtmlHandler, SyntectHtmlHandler};

let mut handler = SyntectHtmlHandler {
    syntax_set: {
        let set = SyntaxSet::load_defaults_newlines();
        let mut builder = set.into_builder();
        // add extra language syntax
        builder.add_from_folder("path/to/syntax/dir", true).unwrap();
        builder.build()
    },
    // specify theme
    theme: String::from("Solarized (dark)"),
    inner: DefaultHtmlHandler,
    ..Default::default()
};

// Make sure to check if theme presents or it will panic at runtime
if handler.theme_set.themes.contains_key("dont-exists") {

}

Fields§

§syntax_set: SyntaxSet

syntax set, default is SyntaxSet::load_defaults_newlines()

§theme_set: ThemeSet

theme set, default is ThemeSet::load_defaults()

§theme: String

theme used for highlighting, default is "InspiredGitHub"

§inner: H

inner html handler

§background: IncludeBackground

background color, default is IncludeBackground::No

§error_type: PhantomData<E>

handler error type

Implementations§

Source§

impl<E: From<Error>, H: HtmlHandler<E>> SyntectHtmlHandler<E, H>

Source

pub fn new(inner: H) -> Self

Trait Implementations§

Source§

impl<E: From<Error>, H: HtmlHandler<E>> Default for SyntectHtmlHandler<E, H>

Source§

fn default() -> Self

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

impl<E: From<Error>, H: HtmlHandler<E>> HtmlHandler<E> for SyntectHtmlHandler<E, H>

Source§

fn start<W: Write>(&mut self, w: W, element: &Element<'_>) -> Result<(), E>

Source§

fn end<W: Write>(&mut self, w: W, element: &Element<'_>) -> Result<(), E>

Auto Trait Implementations§

§

impl<E, H> !Freeze for SyntectHtmlHandler<E, H>

§

impl<E, H> !RefUnwindSafe for SyntectHtmlHandler<E, H>

§

impl<E, H> Send for SyntectHtmlHandler<E, H>
where H: Send, E: Send,

§

impl<E, H> Sync for SyntectHtmlHandler<E, H>
where H: Sync, E: Sync,

§

impl<E, H> Unpin for SyntectHtmlHandler<E, H>
where H: Unpin, E: Unpin,

§

impl<E, H> UnwindSafe for SyntectHtmlHandler<E, H>
where H: UnwindSafe, E: UnwindSafe,

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.