Builder functions for Folio content nodes.
Every function returns a %Folio.Content.*{} struct.
Use inside #{} interpolation in ~MD sigils, or directly in Elixir code.
use Folio
content = [heading(1, "Title"), text("Hello"), strong("world")]
{:ok, pdf} = Folio.to_pdf(content)
Summary
Functions
Align content. Accepts :left, :center, :right or string equivalents.
Insert a bibliography listing.
Block-level container. Options: :width, :height, :above, :below.
Block quote. Options: :block, :attribution.
Circle. Options: :radius, :fill, :body.
Cite a bibliography entry.
Force a column break. Options: :weak.
Flow content into count columns. Options: :gutter.
Horizontal divider.
Ellipse. Options: :width, :height, :fill, :body.
Italic text.
Numbered list. Items can be plain content or {number, content} tuples.
Wrap content in a figure. Options: :caption, :placement ("top"/"bottom"), :scope, :numbering.
Footnote.
Grid layout. Options: :columns, :rows, :gutter.
Use do block for cells.
Create a grid cell. Options: :colspan, :rowspan, :align, :fill.
Create a heading (levels 1-6).
Hide content (invisible but takes space).
Highlighted text. Options: :fill color.
Horizontal spacing. Options: :weak.
Embed an image. Options: :width, :height, :fit ("contain"/"cover"/"stretch").
Label a position for cross-references.
Line. Options: :start, :end, :length, :angle, :stroke.
Insert a line break.
Hyperlink. Second argument is optional display text.
Bullet list. Options: :tight, :marker.
Local style overrides for a content block.
Mirrors Typst's #set text(...) / #set par(...) within a scope.
Math expression in Typst syntax. Options: :block.
Table of contents. Options: :title, :indent, :depth.
Add padding around content. Options: :left, :right, :top, :bottom.
Force a page break. Options: :weak.
Insert a paragraph break.
Place content at an alignment. Options: :alignment, :float.
Polygon from coordinate list. Options: :fill, :stroke.
Raw/code text. Options: :lang, :block.
Raw Typst source injected directly.
Rectangle. Options: :width, :height, :fill, :body.
Reference a labelled element.
Repeat content to fill available space.
Create a show rule that transforms matching content elements.
Small capitals text.
Square. Options: :size, :fill, :body.
Stack children in a direction. Options: :dir ("ttb"/"ltr"/"rtl"/"btt"), :spacing.
Strikethrough text.
Bold text.
Subscript text.
Superscript text.
Create a table. Options: :columns, :rows, :stroke, :gutter, :align. Use do block for rows.
Create a table cell. Options: :colspan, :rowspan, :align.
Create a table header row from a list of cell contents.
Create a table data row from a list of cell contents.
Single term item.
Definition list from {term, description} tuples. Options: :tight.
Create a text node.
Document title.
Underlined text.
Vertical spacing. Options: :weak.
Functions
@spec align(atom() | String.t(), Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Align.t()
Align content. Accepts :left, :center, :right or string equivalents.
@spec bibliography( String.t() | [String.t()], keyword() ) :: Folio.Content.Bibliography.t()
Insert a bibliography listing.
bibliography("refs.bib", title: "References", style: "ieee")
@spec block( keyword(), [{:do, [Folio.Content.t()]}] ) :: Folio.Content.Block.t()
Block-level container. Options: :width, :height, :above, :below.
@spec blockquote( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.Quote.t()
Block quote. Options: :block, :attribution.
@spec circle(keyword()) :: Folio.Content.Circle.t()
Circle. Options: :radius, :fill, :body.
@spec cite( String.t(), keyword() ) :: Folio.Content.Cite.t()
Cite a bibliography entry.
cite("knuth1984", form: "prose")
@spec colbreak(keyword()) :: Folio.Content.Colbreak.t()
Force a column break. Options: :weak.
@spec columns(pos_integer(), keyword(), [{:do, [Folio.Content.t()]}]) :: Folio.Content.Columns.t()
Flow content into count columns. Options: :gutter.
@spec divider() :: Folio.Content.Divider.t()
Horizontal divider.
@spec ellipse(keyword()) :: Folio.Content.Ellipse.t()
Ellipse. Options: :width, :height, :fill, :body.
@spec emph(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Emph.t()
Italic text.
@spec enum( [term()], keyword() ) :: Folio.Content.EnumList.t()
Numbered list. Items can be plain content or {number, content} tuples.
enum(["First", "Second"]) # auto-numbered
enum([{1, "First"}, {5, "Fifth"}]) # explicit numbers
enum(["A", "B"], start: 3) # start from 3
@spec figure( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.Figure.t()
Wrap content in a figure. Options: :caption, :placement ("top"/"bottom"), :scope, :numbering.
@spec footnote(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Footnote.t()
Footnote.
@spec grid( keyword(), [{:do, [Folio.Content.t()]}] ) :: Folio.Content.Grid.t()
Grid layout. Options: :columns, :rows, :gutter.
Use do block for cells.
grid(columns: ["1fr", "1fr"], gutter: "6pt",
do: [grid_cell("A"), grid_cell("B")])
@spec grid_cell( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.GridCell.t()
Create a grid cell. Options: :colspan, :rowspan, :align, :fill.
@spec heading(1..6, Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Heading.t()
Create a heading (levels 1-6).
@spec hide(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Hide.t()
Hide content (invisible but takes space).
@spec highlight( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.Highlight.t()
Highlighted text. Options: :fill color.
@spec hspace( String.t() | number(), keyword() ) :: Folio.Content.HSpace.t()
Horizontal spacing. Options: :weak.
@spec image( String.t(), keyword() ) :: Folio.Content.Image.t()
Embed an image. Options: :width, :height, :fit ("contain"/"cover"/"stretch").
@spec label(String.t()) :: Folio.Content.Label.t()
Label a position for cross-references.
@spec line(keyword()) :: Folio.Content.Line.t()
Line. Options: :start, :end, :length, :angle, :stroke.
@spec linebreak() :: Folio.Content.Linebreak.t()
Insert a line break.
@spec link(String.t(), nil | Folio.Content.t() | String.t()) :: Folio.Content.Link.t()
Hyperlink. Second argument is optional display text.
@spec list( [term()], keyword() ) :: Folio.Content.List.t()
Bullet list. Options: :tight, :marker.
@spec local_set( keyword(), [{:do, [Folio.Content.t()]}] ) :: Folio.Content.LocalSet.t()
Local style overrides for a content block.
Mirrors Typst's #set text(...) / #set par(...) within a scope.
local_set([hyphenate: false, justify: false],
do: [text("No hyphenation here")])
@spec math( String.t(), keyword() ) :: Folio.Content.Math.t()
Math expression in Typst syntax. Options: :block.
@spec outline(keyword()) :: Folio.Content.Outline.t()
Table of contents. Options: :title, :indent, :depth.
@spec pad( keyword(), [{:do, [Folio.Content.t()]}] ) :: Folio.Content.Pad.t()
Add padding around content. Options: :left, :right, :top, :bottom.
@spec pagebreak(keyword()) :: Folio.Content.Pagebreak.t()
Force a page break. Options: :weak.
@spec parbreak() :: Folio.Content.Parbreak.t()
Insert a paragraph break.
@spec place( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.Place.t()
Place content at an alignment. Options: :alignment, :float.
@spec polygon( [{number(), number()}], keyword() ) :: Folio.Content.Polygon.t()
Polygon from coordinate list. Options: :fill, :stroke.
@spec raw( String.t(), keyword() ) :: Folio.Content.Raw.t()
Raw/code text. Options: :lang, :block.
@spec raw_typst(String.t()) :: Folio.Content.RawTypst.t()
Raw Typst source injected directly.
raw_typst("#set text(hyphenate: false)Hello")
@spec rect(keyword()) :: Folio.Content.Rect.t()
Rectangle. Options: :width, :height, :fill, :body.
@spec ref(String.t(), nil | Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Ref.t()
Reference a labelled element.
@spec repeat(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Repeat.t()
Repeat content to fill available space.
@spec show(atom(), (struct() -> Folio.Content.t() | [Folio.Content.t()] | String.t())) :: Folio.Content.ShowRule.t()
Create a show rule that transforms matching content elements.
The target is an atom matching the content type. Common targets:
:enum, :enum_item, :list, :list_item, :heading,
:paragraph, :quote, :table, :grid, :block, etc.
The transform receives the matched struct and returns replacement content (a struct, a list of structs, or a string).
Example — custom enum formatting
show(:enum, fn %Folio.Content.EnumList{children: items} ->
items
|> Enum.with_index(1)
|> Enum.map(fn {item, num} ->
block([above: "0.65em", below: "0.65em"],
do: [
local_set([first_line_indent: 0],
do: [
hspace("1.25cm"),
text("#{num}."),
hspace("0.3em"),
item.body
]
)
]
)
end)
|> List.flatten()
end)
@spec smallcaps(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Smallcaps.t()
Small capitals text.
@spec square(keyword()) :: Folio.Content.Square.t()
Square. Options: :size, :fill, :body.
@spec stack( keyword(), [{:do, [Folio.Content.t()]}] ) :: Folio.Content.Stack.t()
Stack children in a direction. Options: :dir ("ttb"/"ltr"/"rtl"/"btt"), :spacing.
@spec strike(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Strike.t()
Strikethrough text.
@spec strong(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Strong.t()
Bold text.
@spec subscript(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Sub.t()
Subscript text.
@spec superscript(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Super.t()
Superscript text.
@spec table( keyword(), [{:do, [Folio.Content.t()]}] ) :: Folio.Content.Table.t()
Create a table. Options: :columns, :rows, :stroke, :gutter, :align. Use do block for rows.
@spec table_cell( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.TableCell.t()
Create a table cell. Options: :colspan, :rowspan, :align.
@spec table_header([Folio.Content.t() | String.t()]) :: Folio.Content.TableHeader.t()
Create a table header row from a list of cell contents.
@spec table_row([Folio.Content.t() | String.t()]) :: Folio.Content.TableRow.t()
Create a table data row from a list of cell contents.
@spec term_item(term(), term()) :: Folio.Content.TermItem.t()
Single term item.
@spec term_list( [{term(), term()}], keyword() ) :: Folio.Content.TermList.t()
Definition list from {term, description} tuples. Options: :tight.
@spec text(String.t()) :: Folio.Content.Text.t()
Create a text node.
@spec title(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Title.t()
Document title.
@spec underline(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Underline.t()
Underlined text.
@spec vspace( String.t() | number(), keyword() ) :: Folio.Content.VSpace.t()
Vertical spacing. Options: :weak.