Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

yaml

YAML syntax highlighter. Pure (text) -> { Segment }. Mirrors the algorithm of the deleted Rust highlight_yaml / highlight_yaml_content / highlight_yaml_scalar trio (renderer.rs): per-line comment splitting, key: value recognition (split on first :), and scalar typing (quoted string / true|false|null / numeric / plain). Colors flow from ui.getToken("code.<role>") via the active theme; hardcoded fallbacks match the deleted Rust values when no theme is active.

Exports

  • highlight(text: string) -> { Segment } — tokenize a YAML string into colored segments for the zui code renderer. The module returns this function directly.

Types:

  • Segment = { text: string, color: string, monospace: boolean }

Usage

local highlight = require("@builtin::modules.zui.highlight.yaml")
local segments  = highlight("name: zero\n# comment\n")

Notes

  • The module-level color upvalues are reassigned at every highlighter entry so the inner scalar/content helpers see the active palette without per-call args. Multiple concurrent calls are NOT safe — this module is designed for serial UI rendering.
  • Numeric detection allows ., -, + alongside digits, so dotted versions and negatives parse as numbers (matches the Rust behaviour).