Pass 1: Block Parser #
CommonMark is parsed in two passes:
- The first pass identifies the block structure of the document and accumulates the definitions of ref-style links.
- Within each block, the second pass finds the structure of inlines and applies fallback rules for poorly nested or mismatched delimiters.
This file contains the first pass. Ref-style link labels are compared modulo normalizeLabel, whose
case folding covers only ASCII, Latin-1, and Greek, rather than the full Unicode case fold specified
by CommonMark.
Processing Lines #
Lines are processed one at a time. A kind of rightward-only zipper is maintained, allowing blocks to be added at the lower right of the syntax tree.
Each step of the pipeline is a ProcessM Unit that is named after its description in the CommonMark
spec. Steps that produce the line's final zipper end the pipeline with finishLine, while steps
that only mutate the in-flight state fall through to the next.
A state that is read with get is shared with the monad, so extending one of the zipper's arrays
would copy the array. The zipper should be changed only either inside modify or after takeState
has taken the state out of the monad.
Builds the document's reference table from its link reference definitions and from externalRefs,
which maps labels to definitions that the caller supplies.
An earlier definition of a label in the document takes precedence over a later one. A definition in
the document takes precedence over an external one with the same label unless the external one has
overrideDocument set.
The labels of externalRefs are normalized like those in the document. When several of them
normalize to the same label, the definition of the lexicographically least of them is used.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Identifies the complete block structure of s. Up to indent leading spaces of each line are
skipped.
Equations
- Lean.Markdown.parseBlocks s indent = Lean.Markdown.postProcessRefDefs✝ (Lean.Markdown.parseBlocksRaw✝ s indent)