2.7 KiB
White Tiger
white-tiger is a gemtext parser.
Gemtext documents are split into lines. Each line has a type and an optional text component.
The following line types exist:
Line types
Text
Line starts with none of the below sigils.
No special formatting; content is verbatim.
Level 3 header
Line starts with ###
.
Level 2 header
Line starts with ##
.
Level 1 header
Line starts with #
.
List item
Line starts with *
.
No special element to start or end lists. List nesting is not permitted (no support).
Quote
Line starts with >
.
Preformat mode toggle
Line starts with ```
.
All lines following a preformat mode toggle are to be displayed verbatim, ie, no processing occurs and all subsequent content should be a contiguous text block (newlines should be considered part of the text component, not a line divider).
A subsequent line-beginning ```
ends preformat mode.
The text component of a preformat mode initiation line is the "alt text". The text component of a preformat mode termination line has no special significance to clients.
Link
Line starts with =>
.
The first block of non-whitespace text following the line type sigil is the target of the link. All subsequent text on the line, if present, is the display text.
Display text is optional.
Whitespace between the line type sigil and target is permitted but optional.
Whitespace between the target and display text is mandatory if the display text is present.
Abstract syntax list
The parser parses the file into an abstract syntax list. This data structure is a list of nodes.
Usually, each line of the parsed file will correspond to one node in the abstract syntax list. Preformat-mode content violates this rule.
Terminating newlines at the end of parsed file lines, ie line separators, are not represented in the text content of nodes. Software which assembles the abstract syntax list back into a discrete file should join the nodes using newline characters.
Node
A node is a data structure containing the following elements:
- Type (typeval)
- Text component (optional textval)
- Preformat (boolean)
Preformat calculation
The currently visited node should be marked "preformat" when:
current preformat mode | visited node type | preformat? |
---|---|---|
t | preformat | nil |
nil | preformat | t |
t | any other | t |
nil | any other | nil |
a := current preformat mode is t b := newly visited node is a PREFORMAT node
(not a and b) or (a and not b)