Reference

Cleaners

The four cleaners of Brevier, each with an input and an output, and the fact that no template sets them yet.

On this page

Community

A cleaner removes unwanted parts from a value before it is bound: stray tags, entities and extra spaces. Cleaners run in the order they are listed, before the field type.

Cleaner Input Output Does
stripHtml "<p>Hello <b>world</b></p>" Hello world Removes every tag and keeps the text. Entities such as &nbsp; stay. A <br> joins the words around it.
decodeEntities "Tom &amp; Jerry &lt;3" Tom & Jerry <3 Turns HTML entities into their characters.
collapseSpaces "a b\r\n c" a b c Turns each run of spaces, tabs and line breaks into one space.
trim " hi " hi Removes spaces, tabs and line breaks at both ends.

On a multiline field, collapseSpaces turns \r\n into \n and keeps the line breaks.

An unknown name fails. The error lists the four known names.

A typical list for text from a database: [stripHtml, decodeEntities, collapseSpaces, trim].

Not available in a template yet

No template, schema or command sets a cleaner today. No render through brevier pdf, brevier html, the clients or brevier serve runs one.

The engine reads cleaners from a function argument: bind_template(html, data, cleaners={"note": ["stripHtml", "trim"]}).

The PRD (section E) describes a declaration in a schema or in the front matter. It is not read yet.