[][src]Struct syntect::html::ClassedHTMLGenerator

pub struct ClassedHTMLGenerator<'a> { /* fields omitted */ }

Output HTML for a line of code with <span> elements using class names

Because this has to keep track of open and closed <span> tags, it is a struct with additional state.

There is a finalize() method that must be called in the end in order to close all open <span> tags.

Note that because CSS classes have slightly different matching semantics than Textmate themes, this may produce somewhat less accurate highlighting than the other highlighting functions which directly use inline colors as opposed to classes and a stylesheet.

Example

use syntect::html::{ClassedHTMLGenerator, ClassStyle};
use syntect::parsing::SyntaxSet;
use syntect::util::LinesWithEndings;

let current_code = r#"
x <- 5
y <- 6
x + y
"#;

let syntax_set = SyntaxSet::load_defaults_newlines();
let syntax = syntax_set.find_syntax_by_name("R").unwrap();
let mut html_generator = ClassedHTMLGenerator::new_with_class_style(&syntax, &syntax_set, ClassStyle::Spaced);
for line in LinesWithEndings::from(current_code) {
    html_generator.parse_html_for_line_which_includes_newline(&line);
}
let output_html = html_generator.finalize();

Implementations

impl<'a> ClassedHTMLGenerator<'a>[src]

pub fn new(
    syntax_reference: &'a SyntaxReference,
    syntax_set: &'a SyntaxSet
) -> ClassedHTMLGenerator<'a>
[src]

👎 Deprecated since 4.2.0:

Please use new_with_class_style instead

pub fn new_with_class_style(
    syntax_reference: &'a SyntaxReference,
    syntax_set: &'a SyntaxSet,
    style: ClassStyle
) -> ClassedHTMLGenerator<'a>
[src]

pub fn parse_html_for_line_which_includes_newline(&mut self, line: &str)[src]

Parse the line of code and update the internal HTML buffer with tagged HTML

Note: This function requires line to include a newline at the end and also use of the load_defaults_newlines version of the syntaxes.

pub fn parse_html_for_line(&mut self, line: &str)[src]

👎 Deprecated since 4.5.0:

Please use parse_html_for_line_which_includes_newline instead

Parse the line of code and update the internal HTML buffer with tagged HTML

Warning

Due to an unfortunate oversight this function adds a newline after the HTML line, and thus requires lines to be passed without newlines in them, and thus requires usage of the load_defaults_nonewlines version of the default syntaxes.

These versions of the syntaxes can have occasionally incorrect highlighting but this function can't be changed without breaking compatibility so is deprecated.

pub fn finalize(self) -> String[src]

Close all open <span> tags and return the finished HTML string

Auto Trait Implementations

impl<'a> !RefUnwindSafe for ClassedHTMLGenerator<'a>

impl<'a> !Send for ClassedHTMLGenerator<'a>

impl<'a> !Sync for ClassedHTMLGenerator<'a>

impl<'a> Unpin for ClassedHTMLGenerator<'a>

impl<'a> !UnwindSafe for ClassedHTMLGenerator<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.