Skip to main content

Module emit

Module emit 

Source
Expand description

The LikeC4 emitter: a Model to the text of one .c4 file.

This is the only place LikeC4 syntax is produced. The facts it relies on were verified against the LikeC4 release the CLI pins, and the CLI’s likec4_ tests run every emitted shape through the real parser. Output is a pure function of the normalized model: same model, same bytes, on every platform.

Structs§

EmitOptions
How the file relates to the repo it describes.

Constants§

HEADER
The first line of every generated file. No version in it: a version would turn every asbuilt release into drift in every consumer.

Functions§

emit
The .c4 text for model. The model is normalized on a copy first, so the caller’s element order does not matter.
link_encode
A path as a LikeC4 link target, which is an unquoted URI: every byte outside the unreserved set and / is percent-encoded, so a space or a quote in a directory name cannot break the parse.
theme_color_name
The name of a themed kind’s color in the specification.
view_id
The base view id for an element: its sanitized id with _ for .. Two elements can share one (a.b_c and a_b.c); view_ids is where the later one gets its suffix.
view_ids
The generated view of every element with children, keyed by element id: the view name as the emitter declares it and as asbuilt render names the SVG. Where two ids collapse to one base name, the second and later take a numeric suffix in element order, so the names are stable for a normalized model (emit normalizes first; call this on the same model to get the same names).