Skip to main content

Module inline

Module inline 

Source
Expand description

Pure, deterministic inline-markdown → TextSpan parser.

This converts an INLINE markdown string (emphasis within a single text block) into a Vec<TextSpan>, setting the per-span marks Zenith already supports. It is inline only — there is no block-level structure here (no headings, lists, tables, or paragraph splitting). It is intended to be invoked when a text node opts into data-format="markdown"; this module is just the parser.

§Supported syntax

MarkdownSpan mark set
**bold** / __bold__font_weight = Literal("700") (resolves to 700)
*italic* / _italic_italic = Some(true)
~~strike~~strikethrough = Some(true)
++underline++underline = Some(true)
==highlight==highlight = Literal("#fff59d") (marker yellow)
`code`code = Some(true) (RAW: no inner parsing)
[label](url)span(s) with link = Some(url); label parsed

§Rules

  • Plain text between marks becomes plain spans (no marks set).
  • Backslash escapes (\*, \_, \~, \=, \+, \`, \[, \], \\) emit the literal character, not a delimiter.
  • Marks may nest when they cleanly close in LIFO order, e.g. **_bold italic_** → one span with bold weight + italic.
  • A code span (`) is a RAW context: no other marks and no escapes are parsed inside it; its text is verbatim.
  • In [label](url), the label is parsed for inline marks (all carrying the link); the url is taken verbatim. A [ with no matching ](...) is literal text.
  • Flanking rule: a delimiter run only OPENS emphasis when immediately followed by a non-whitespace char, and only CLOSES when immediately preceded by a non-whitespace char (start/end of input count as whitespace). So a * b and a ** b are literal * / **.
  • Unmatched / dangling delimiters degrade to literal text AT THEIR ORIGINAL POSITION. The function is infallible: malformed markdown never errors and never drops or reorders input — concatenating the span texts reproduces the input minus exactly the characters consumed as MATCHED delimiters or escape backslashes.
  • Adjacent runs with identical mark sets are coalesced into one span.
  • Fully deterministic: same input → same Vec<TextSpan>.

Functions§

parse_inline_markdown
Parse an inline-markdown string into styled TextSpans.