shiroa

Typst Support - Content Helpers

These helpers convert semantic Typst content into values suitable for page metadata and themes. Cross-target links are documented separately in Cross Reference.

plain-textplain-text

plain-text(it, limit: none)plain-text(it, limit: none) recursively extracts a plain-text representation from Typst content. Images contribute their alternative text; line and paragraph breaks are preserved; formatting is removed. limitlimit counts Unicode grapheme clusters rather than bytes.

#import "@preview/shiroa:0.4.0": plain-text
#let description = plain-text([
A *formatted* introduction with $x^2$.
], limit: 160).trim()
#import "@preview/shiroa:0.4.0": plain-text
#let description = plain-text([
A *formatted* introduction with $x^2$.
], limit: 160).trim()

prepare-descriptionprepare-description

#import "@preview/shiroa:0.4.0": prepare-description
#assert(prepare-description(none) == none)
#assert(
prepare-description(auto, plain-body: [Hello]) == "Hello",
)
#import "@preview/shiroa:0.4.0": prepare-description
#assert(prepare-description(none) == none)
#assert(
prepare-description(auto, plain-body: [Hello]) == "Hello",
)

Normalizes a page description for a theme:

  • nonenone disables the description.
  • A string is returned unchanged.
  • autoauto extracts and trims plain-bodyplain-body, truncating it to limitlimit clusters and appending ...... when the limit is reached.