pub fn process_brackets(
events: &mut [IrEvent],
text: &str,
refdefs: Option<&RefdefMap>,
dialect: Dialect,
)Expand description
Resolve [/![/] markers into link/image nodes per CommonMark §6.3
(with Pandoc-aware variations under Dialect::Pandoc).
Walks the IR forward looking for ] markers. For each one, finds the
nearest active matching [/or[text](dest "title"). - Full reference:
[text][label], wherelabelis inrefdefs. - Collapsed reference:
[text][], wheretext(normalised) is inrefdefs. - Shortcut reference:
[text]not followed by(or[, wheretext(normalised) is inrefdefs.
On a match, the opener gets a BracketResolution and the closer is
flagged matched. Under Dialect::CommonMark, all earlier active link
openers are deactivated to implement the §6.3 “links may not contain
other links” rule (image brackets do not deactivate earlier link
openers — only links do). Under Dialect::Pandoc, the deactivate-pass
is skipped: pandoc-native is outer-wins for nested links (the inner
[inner](u2) of [link [inner](u2)](u1) is literal text inside the
outer link), and the dispatcher enforces this via a suppress_inner_links
flag during LINK-text recursion. So under Pandoc the IR can leave both
outer and inner resolved and trust the dispatcher to suppress inner
LINK emission.
On a miss the bracket pair stays opaque-as-literal and the closer is
dropped from the bracket stack so the next ] can re-pair.
Reference-form resolution consults the refdef map under both
dialects (CommonMark §6.3 and Pandoc-markdown agree on the
document-scoped lookup rule). Under Pandoc, when a bracket-shape
pattern ([text][label], [text][], [text]) doesn’t resolve to
a refdef, the opener is tagged with unresolved_ref = Some(...)
and the closer’s matched is set to true so that
build_bracket_plan emits a BracketDispo::UnresolvedReference
keyed at the opener. Emission then wraps [start, end) in an
UNRESOLVED_REFERENCE node — distinct from LINK — so downstream
tools (linter, LSP) can attach behavior to the bracket-shape
pattern without the parser having to lie about resolution.
Under CommonMark, no unresolved_ref is recorded; the
no-resolution fall-through behaves as today (opener deactivated,
brackets emit as literal text).