Diagnostics

Alongside built-in link, anchor, and schema checks, you can emit custom diagnostics during Typst evaluation using report(...) from @tola/diagnostic:0.0.0. Unlike panic(...), report(...) records an issue and continues so one build collects every violation across the site.

Metadata checks

Run cross-field or editorial rules during page selection or rendering (description length, missing fields, missing translations):

typst
#import "@tola/diagnostic:0.0.0": report

#let check-page-meta(page) = {
  let desc = page.meta.description
  if desc == "" {
    report(
      "Page \"" + page.meta.title + "\" is missing `description`.",
      severity: "warning",
      code: "site.missing-description",
      at: none,
      hints: ("Add `description` in `tola-meta` for " + page.path + ".",),
    )
  } else if desc.clusters().len() > 160 {
    report(
      "Description on \"" + page.meta.title + "\" exceeds 160 characters.",
      severity: "info",
      code: "site.long-description",
      at: none,
    )
  }
}

severity accepts "error", "warning" (default), "info", and "hint". Any "error" fails tola check and tola build after evaluation finishes; lower severities display diagnostics without aborting builds.

Element locations

Call report(..., at: el) inside article show rules to point diagnostics directly to the source line and column—such as checking missing alt text on images or flagging insecure http:// links:

typst
#import "@tola/diagnostic:0.0.0": report

#let lint-content(body) = {
  show image: img => {
    if img.alt == none or img.alt.trim() == "" {
      report(
        "Image is missing alt text.",
        severity: "warning",
        code: "site.image-alt",
        at: img,
        hints: ("Provide `image(..., alt: \"...\")` for accessibility and search.",),
      )
    }
    img
  }

  show link: it => {
    if type(it.dest) == str and it.dest.starts-with("http://") {
      report(
        "External link uses plain http://: " + it.dest,
        severity: "warning",
        code: "site.insecure-link",
        at: it,
        hints: ("Prefer https:// when supported.",),
      )
    }
    it
  }

  body
}

When an error spans two locations (such as duplicate glossary keys or custom IDs), attach the prior site with related:

typst
#report(
  "Duplicate glossary key",
  severity: "error",
  code: "site.duplicate-term",
  at: second-el,
  related: ((message: "First defined here", at: first-el),),
)

Diagnostic codes

Assigning stable code identifiers (such as "site.image-alt") keeps terminal output clear and lets CI inspect or filter results from tola check --json --pretty.

For submitting diagnostics from Nushell hooks and external processes, see Hooks for all arguments to report(...), see @tola/diagnostic.

Search this site

Use the arrow keys to move through results.

Type to search.