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. Options: :size, :weight, :fill, :tracking.
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.
Examples
use Folio
align(:center, heading(1, "Centered Title"))
align(:right, text("Right-aligned"))
@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.
Examples
use Folio
block(above: "1em", below: "1em",
do: [text("Spaced block content.")])
@spec blockquote( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.Quote.t()
Block quote. Options: :block, :attribution.
Examples
use Folio
blockquote("To be, or not to be.")
blockquote("Elementary, my dear Watson.", attribution: "Sherlock Holmes")
@spec circle(keyword()) :: Folio.Content.Circle.t()
Circle. Options: :radius, :fill, :body.
Examples
use Folio
circle(radius: "20pt", fill: "#ff0000")
@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.
Examples
use Folio
colbreak()
colbreak(weak: true)
@spec columns(pos_integer(), keyword(), [{:do, [Folio.Content.t()]}]) :: Folio.Content.Columns.t()
Flow content into count columns. Options: :gutter.
Examples
use Folio
columns(2, gutter: "12pt",
do: [
text("Left column content."),
colbreak(),
text("Right column content.")
])
@spec divider() :: Folio.Content.Divider.t()
Horizontal divider.
Examples
use Folio
divider()
@spec ellipse(keyword()) :: Folio.Content.Ellipse.t()
Ellipse. Options: :width, :height, :fill, :body.
Examples
use Folio
ellipse(width: "80pt", height: "40pt", fill: "#aaffaa")
@spec emph(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Emph.t()
Italic text.
Examples
use Folio
emph("emphasis")
@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.
Examples
use Folio
[text("See here"), footnote("Additional details in the appendix.")]
@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.
Examples
use Folio
grid_cell("plain")
grid_cell(strong("header"), colspan: 2, fill: "#eeeeee")
@spec heading(1..6, Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Heading.t()
Create a heading (levels 1-6).
Examples
use Folio
heading(1, "Introduction")
heading(2, [strong("Bold"), text(" subtitle")])
@spec hide(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Hide.t()
Hide content (invisible but takes space).
Examples
use Folio
hide(text("placeholder"))
@spec highlight( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.Highlight.t()
Highlighted text. Options: :fill color.
Examples
use Folio
highlight("important passage")
highlight("custom color", fill: "#ffff00")
@spec hspace( String.t() | number(), keyword() ) :: Folio.Content.HSpace.t()
Horizontal spacing. Options: :weak.
Examples
use Folio
hspace("1em")
hspace("0.5cm", weak: true)
@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.
Examples
use Folio
[heading(1, "Introduction"), label("intro")]
@spec line(keyword()) :: Folio.Content.Line.t()
Line. Options: :start, :end, :length, :angle, :stroke.
Examples
use Folio
line(length: "100%", stroke: "1pt")
line(start: "(0pt, 0pt)", end: "(50pt, 50pt)")
@spec linebreak() :: Folio.Content.Linebreak.t()
Insert a line break.
Examples
use Folio
[text("Line one."), linebreak(), text("Line two.")]
@spec link(String.t(), nil | Folio.Content.t() | String.t()) :: Folio.Content.Link.t()
Hyperlink. Second argument is optional display text.
Examples
use Folio
link("https://elixir-lang.org")
link("https://elixir-lang.org", "Elixir")
link("https://elixir-lang.org", strong("Elixir"))
@spec list( [term()], keyword() ) :: Folio.Content.List.t()
Bullet list. Options: :tight, :marker.
Examples
use Folio
list(["First item", "Second item", "Third item"])
list(["A", "B"], tight: false, 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.
Examples
use Folio
math("x^2 + y^2 = r^2")
math("sum_(i=1)^n i = (n(n+1))/2", block: true)
@spec outline(keyword()) :: Folio.Content.Outline.t()
Table of contents. Options: :title, :indent, :depth.
Examples
use Folio
outline()
outline(title: "Contents", depth: 2)
@spec pad( keyword(), [{:do, [Folio.Content.t()]}] ) :: Folio.Content.Pad.t()
Add padding around content. Options: :left, :right, :top, :bottom.
Examples
use Folio
pad(left: "1cm", right: "1cm",
do: [text("Indented paragraph.")])
@spec pagebreak(keyword()) :: Folio.Content.Pagebreak.t()
Force a page break. Options: :weak.
Examples
use Folio
pagebreak()
pagebreak(weak: true)
@spec parbreak() :: Folio.Content.Parbreak.t()
Insert a paragraph break.
Examples
use Folio
[text("First paragraph."), parbreak(), text("Second paragraph.")]
@spec place( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.Place.t()
Place content at an alignment. Options: :alignment, :float.
Examples
use Folio
place(image("logo.png"), alignment: "top + right", float: true)
@spec polygon( [{number(), number()}], keyword() ) :: Folio.Content.Polygon.t()
Polygon from coordinate list. Options: :fill, :stroke.
Examples
use Folio
polygon([{0, 0}, {50, 0}, {25, 40}], fill: "#aaaaff", stroke: "1pt")
@spec raw( String.t(), keyword() ) :: Folio.Content.Raw.t()
Raw/code text. Options: :lang, :block.
Examples
use Folio
raw("IO.puts("hello")", lang: "elixir")
raw("SELECT * FROM users", lang: "sql", block: true)
@spec raw_typst(String.t()) :: Folio.Content.RawTypst.t()
Raw Typst source injected directly.
raw_typst("#set text(hyphenate: false)\nHello")
@spec rect(keyword()) :: Folio.Content.Rect.t()
Rectangle. Options: :width, :height, :fill, :body.
Examples
use Folio
rect(width: "100pt", height: "50pt", fill: "#cccccc")
rect(width: "4cm", body: text("inside"))
@spec ref(String.t(), nil | Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Ref.t()
Reference a labelled element.
Examples
use Folio
ref("intro")
ref("fig:chart", "Figure")
@spec repeat(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Repeat.t()
Repeat content to fill available space.
Examples
use Folio
repeat(text("."))
@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.
Examples
use Folio
smallcaps("Section Title")
@spec square(keyword()) :: Folio.Content.Square.t()
Square. Options: :size, :fill, :body.
Examples
use Folio
square(size: "40pt", fill: "#0055bb")
@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.
Examples
use Folio
strike("deleted")
@spec strong(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Strong.t()
Bold text.
Examples
use Folio
strong("important")
strong([text("also "), emph("works")])
@spec subscript(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Sub.t()
Subscript text.
Examples
use Folio
[text("H"), subscript("2"), text("O")]
@spec superscript(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Super.t()
Superscript text.
Examples
use Folio
[text("x"), superscript("2")]
@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.
Examples
use Folio
table(columns: ["1fr", "1fr"],
do: [
table_header(["Name", "Score"]),
table_row(["Alice", "95"]),
table_row(["Bob", "87"])
])
@spec table_cell( Folio.Content.t() | [Folio.Content.t()] | String.t(), keyword() ) :: Folio.Content.TableCell.t()
Create a table cell. Options: :colspan, :rowspan, :align.
Examples
use Folio
table_cell("plain cell")
table_cell(strong("header"), colspan: 2, align: "center")
@spec table_header([Folio.Content.t() | String.t()]) :: Folio.Content.TableHeader.t()
Create a table header row from a list of cell contents.
Examples
use Folio
table_header(["Name", "Age", "City"])
@spec table_row([Folio.Content.t() | String.t()]) :: Folio.Content.TableRow.t()
Create a table data row from a list of cell contents.
Examples
use Folio
table_row(["Alice", "30", "London"])
@spec term_item(term(), term()) :: Folio.Content.TermItem.t()
Single term item.
Examples
use Folio
term_item("Folio", "A PDF library for Elixir.")
@spec term_list( [{term(), term()}], keyword() ) :: Folio.Content.TermList.t()
Definition list from {term, description} tuples. Options: :tight.
Examples
use Folio
term_list([
{"Elixir", "A functional language."},
{"Typst", "A modern typesetting system."}
])
@spec text( String.t(), keyword() ) :: Folio.Content.Text.t()
Create a text node. Options: :size, :weight, :fill, :tracking.
Examples
use Folio
text("Hello, world!")
text("Big", size: "24pt", weight: "bold", fill: "#ff0000")
@spec title(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Title.t()
Document title.
Examples
use Folio
title("My Report")
title([strong("Folio"), text(" — PDF Library")])
@spec underline(Folio.Content.t() | [Folio.Content.t()] | String.t()) :: Folio.Content.Underline.t()
Underlined text.
Examples
use Folio
underline("underlined")
@spec vspace( String.t() | number(), keyword() ) :: Folio.Content.VSpace.t()
Vertical spacing. Options: :weak.
Examples
use Folio
vspace("1em")
vspace("2pt", weak: true)