Skip to main content

Module core

Module core 

Source
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

  1. Parse text left-to-right
  2. When we see delimiters, try to parse emphasis (look for matching closer)
  3. If successful, emit emphasis node and continue from after closer
  4. If failed (no closer found), emit delimiter as literal and continue
  5. 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 *foo as 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.