Source structure
modl source is read one line at a time. Every line stands on its own: there are no blocks, no brackets, and no line continuations.
Kinds of lines
After its comment is removed, each line is classified by the first rule that matches:
- Blank: nothing left but whitespace, so the line is ignored.
- Background: the whole line is exactly one unquoted color name, which sets the background color.
- Edge: the line contains
->anywhere outside quotes, so it declares one or more edges. - Node: anything else declares or updates a node.
# a comment line, then a blank line
teal # background
a square Start # node
a -> b # edge
Open in editor
Because rule 3 only looks for -> somewhere in the line, an unquoted node label that contains
-> turns the line into an edge line. Put such a label in quotes. See
Gotchas.
Comments
A # starts a comment in two situations:
- It is the first non-blank character of the line, so the whole line is a comment, even when indented.
- It follows whitespace (a space or tab), so the rest of the line is a comment.
A # directly after another character is ordinary text. That keeps URL fragments and names like
C# intact. A # inside quotes is always text.
# whole-line comment
# indented whole-line comment
a square Server A # trailing comment
lang square C# and F# # the # in C# and F# is text; this one starts a comment
docs /example.com/page#section Fragment links survive
bug square "Fix issue #42" # quoted, so the first # is text
Open in editor
Quoted strings
A word can be wrapped in double quotes "…" or single quotes '…'. Everything between the
quotes is one word, taken literally: spaces, -> and # are just characters, and the word is
never read as a size, shape, color or URL. The quotes themselves aren't part of the word.
a square "Input -> Output" # an arrow in a label
b square red "Issue #42" # a # in a label
c "big" data # a label starting with a reserved word
d "red" # a gray node labeled red
Open in editor
Ids can be quoted too, which lets them contain any characters. "a" and a are the same
node.
"example.com" square blue
"v1.2" -> "v1.3" upgrade
"example.com" -> "v1.2"
Open in editor
The rules for quotes:
- A string is closed by the next quote of the same kind, so double quotes can hold single quotes and single quotes can hold double quotes. There are no escape characters.
- A quote opens a string only at the start of a word, so apostrophes inside words, as in
Bob'sordon't, are ordinary characters. - A quote with no matching quote later on the line is an ordinary character too.
- A quoted string and the characters or strings directly next to it, with no space between, form one word. To
use both kinds of quote in one label, write two strings side by side:
"it's "'"fine"'is the wordit's "fine". - An empty string,
""or'', is an empty word. As text it clears a node's label (see Redefining nodes). As an id it is an error.
a "Bob's car"
b 'She said "hi"'
c Bob's car # mid-word apostrophe: plain text
d "it's "'"fine"'
Open in editor
Whitespace
- Words are separated by any run of spaces or tabs. Indentation and alignment don't matter.
- Spaces around
->are optional:a->banda -> bare the same. - Runs of whitespace between words of label text collapse to a single space. Whitespace inside quotes is kept.
- Blank lines are ignored. Both
\nand\r\nline endings work.
a->b
b -> c
c square lots of space
Open in editor
Line order
Lines can appear in any order. A node can be used in an edge before or after the line that styles it, and the result is the same:
a square red Alpha
b hex blue Beta
a -> b
Open in editor
a -> b
a square red Alpha
b hex blue Beta
Open in editor
Order matters in only two cases. When a node is declared more than once, later attributes override earlier ones (see Redefining nodes). When several background lines appear, the last one wins.
Background color
A line holding nothing but a color name (a trailing comment is fine) fills the canvas with that color. Without one, the editor's default dark backdrop shows through. Background colors are solid, unlike node fills, which are translucent.
black
a circle orange Sun
b circle blue Earth
a -> b yellow
Open in editor
white
a square blue Light theme
a -> b black
b circle black
Open in editor
red
blue
green # this one is used
a -> b
Open in editor
Color names are case-sensitive, so Red alone on a line is a node named Red, not a
background. All 12 colors are shown on Sizes, shapes, lines & colors.
Case sensitivity
Everything is case-sensitive. Web and web are different nodes, and only lowercase
reserved words are recognized. BIG or Circle are just label text.
web circle blue lowercase keywords work
Web Circle Blue capitalized ones are text
Open in editor
Errors
A line that can't be understood is listed in the editor's error box as Line N: …, counting
blank and comment lines. The rest of the diagram still draws. The possible messages are listed in the
grammar reference.
good -> fine
bad.id circle red # Line 2: invalid node id "bad.id"
fine square teal Still drawn
Open in editor