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

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§

source

fn styled<'a>(&mut self, text: &'a str, style: Style) -> Cow<'a, str>

Is called for every styled region of the input.

The input was already passed to Renderer::escape before. Implementors should return a string representing the input text in the given Style.

Provided Methods§

source

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.

source

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.

source

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

source

fn escape<'a>(&mut self, text: &'a str) -> Cow<'a, str>

Is called for every region of the input, both styled and unstyled.

May be implemented to escape special characters. The output will be passed to styled or unstyled.

The default implementation returns text unchanged.

source

fn unstyled<'a>(&mut self, text: &'a str) -> Cow<'a, str>

Is called for every unstyled region of the input.

The input was already passed to Renderer::escape before.

The default implementation returns text unchanged.

Implementors§