Skip to main content

split_locator

Function split_locator 

Source
pub fn split_locator(target: &str) -> (&str, Option<&str>)
Expand description

Split a target into the part naming a document and its locator.

Splits at the first separator, so a locator may itself contain one. Two targets deliberately have no locator:

  • one with no # at all — the ordinary case;
  • one whose # is the first character (#3). That is a same-document reference, and reading it as a locator on an empty path would resolve the link to the containing directory — a silent retarget where doing nothing is correct.

Purely syntactic: callers that must not split an external URL’s fragment guard with Link::is_external first, as Link::locator does.

The cost of the convention is a document whose filename contains #, which can no longer be linked by path. That is the same trade every URL and Markdown implementation makes, and the character is rare in filenames where a locator is not.