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 under Dialect::Pandoc is shape-only: any
non-empty link text or label resolves regardless of refdef presence,
matching the historical legacy reference_resolves-returns-true
behavior. (Pandoc emits LINK nodes for unresolved shortcut/collapsed/
full-reference shapes so downstream features — linter, LSP, formatter
— have a typed wrapper to walk. Refdef-aware resolution under Pandoc
is bug #1/#2 territory and is a parser-linter-LSP cross-cut deferred
to a future workstream.)