renderer {highlight}R Documentation

highlight renderer

Description

The function builds a renderer, suitable for the renderer argument of the highlight function. In the highlight process, renderers are responsible to render the information in the target markup language.

Usage

renderer(translator, formatter, space, newline, header, footer, ...)

Arguments

translator

This argument should be a function with one argument. The translator needs to work token characters so that they display nicely in the target markup language.

formatter

The formatter should be a function with at least two arguments: the tokens and the styles. These two arguments are supplied to the formatter by the highlight function. The formatter should wrap tokens and styles into the target markup language. For example, the formatter used by the html renderer makes a ‘⁠<span>⁠’ tag of ‘⁠class⁠’ given by the ‘⁠styles⁠’ and content given by the ‘⁠token⁠’.

space

This should be a function with no argument. The output of this function should be a character vector of length one giving the representation of a space character in the target language. For example, in the latex renderer, the function returns ‘⁠"{\ }"⁠’.

newline

This should be a function with no argument. The output of the function is a character vector of length one giving the representation of a newline character in the target language.

header

This should be a function with no argument. The output of this function is a character vector of arbitrary length. The elements of the output are written before the highlighted content. headers and footers are used to embed the highlighted tokens into some markup. For example, the header used in the html renderer starts a ‘⁠<pre>⁠’ tag that is closed by the footer. headers and footer might also be used to write style definitions such as CSS, STY, ...

footer

This should be a function with no argument. The output of this function is written after all tokens.

...

Additional arguments. This might be used to store additional renderer specific objects.

Details

Implementations of renderers should call this function to ensure that a proper renderer is created. At the moment, no checking is performed to ensure that the built object complies with the expected interface, but this is very likely to change.

Value

A ‘⁠renderer⁠’ object. Renderer objects define the interface expected by the highlight function. At the moment, a renderer object is a list of class ‘⁠renderer⁠’ containing elements: ‘⁠translator⁠’, ‘⁠formatter⁠’, ‘⁠space⁠’, ‘⁠newline⁠’, ‘⁠header⁠’ and ‘⁠footer⁠’.

See Also

The renderer_html implements a renderer using html markup, ‘⁠<span>⁠’ tags and CSS.

The renderer_latex implements a latex renderer.


[Package highlight version 0.5.1 Index]