[−][src]Function syntect::html::styled_line_to_highlighted_html
pub fn styled_line_to_highlighted_html(
v: &[(Style, &str)],
bg: IncludeBackground
) -> String
Output HTML for a line of code with <span>
elements using inline
style
attributes to set the correct font attributes.
The bg
attribute determines if the spans will have the background-color
attribute set. See the IncludeBackground
enum's docs.
The lines returned don't include a newline at the end.
Examples
use syntect::easy::HighlightLines; use syntect::parsing::SyntaxSet; use syntect::highlighting::{ThemeSet, Style}; use syntect::html::{styled_line_to_highlighted_html, IncludeBackground}; // Load these once at the start of your program let ps = SyntaxSet::load_defaults_newlines(); let ts = ThemeSet::load_defaults(); let syntax = ps.find_syntax_by_name("Ruby").unwrap(); let mut h = HighlightLines::new(syntax, &ts.themes["base16-ocean.dark"]); let regions = h.highlight("5", &ps); let html = styled_line_to_highlighted_html(®ions[..], IncludeBackground::No); assert_eq!(html, "<span style=\"color:#d08770;\">5</span>");