Skip to main content

sanitize_roxygen_links

Function sanitize_roxygen_links 

Source
fn sanitize_roxygen_links(s: &str, links: Neutralize) -> String
Expand description

Neutralize rustdoc intra-doc link syntax so prose is valid roxygen2 markdown.

rustdoc [Foo] / [Foo] / [text][target] are intra-doc links resolved against Rust items by cargo doc. roxygen2 (markdown on) reads the same [...] as an R \link{} to a help topic, which can’t resolve. We strip the link brackets down to the visible text (keeping any `code` span), while leaving genuine markdown links [text](url) — recognized by the ]( that follows — untouched. With Neutralize::AllLinks a roxygen2 link ([other_fn()]) is stripped too: the syntax is rustdoc’s as well, so a crate writing for roxygen2 opts out with ProseLinks::Keep. With Neutralize::RustdocOnly only a link whose target roxygen2 can never resolve is stripped (is_rustdoc_only_target); the rest stay as written.

rustdoc’s inline form [text](crate::x) is the one [text](...) that loses its link, under either scope: its destination is a rustdoc-only Rust path (inline_rustdoc_destination), which roxygen2 would render as a dead \href{}.