Contains helper functions for converting Elixir datatypes into the format that Typst expects.
These functions are useful when building Typst markup with EEx templates.
Examples
iex> Typst.render_to_string("Name: <%= name %>", name: Typst.Format.bold("Alice"))
"Name: *Alice*"
iex> Typst.render_to_string("columns: <%= cols %>", cols: Typst.Format.array(["1fr", "2fr"]))
"columns: (1fr, 2fr)"
Summary
Functions
Converts a list into a Typst array (...).
Wraps the given element in Typst bold markers (*...*).
Wraps the given element in Typst content brackets ([...]).
Escapes special Typst markup characters in the given string by prefixing them with a backslash.
Functions
Converts a list into a Typst array (...).
Examples
iex> Typst.Format.array(["1fr", "2fr", "1fr"])
"(1fr, 2fr, 1fr)"
iex> Typst.Format.array(["red", "blue"])
"(red, blue)"
@spec bold(String.Chars.t()) :: String.t()
Wraps the given element in Typst bold markers (*...*).
Examples
iex> Typst.Format.bold("hello")
"*hello*"
iex> Typst.Format.bold(42)
"*42*"
@spec content(String.Chars.t()) :: String.t()
Wraps the given element in Typst content brackets ([...]).
Returns [] for nil values.
Examples
iex> Typst.Format.content("hello")
"[hello]"
iex> Typst.Format.content(nil)
"[]"
Escapes special Typst markup characters in the given string by prefixing them with a backslash.
This is useful when inserting user-provided text that should be rendered literally, without triggering Typst's markup syntax.
The following characters are escaped: \, *, _, `, $, #, @, <, >, ~, =, -, +, /, [, ]
Note: the \\ in the examples below is Elixir's string representation of a single backslash.
Examples
iex> Typst.Format.escape("hello *world*")
"hello \\*world\\*"
iex> Typst.Format.escape("email@example.com")
"email\\@example.com"
iex> Typst.Format.escape("price is $10")
"price is \\$10"