Expand description
Recursive emphasis parsing using Pandoc’s algorithm.
This module implements emphasis/strong emphasis parsing using a recursive
descent approach based on Pandoc’s Haskell implementation in
Readers/Markdown.hs:L1662-L1722.
Key algorithm: Left-to-right, greedy, first-match wins
- Parse text left-to-right
- When we see delimiters, try to parse emphasis (look for matching closer)
- If successful, emit emphasis node and continue from after closer
- If failed (no closer found), emit delimiter as literal and continue
- Nested emphasis is handled naturally by recursive parsing of content
Example: *foo **bar* baz**
- See
*, try to parse EMPH - Parse content: see
**, try to parse STRONG - STRONG finds closer
**at end → succeeds, emits STRONG[bar* baz] - Outer
*can’t find closer (all delimiters consumed) → fails, emits*fooas literal - Result:
*foo+ STRONG[bar* baz]
This matches Pandoc’s behavior exactly.
Functions§
- parse_
inline_ text - Parse inline elements from text content. This is a standalone function used for recursive inline parsing within blocks.
- parse_
inline_ text_ recursive - Parse inline text using the recursive emphasis algorithm.
- try_
parse_ emphasis - Try to parse emphasis starting at the given position.