Anonymous View
Documentation

yamlGo to source

Reads structured data from a YAML file.

The file must contain a valid YAML object or array. The YAML values will be converted into corresponding Typst values as listed in the table below.

The function returns a dictionary, an array or, depending on the YAML file, another YAML data type.

The YAML files in the example contain objects with authors as keys, each with a sequence of their own submapping with the keys “title” and “published”.

Example

#let bookshelf(contents) = {
  for (author, works) in contents {
    author
    for work in works [
      - #work.title (#work.published)
    ]
  }
}

#bookshelf(
  yaml("scifi-authors.yaml")
)

Conversion details

YAML valueConverted into Typst
null-values (null, ~ or empty )none
booleanbool
numberfloat or int
stringstr
sequencearray
mappingdictionary
Typst valueConverted into YAML
types that can be converted from YAMLcorresponding YAML value
bytesstring via repr
symbolstring
contenta mapping describing the content
other types (length, etc.)string via repr

Notes

Parameters

yaml(strpathbytes) → any

source
str or path or bytes
RequiredPositional
Question mark

A path to a YAML file or raw YAML bytes.

Definitions
Question mark

encodeGo to source

Encode structured data into a YAML string.

yaml.encode(any) → str

value
any
RequiredPositional
Question mark

Value to be encoded.