Reference

Expression language

Mantou ships a minimal expression language. It is powerful enough for conditional styling and intentionally too small to do anything unsafe.

Allowed#

  • Property access: node.on, node.parent.on, edge.from.status
  • Comparisons: == != > < >= <=
  • Booleans: && || !
  • Ternary: condition ? a : b
  • Literals: strings, numbers, booleans
  • Theme tokens: chili, cream, …
  • Array helpers: any(...) and all(...)

Examples#

mantou
node.on ? chili : cream
node.parent.on ? bamboo : cream
node.status == "running" ? chili : scallion
node.selected ? chili : node.parent.selected ? bamboo : cream
node.children.any(on) ? scallion : cream
node.descendants.any(status == "failed") ? danger : cream
edge.from.on && edge.to.on ? chili : bamboo

Array helpers#

any and all take a predicate evaluated against each element, where the element's fields are in scope. So node.children.any(on) is true when any child has on: true.

▲

Disallowed

No arbitrary JavaScript, function definitions, imports, loops, assignment, mutation, network or filesystem access, eval, or access to window, document, process, prototypes, or globals.