Folio.DSL (Folio v0.2.3)

Copy Markdown View Source

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

align(alignment, content)

Align content. Accepts :left, :center, :right or string equivalents.

bibliography(sources, opts \\ [])

@spec bibliography(
  String.t() | [String.t()],
  keyword()
) :: Folio.Content.Bibliography.t()

Insert a bibliography listing.

bibliography("refs.bib", title: "References", style: "ieee")

block(opts \\ [], list)

@spec block(
  keyword(),
  [{:do, [Folio.Content.t()]}]
) :: Folio.Content.Block.t()

Block-level container. Options: :width, :height, :above, :below.

blockquote(content, opts \\ [])

@spec blockquote(
  Folio.Content.t() | [Folio.Content.t()] | String.t(),
  keyword()
) :: Folio.Content.Quote.t()

Block quote. Options: :block, :attribution.

circle(opts \\ [])

@spec circle(keyword()) :: Folio.Content.Circle.t()

Circle. Options: :radius, :fill, :body.

cite(key, opts \\ [])

@spec cite(
  String.t(),
  keyword()
) :: Folio.Content.Cite.t()

Cite a bibliography entry.

cite("knuth1984", form: "prose")

colbreak(opts \\ [])

@spec colbreak(keyword()) :: Folio.Content.Colbreak.t()

Force a column break. Options: :weak.

columns(count, opts \\ [], list)

@spec columns(pos_integer(), keyword(), [{:do, [Folio.Content.t()]}]) ::
  Folio.Content.Columns.t()

Flow content into count columns. Options: :gutter.

divider()

@spec divider() :: Folio.Content.Divider.t()

Horizontal divider.

ellipse(opts \\ [])

@spec ellipse(keyword()) :: Folio.Content.Ellipse.t()

Ellipse. Options: :width, :height, :fill, :body.

emph(content)

Italic text.

enum(items, opts \\ [])

@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

figure(content, opts \\ [])

Wrap content in a figure. Options: :caption, :placement ("top"/"bottom"), :scope, :numbering.

footnote(content)

Footnote.

grid(opts, list)

@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")])

grid_cell(content, opts \\ [])

Create a grid cell. Options: :colspan, :rowspan, :align, :fill.

heading(level, content)

@spec heading(1..6, Folio.Content.t() | [Folio.Content.t()] | String.t()) ::
  Folio.Content.Heading.t()

Create a heading (levels 1-6).

hide(content)

Hide content (invisible but takes space).

highlight(content, opts \\ [])

Highlighted text. Options: :fill color.

hspace(amount, opts \\ [])

@spec hspace(
  String.t() | number(),
  keyword()
) :: Folio.Content.HSpace.t()

Horizontal spacing. Options: :weak.

image(src, opts \\ [])

@spec image(
  String.t(),
  keyword()
) :: Folio.Content.Image.t()

Embed an image. Options: :width, :height, :fit ("contain"/"cover"/"stretch").

label(name)

@spec label(String.t()) :: Folio.Content.Label.t()

Label a position for cross-references.

line(opts \\ [])

@spec line(keyword()) :: Folio.Content.Line.t()

Line. Options: :start, :end, :length, :angle, :stroke.

linebreak()

@spec linebreak() :: Folio.Content.Linebreak.t()

Insert a line break.

link(url, text \\ nil)

@spec link(String.t(), nil | Folio.Content.t() | String.t()) :: Folio.Content.Link.t()

Hyperlink. Second argument is optional display text.

list(items, opts \\ [])

@spec list(
  [term()],
  keyword()
) :: Folio.Content.List.t()

Bullet list. Options: :tight, :marker.

local_set(opts, list)

@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")])

math(content, opts \\ [])

@spec math(
  String.t(),
  keyword()
) :: Folio.Content.Math.t()

Math expression in Typst syntax. Options: :block.

outline(opts \\ [])

@spec outline(keyword()) :: Folio.Content.Outline.t()

Table of contents. Options: :title, :indent, :depth.

pad(opts, list)

@spec pad(
  keyword(),
  [{:do, [Folio.Content.t()]}]
) :: Folio.Content.Pad.t()

Add padding around content. Options: :left, :right, :top, :bottom.

pagebreak(opts \\ [])

@spec pagebreak(keyword()) :: Folio.Content.Pagebreak.t()

Force a page break. Options: :weak.

parbreak()

@spec parbreak() :: Folio.Content.Parbreak.t()

Insert a paragraph break.

place(content, opts \\ [])

Place content at an alignment. Options: :alignment, :float.

polygon(vertices, opts \\ [])

@spec polygon(
  [{number(), number()}],
  keyword()
) :: Folio.Content.Polygon.t()

Polygon from coordinate list. Options: :fill, :stroke.

raw(text, opts \\ [])

@spec raw(
  String.t(),
  keyword()
) :: Folio.Content.Raw.t()

Raw/code text. Options: :lang, :block.

raw_typst(source)

@spec raw_typst(String.t()) :: Folio.Content.RawTypst.t()

Raw Typst source injected directly.

raw_typst("#set text(hyphenate: false)

Hello")

rect(opts \\ [])

@spec rect(keyword()) :: Folio.Content.Rect.t()

Rectangle. Options: :width, :height, :fill, :body.

ref(target, supplement \\ nil)

Reference a labelled element.

repeat(content)

Repeat content to fill available space.

show(target, transform)

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)

smallcaps(content)

Small capitals text.

square(opts \\ [])

@spec square(keyword()) :: Folio.Content.Square.t()

Square. Options: :size, :fill, :body.

stack(opts, list)

@spec stack(
  keyword(),
  [{:do, [Folio.Content.t()]}]
) :: Folio.Content.Stack.t()

Stack children in a direction. Options: :dir ("ttb"/"ltr"/"rtl"/"btt"), :spacing.

strike(content)

Strikethrough text.

strong(content)

Bold text.

subscript(content)

@spec subscript(Folio.Content.t() | [Folio.Content.t()] | String.t()) ::
  Folio.Content.Sub.t()

Subscript text.

superscript(content)

@spec superscript(Folio.Content.t() | [Folio.Content.t()] | String.t()) ::
  Folio.Content.Super.t()

Superscript text.

table(opts, list)

@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.

table_cell(content, opts \\ [])

Create a table cell. Options: :colspan, :rowspan, :align.

table_header(cells)

@spec table_header([Folio.Content.t() | String.t()]) :: Folio.Content.TableHeader.t()

Create a table header row from a list of cell contents.

table_row(cells)

@spec table_row([Folio.Content.t() | String.t()]) :: Folio.Content.TableRow.t()

Create a table data row from a list of cell contents.

term_item(term, description)

@spec term_item(term(), term()) :: Folio.Content.TermItem.t()

Single term item.

term_list(items, opts \\ [])

@spec term_list(
  [{term(), term()}],
  keyword()
) :: Folio.Content.TermList.t()

Definition list from {term, description} tuples. Options: :tight.

text(str)

@spec text(String.t()) :: Folio.Content.Text.t()

Create a text node.

title(content)

Document title.

underline(content)

Underlined text.

vspace(amount, opts \\ [])

@spec vspace(
  String.t() | number(),
  keyword()
) :: Folio.Content.VSpace.t()

Vertical spacing. Options: :weak.