wiki/org.lisp
Element model
A block-level piece of an Org document.
One wiki page: file keywords and a tree of headings.
An Org headline with its section and subheadings.
A bulleted or numbered list of LIST-ITEMs.
A #+begin_example block, kept verbatim.
A #+begin_src block with its language.
Inline objects. Plain text is represented by strings.
Emphasized text; VERBATIM and CODE hold one string child.
An Org bracket link.
Inline ... or ... math, or display
A light #ID reference to a figure: a hash and six capitals or digits.
The figure ID an inline object refers to, or NIL.
All headings in document that carry an ID, in document order.
The plain text of a list of inline objects, dropping markup.
Line utilities
When line begins a list item, return (values indent ordered-p body-start).
Return (values kind parameters) for a #+begin_KIND line.
Inline reader
Are the characters of string from start below end all hex digits? A
figure ID never is, so that #111517 in a stylesheet stays a colour.
If a #ID mention (six capitals or digits, not all of them hex digits)
begins at start, return the index after it.
If a ... link begins at start, return (values link end).
The description of a link may not itself contain a link, so a stray "]]" inside it cannot fool us here.
True while reading docstrings and comments as prose: there *name*
without spaces is a Lisp special variable and reads as code, not bold.
If an emphasis span begins at start, return (values emphasis end).
Read string into a list of strings and inline objects.
Block reader
The block reader works on a vector of lines and an index. Each reader function takes the lines and a start index and returns (values element next-index), or NIL when the construct does not begin there.
Read a plain list whose first item begins at line I.
Gather the item's lines: the first line's body, then every following line indented deeper than the bullet, allowing a blank line inside the item when more indented text follows.
Read the block beginning at line I, returning (values element next-index).
Read the section body lines (a vector) into a list of block elements.
Document reader
If a property drawer begins at line I, return (values alist next-index).
Read the vector lines of an Org file into a document.
File keywords come first; then the preamble section, then headings.
Read consecutive headings of level >= MIN-LEVEL starting at START; return (values headings next-index).
Read the Org file at pathname into a document.
A block-level piece of an Org document.
An open document and the context it was opened in.
An Org headline with its section and subheadings.
A run of prose; CHILDREN are inline objects.
A bulleted or numbered list of LIST-ITEMs.
One list item; CHILDREN are blocks, usually a paragraph.
A #+begin_example block, kept verbatim.
A #+begin_src block with its language.
A simple Org table without formulas.
Emphasized text; VERBATIM and CODE hold one string child.
An Org bracket link.
Inline $...$ or \(...\) math, or display \[...\] and $$...$$.
A light #ID reference to a figure: a hash and six capitals or digits.
((heading heading))((document document))((call tool-call) stream)(inlines)(function element)(document)Logical conjunction of tests and raw truth values.
Status words that turn a heading into a work mark; see index.org.
(line)(line)Logical disjunction of tests and raw truth values.
(string)(prefix string &key (start 0))Test whether one compatible scalar is at most another.
Addition over compatible quantities.
(line)(line)Test whether one compatible scalar is less than another.
(line)Test whether one compatible scalar is at least another.
(line)(line kind)(line)(string index)(string index)(string start end)Are the characters of STRING from START below END all hex digits? A figure ID never is, so that #111517 in a stylesheet stays a colour.
(string start)If a #ID mention (six capitals or digits, not all of them hex digits) begins at START, return the index after it.
Test whether two compatible scalars are equal.
Logical negation of one test or raw truth value.
(string start)(string)True while reading docstrings and comments as prose: there *name* without spaces is a Lisp special variable and reads as code, not bold.
(string start)(string start)If TeX math begins at START, return (values math end). Inline math is $...$ on one line with no space inside the dollars, or \(...\); display math is $$...$$ or \[...\].
Test whether one compatible scalar is greater than another.
(lines i)The minimum of compatible quantities.
(lines i)(string)(lines i)(lines)(lines i)Block readers tried in order; READ-PARAGRAPH always succeeds.
(lines i)(lines i)(line stars)(lines &key name pathname)(string &key name pathname)(pathname &key (name (pathname-name pathname)))
An Org-subset reader for the luv wiki.
The wiki pages are Org files, but they use a deliberately small and regular subset: a title keyword, headings with property drawers, paragraphs, plain and ordered lists, example and source blocks, simple tables, bracket links, the light #XYZ123 figure mention, and the six inline emphasis markers. This reader turns that subset into a tree of CLOS elements. It is not a general Org parser and does not try to be: anything it does not recognize is kept as paragraph text, so a page can never fail to build because of an unfamiliar construct.