Skip to main content

try_parse_emphasis

Function try_parse_emphasis 

Source
pub fn try_parse_emphasis(
    text: &str,
    pos: usize,
    end: usize,
    config: &Config,
    builder: &mut GreenNodeBuilder<'_>,
) -> Option<(usize, usize)>
Expand description

Try to parse emphasis starting at the given position.

This is the entry point for recursive emphasis parsing, equivalent to Pandoc’s enclosure function.

Returns Some((bytes_consumed, delim_count)) if emphasis was successfully parsed, or None if the delimiter should be treated as literal text. When returning None, the delim_count tells the caller how many delimiter characters to skip (to avoid re-parsing parts of a failed delimiter run).

§Arguments

  • text - The full text being parsed
  • pos - Current position in text (where the delimiter starts)
  • end - End boundary (don’t search for closers beyond this)
  • config - Configuration
  • builder - CST builder

Algorithm:

  1. Count opening delimiters
  2. Check if followed by whitespace (if so, return None)
  3. Dispatch to parse_one/two/three based on count
  4. Those functions parse content and look for matching closer (within bounds)
  5. If closer found, emit node and return bytes consumed
  6. If not found, return None with delimiter count (caller skips entire run)