Handle orgifying text in regular link path and raw-link.
This commit is contained in:
@@ -648,3 +648,45 @@ pub enum LinkType<'s> {
|
||||
CodeRef,
|
||||
Fuzzy,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ParserState {
|
||||
Normal,
|
||||
InWhitespace,
|
||||
}
|
||||
|
||||
/// Org-mode treats multiple consecutive whitespace characters as a single space. This function performs that transformation.
|
||||
///
|
||||
/// Example: `orgify_text("foo \t\n bar") == "foo bar"`
|
||||
pub(crate) fn orgify_text<'s>(raw_text: &'s str) -> String {
|
||||
let mut ret = String::with_capacity(raw_text.len());
|
||||
let mut state = ParserState::Normal;
|
||||
for c in raw_text.chars() {
|
||||
state = match (&state, c) {
|
||||
(ParserState::Normal, _) if " \t\r\n".contains(c) => {
|
||||
ret.push(' ');
|
||||
ParserState::InWhitespace
|
||||
}
|
||||
(ParserState::InWhitespace, _) if " \t\r\n".contains(c) => ParserState::InWhitespace,
|
||||
(ParserState::Normal, _) => {
|
||||
ret.push(c);
|
||||
ParserState::Normal
|
||||
}
|
||||
(ParserState::InWhitespace, _) => {
|
||||
ret.push(c);
|
||||
ParserState::Normal
|
||||
}
|
||||
};
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
impl<'s> RegularLink<'s> {
|
||||
pub fn get_raw_link(&self) -> String {
|
||||
orgify_text(self.raw_link)
|
||||
}
|
||||
|
||||
pub fn get_path(&self) -> String {
|
||||
orgify_text(self.path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user