Expand description
limu reads Mermaid diagrams and lays them out, for programs that draw them themselves: in a window, in a terminal, as SVG.
A diagram goes through three stages. Parsing reads the diagram’s text into a model of it. Layout places the model’s parts, measuring text with a measurer the host gives, into a scene, which says what each part is and where it is, but not how it looks. A backend draws the scene, settling its colors from a style’s look. Style is not layout, so a scene is drawn in any theme without being laid out again.
Much of limu is ported from Pele, the Mermaid renderer of the Obsidian team, and its tests compare what limu does with what Pele does, number for number.
Re-exports§
pub use limu_scene as scene;
Modules§
- layout
- What a layout takes besides the diagram: what changes where things are. A change of these lays a diagram out again, where a change of style does not.
- roles
- The roles of the items limu lays out, by the diagram they are of, as “flowchart.node”. A
host styles items by role, keying
Look::overridesby these names, and a host that draws items its own way tells them apart by role, as an item’sRoleequals the name it has.
Structs§
- Diagram
- A diagram’s text read into a model, ready to be laid out. Laying it out changes neither its model nor its configuration, so one diagram may be laid out many times, with other options, and from many threads at once. A host that lays a diagram out again when its width changes parses it once.
- Error
- An error in a diagram’s text, as Pele’s PeleError is.
- Map
- An object’s keys and values, in the order JavaScript gives an object’s keys: those that are array indices, “0” to “4294967294” written without leading zeros, in numeric order, and then the rest in the order they were first set.
- Parse
Options - What a diagram’s text is read with, as Pele’s ParseOptions has it.
Enums§
- Diagram
Type - A type of diagram, as Pele names it.
- Error
Code - What kind of error an
Erroris, as Pele’s PeleErrorCode says. - Value
- A value of a diagram’s configuration: one of JSON’s kinds of value, as JavaScript holds it once JSON.parse or a YAML reader has read it.
Constants§
- DEFAULT_
LIMIT - The most UTF-16 code units a diagram’s text may have by default, Mermaid’s maxTextSize. It is how long the text may be, counted as JavaScript counts a string’s length.
- DEFAULT_
MAX_ EDGES - The most edges a flowchart or an agent flow may have by default. Mermaid stops at 500.
Pele draws 5,000 in tens of milliseconds, and
A & B --> C & Dmultiplies, so that without a limit a few kilobytes of text ask for millions of edges.
Functions§
- layout
- Reads a diagram’s text and lays it out as a scene, for a backend to draw:
parsewith the default limits and no configuration of the host’s, and thenDiagram::layout. Its errors are theirs. - parse
- Reads a diagram’s text, as Pele’s parse does: its front matter and directives, its type,
and then its body, with the parser of its type. The options hold the limits the text is
held to and the configuration beneath its own. What changes where things are is given to
Diagram::layout. Its errors are text of no type limu reads, text it cannot parse, and text past a limit. An error found once the type is known holds it, as Pele’s tagErrors gives it, and so do the errors of layout. - supports
- Whether limu reads the type of diagram a text is, as Pele’s supports says: its type is found, and it is one limu reads. Text whose front matter does not read is not supported. It does not parse the diagram, which may still be in error.
- types
- The types of diagram limu reads, in the order Pele’s registry lists them. Each is a feature of the crate, and only those it is built with are here.