Skip to main content

Module inline_ir

Module inline_ir 

Source
Expand description

Inline IR for both CommonMark and Pandoc dialects.

The inline parsing pipeline runs in three passes over an intermediate representation (IR):

  1. Scan (build_ir): walk the source bytes once, producing a flat Vec<IrEvent>. Opaque higher-precedence constructs (escapes, code spans, autolinks, raw HTML, plus Pandoc math / native spans / inline footnotes / footnote references / citations / bracketed spans) are skipped past as a single IrEvent::Construct event whose source range is preserved for losslessness. Delimiter runs (*/_), bracket markers ([, ![, ]), soft line breaks, and plain text spans become distinct events.

  2. Process brackets (process_brackets) — CommonMark §6.3: the bracket-stack algorithm walks ] markers left-to-right. For each ], the algorithm finds the nearest active opener and tries to resolve the pair as a link or image: inline [text](dest), full reference [text][label], collapsed [text][], or shortcut [text]. Under CommonMark, reference forms are validated against the document refdef map and a successful match deactivates all earlier active openers (§6.3 “links may not contain other links”). Under Pandoc, reference forms resolve shape-only (any non-empty label) and the deactivation pass is skipped; outer-wins nested-link semantics are enforced by the emission walk’s suppress_inner_links flag instead.

  3. Process emphasis (process_emphasis_in_range): the classic delimiter-stack algorithm runs over the IrEvent::DelimRun events, pairing openers with closers and recording matches on the runs. Runs first scoped per resolved bracket pair (innermost first), then a top-level pass over the residual events. Each match consumes 1 or 2 inner-edge bytes from each side; leftover bytes fall through to literal text. Dialect gates (Pandoc flanking rules, mod-3 rejection, asymmetric (1,2)/(2,1) rejection, opener-count >= 4 rejection, triple-emph nesting flip, cascade-then-rerun) branch on the dialect parameter.

The emission walk in [super::core::parse_inline_range_impl] consumes three byte-keyed plans built by build_full_plans: an EmphasisPlan for delim-run dispositions, a BracketPlan for resolved link/image bracket pairs, and a ConstructPlan for standalone Pandoc constructs (inline footnotes, native spans, footnote references, citations, bracketed spans). Matched delim runs become EMPHASIS / STRONG nodes; matched bracket pairs become LINK / IMAGE nodes via the dispatcher’s try_parse_* recognizers (called to parse a matched range, not to resolve it). Unmatched delims and brackets fall through to plain text.

Structs§

BracketPlan
A byte-keyed view of the IR’s bracket resolutions.
BracketResolution
Successful bracket resolution: the [] pair is a link or image.
ConstructPlan
A byte-keyed view of the IR’s standalone Pandoc constructs that the emission walk consumes directly: inline footnotes, native spans, footnote references, bracketed citations, bare citations, and bracketed spans. Recognition is authoritative in build_ir under Dialect::Pandoc; the dispatcher’s legacy branches for these constructs (^[, <span>, [^id], [@cite], @cite / -@cite, [text]{attrs}) are gated to Dialect::CommonMark only and only fire when the relevant extension is explicitly enabled.
DelimMatch
One matched fragment within a IrEvent::DelimRun.
EmphasisPlan
Byte-keyed disposition map for * / _ delimiter chars produced by the IR’s emphasis pass and consumed by the inline emission walk.
InlinePlans
Bundle of plans produced by build_full_plans and consumed by the inline emission walk.
UnresolvedRefShape
Pandoc-only: extents of an unresolved bracket-shape reference pattern. Recorded on IrEvent::OpenBracket.unresolved_ref when the no-resolution fall-through fires under Dialect::Pandoc.

Enums§

BracketDispo
Disposition of a single bracket byte after process_brackets.
ConstructDispo
A standalone Pandoc inline construct recognised by build_ir and dispatched directly from the emission walk. Carries the construct’s full source range so the emission walk can slice the content for the existing emit_* helpers without re-running the recognition.
ConstructKind
Categorical tag for a IrEvent::Construct event so emission knows which parser to call to rebuild the CST subtree.
DelimChar
Disposition of a single delimiter byte after emphasis resolution.
EmphasisKind
IrEvent
One event in the inline IR.
LinkKind
What kind of link/image we resolved a bracket pair to.

Functions§

build_bracket_plan
Build a BracketPlan from the resolved IR. Each OpenBracket resolution becomes an BracketDispo::Open keyed at the opener’s start byte. Unresolved openers and unmatched closers become BracketDispo::Literal so the emission path can recognise them without re-parsing.
build_construct_plan
Build a ConstructPlan from the resolved IR. Each Construct { kind: InlineFootnote | NativeSpan, .. } becomes one entry keyed at its start byte.
build_emphasis_plan
Convert the IR’s delim-run match decisions into an EmphasisPlan, preserving the byte-keyed disposition shape the existing emission walk consumes.
build_full_plans
One-shot helper: build the IR, run all passes, and return the bundled InlinePlans (emphasis dispositions, bracket resolutions, and standalone Pandoc constructs) — packaged together so the inline emission path can consume them in one go for either dialect.
build_ir
Scan text[start..end] once, producing a flat IR of events.
process_brackets
Resolve [/![/] markers into link/image nodes per CommonMark §6.3 (with Pandoc-aware variations under Dialect::Pandoc).
process_emphasis
Run the CommonMark §6.3 process_emphasis algorithm over the IR’s delim runs. Mutates the IR in place: matched runs gain entries in their matches vec, unmatched bytes stay implicit (the emission pass treats any byte not covered by a match as literal text).
process_emphasis_in_range
Range-scoped variant of process_emphasis.