Reference

Field types

The four field types of Brevier and what each does to whitespace and markup, and how a schema declares them.

On this page

Community

A field type says what may be in a value. It also says what happens to whitespace and markup before the value reaches the page. text is the default.

Field type Input Output Does
text "Anna <b>Berg</b>\n" Anna &lt;b&gt;Berg&lt;/b&gt; Runs of spaces and line breaks become one space. The ends are trimmed. Markup is escaped.
multiline "Line 1\nLine <b>2</b>" Line 1<br>Line &lt;b&gt;2&lt;/b&gt; A line break becomes <br>. Other markup is escaped. For addresses and notes.
rich "<b>bold</b> <script>x()</script><a href=\"javascript:x()\">link</a>" <b>bold</b> <a>link</a> Bold, italic, lists, links and line breaks stay. Other markup is removed. For text from a CMS.
raw "<b>x</b>" <b>x</b> The value passes unchanged. Use it only for markup that you trust.

A name that is not one of the four types is treated as text.

What rich keeps

  • Tags: b, i, em, strong, ul, ol, li, a, br, p and span.
  • Attributes: href and title on a, and class on p and span.
  • Links: an href with the scheme http, https, mailto or tel, or with no scheme, stays. A link with another scheme, such as javascript:, loses its href.
  • Event attributes such as onclick are removed.
  • Any other tag is removed and its text stays. script and style lose their text too.

Declare a field type

Give the field x-brevier-type in the template's schema: the file rechnung.schema.json next to rechnung.html, or the schema that --schema names.

rechnung.schema.json
{
  "type": "object",
  "properties": {
    "bemerkung": { "type": "string", "x-brevier-type": "multiline" }
  }
}
  • brevier pdf, brevier html, brevier lint, brevier preview, brevier serve and the clients bind the field with that type.
  • A field without x-brevier-type is text. So is every field of a template that has no schema.
  • The type belongs to the field's place in the schema, not to its name. kunde.name can be rich while lieferant.name stays text.
  • The front-matter fields: block, the page: header and footer, and the Python Pdf builder do not use field types yet: their fields are text.