Skip to main content

emphasis_can_pair

Function emphasis_can_pair 

Source
pub fn emphasis_can_pair(text: &str, delimiter: char) -> bool
Expand description

Whether the delimiter (* or _) characters of text can make emphasis among themselves: a run of them that can open (CommonMark §6.2: left-flanking, and for _ not inside a word) followed somewhere later by a run that can close.

text is a complete inline context — a table cell, a link label — so when no run can pair, every delimiter in it is read as itself and none needs escaping: the significance stars of 0.039***, a lone *8 ml. Without a later closer an opener opens nothing. The answer errs toward true: the rule of three (§6.2, rules 9–10) is not applied, so a pair it would forbid still counts as one.

use unparser_shared::markdown::emphasis_can_pair;

assert!(!emphasis_can_pair("0.039***", '*'));
assert!(!emphasis_can_pair("*8 ml", '*'));
assert!(emphasis_can_pair("x*y*z", '*'));
assert!(emphasis_can_pair("a _foo_ b", '_'));
assert!(!emphasis_can_pair("snake_case_name", '_'));