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

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

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

👎 Deprecated since 4.2.0:

Please use new_with_class_style instead

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.

👎 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.

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.