# Syntax `deft/stdext/syntax/` holds the Deft-language syntax highlighters and the registry that dispatches fenced code to them. Highlighting is widget-independent: every highlighter is a state machine that maps one source line to a per-character color vector, so the editor, the markdown viewer, chat, and the help app all render code the same way.
import "deft/stdext/syntax/registry" as hl-reg
import "deft/stdext/syntax/deft.syntax" as deft-syntax
import "deft/stdext/syntax/markdown.syntax" as hl-md
import "deft/stdext/syntax/zig.syntax" as zig-syntax
## The Registry | Def | Signature | Description | |---|---|---| | `register` | `{| lang hl-fn |}` | Register a language's `highlight-line` function | | `dispatch` | `{| lang line |}` | Highlight one line; `@{}` of per-char colors, or nil for unknown | | `reset` | `{| lang |}` | Reset a language's multi-line state (call before each fresh code block) | | `set-default-lang` / `default-lang` | `{| lang |}` / `{||}` | Default for empty fence tags | An empty language tag (an unlabeled fence) resolves to the default; with none set, `dispatch` returns nil and callers fall back to plain code colors.
[hl-reg/register "deft" deft-syntax/highlight-line]
[hl-reg/set-default-lang "deft"]

[hl-reg/reset "deft"]                          # before a fresh block
set colors [hl-reg/dispatch "deft" "set x 42"]
The registry stores function values, not modules, and has no unregister. ## The Standard Highlighter API All three highlighters share one contract: | Def | Signature | Description | |---|---|---| | `highlight-line` | `{| line |}` | `@{}` of hex color strings, one per character | | `set-theme-colors` | `{| colors |}` | Apply a theme `:syntax` map | | `reset-line-state` / `reset-state` | `{||}` | Clear cross-line state | | `get-line-state` / `set-line-state` | `{||}` / `{| state |}` | Save/restore state (string keys) for caching and scroll pre-scans | Cross-line state to thread through `get`/`set`: - deft — map-literal key/value expectation, compound-expression nesting, `#| … |#` block comments, backtick strings. - markdown — root vs fence state, fence language/depth, and list continuation coloring. On a fence open it delegates to the registered language via the injected `set-dispatch`/`set-reset` hooks so state from a previous block cannot bleed in. - zig — nested `/* … */` block-comment depth. ## Wiring `deft/editor/syntax-highlight` registers the built-ins and sets the default from editor config; the TUI markdown pipeline wires its fenced delegation with:
[hl-md/set-dispatch hl-reg/dispatch]
[hl-md/set-reset hl-reg/reset]
## See Also - Markdown — consumes highlighters through a `highlight-fn` - Themes — the `:syntax` color map - Editor app help — editor highlighting config