🌿 Twig - Typst written in Gleam 🌿

Package Version Hex Docs

A Gleam library for generating Typst documents. Inspired by Lustre, Twig lets you build Typst documents using typed Gleam functions with attributes and content, just like Typst’s own function model.

Installation

gleam add twig

Usage

import gleam/io
import twig
import twig/model
import twig/text

pub fn main() {
  twig.Sequence([
    model.heading([model.level(1)], [text.text("My Document")]),
    model.heading([model.level(2)], [text.text("Introduction")]),
    model.strong([], [text.text("Welcome to Twig. ")]),
    text.line_break(),
    model.bullet_list([model.marker(model.TextMarker("--"))], [
      text.text("Type safe"),
      model.strong([], [text.text("Fast")]),
      model.emph([], [text.text("Easy to use")]),
    ]),
  ])
  |> twig.render()
  |> io.println()
}

Which outputs valid Typst markup:

#heading(level: 1)[My Document]
#heading(level: 2)[Introduction]
#strong[Welcome to Twig. ]

#list(marker: [--])[Type safe][#strong[Fast]][#emph[Easy to use]]

Development

gleam test  # Run the tests
gleam docs build  # Build the documentation
Search Document