Trait syntastica::renderer::Renderer
source · pub trait Renderer {
// Required method
fn styled<'a>(&mut self, text: &'a str, style: Style) -> Cow<'a, str>;
// Provided methods
fn head(&mut self) -> Cow<'static, str> { ... }
fn tail(&mut self) -> Cow<'static, str> { ... }
fn newline(&mut self) -> Cow<'static, str> { ... }
fn escape<'a>(&mut self, text: &'a str) -> Cow<'a, str> { ... }
fn unstyled<'a>(&mut self, text: &'a str) -> Cow<'a, str> { ... }
}
Expand description
A Renderer
defines how to render Highlights
to end users. The methods are invoked by
render
.
Syntastica comes with two implementors of this trait, namely
TerminalRenderer
for output to ANSI compatible terminals, andHtmlRenderer
for output to websites.
If the purpose of a trait function is not clear, it may be worthwhile to look at the
implementation of TerminalRenderer
and HtmlRenderer
.
Required Methods§
Provided Methods§
sourcefn head(&mut self) -> Cow<'static, str>
fn head(&mut self) -> Cow<'static, str>
Is called at the start of rendering, before anything else. The returned string will be the start of the final output.
The default implementation returns an empty string.
sourcefn tail(&mut self) -> Cow<'static, str>
fn tail(&mut self) -> Cow<'static, str>
Is called at the end of rendering, after the final call to Renderer::newline
.
The returned string will be the end of the final output.
The default implementation returns an empty string.
sourcefn newline(&mut self) -> Cow<'static, str>
fn newline(&mut self) -> Cow<'static, str>
Is called at the end of every input line. The returned string will be used for line breaks in the output.
The default implementation returns "\n"
.