1. Input Alphabet
Let the input lines be: Each line is a tuple: where:- indicates if the line is empty
- is the leading space count
- is the raw text of the line
2. State Machine Definition
We modelRuleParagraph as a deterministic state machine:
States
- : initial line evaluation
- : scanning subsequent lines until termination
- : extract paragraph content and build tokens
- : final state
Initial State
Final State
State Variables
- : current line index
- : scanning index
- : current block context
- : flag indicating terminator hit
3. Transition Rules
3.1 Start State ()
At , reject if the line is empty: If: Then: Otherwise:3.2 Scan State ()
For , continue scanning while all conditions hold: Then: Otherwise if :3.3 Extract State ()
At , the machine:- the paragraph content:
- Builds the tokens:
- Open token:
paragraph_open - Inline token:
inlinewithcontent - Close token:
paragraph_close
4. Tabular Format
| Current State | Input / Condition | Next State | Output / Action | Transition |
|---|---|---|---|---|
| (Start) | (Done) | None | ||
| (Start) | (Scan) | Init next\_line = start\_line + 1; load ; set parent_type = Paragraph | ||
| (Scan) | (Extract) | End-of-block reached | ||
| (Scan) | (Extract) | Empty line terminates paragraph | ||
| (Scan) | (Extract) | Indent too deep → terminate paragraph | ||
| (Scan) | (Scan) | Blockquote quirk → skip line | ||
| (Scan) | (Extract) | Terminator rule fires | ||
| (Scan) | (Scan) | Normal continuation: advance to | ||
| (Extract) | — | (Done) | Extract text, trim, generate tokens | |
| (Done) | — | — | Restore parent_type, assign state.line, return true | — |
5. Image
