Skip to main content

quote_reference

Function quote_reference 

Source
pub fn quote_reference(reference: &str) -> String
Expand description

Writes one reference so that a parser reads it back as exactly this text, in the ID or value position of any link.

This is the function the formatter writes every reference with. Text that needs no delimiters is returned as it is; anything else is quoted, or written as a versioned literal when it is empty or holds a control character.

The answer is deliberately conservative, so the text also reads back with releases older than the one that made bare 12:30 and tag #release legal (issue #444): a colon, a whitespace character, a parenthesis, a quote, and a # that starts the text still ask for quotes.

ยงExamples

use links_notation::quote_reference;

assert_eq!(quote_reference("plain"), "plain");
assert_eq!(quote_reference("has space"), "'has space'");
assert_eq!(quote_reference("12:30"), "'12:30'");
assert_eq!(quote_reference("#release"), "'#release'");
assert_eq!(quote_reference(""), "~1{}");