Development build 586e1bd4
Typst文档简体中文版v0.15.1 + dev 586e1bd4

yaml0.1.0起可用Go 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

参数
Question mark

yaml(strpathbytes) → any

source
str or path or bytes
必需参数
Question mark
位置参数
Question mark

A path to a YAML file or raw YAML bytes.

定义
Question mark

encode0.8.0起可用Go to source

Encode structured data into a YAML string.

yaml.encode(any) → str

value
any
必需参数
Question mark
位置参数
Question mark

Value to be encoded.