Skip to main content

exclude_code_spans

Function exclude_code_spans 

Source
pub fn exclude_code_spans(
    links: Vec<Wikilink>,
    code_spans: &[Range<usize>],
) -> Vec<Wikilink>
Expand description

Keep only the wikilinks in links whose span does not overlap any of code_spans — the code-awareness DESIGN §8 asks for: a [[…]] that is really code (inside a fenced/inline code span) must never be treated as a link.

Caveat: this only helps for a links list in which every real wikilink was already found as its own match. It cannot rescue a real [[…]] that parse_wikilinks’ greedy “next ]] wins” scan has already merged into one bogus match together with an unrelated [[ earlier in the same code span — by the time that happens, the real link was never emitted as a separate Wikilink to keep. scan_wikilinks avoids the problem at the source (it never lets a lexical scan cross a code span in the first place) and is what census/check/rename actually use; reach for this function only when you already have a trustworthy Vec<Wikilink> (e.g. from a segment scan_wikilinks itself produced) and just need the range check.