Remove line breaks from path and do not allow search option for protocol links.
This commit is contained in:
@@ -732,3 +732,33 @@ impl<'s> RadioLink<'s> {
|
||||
self.path
|
||||
}
|
||||
}
|
||||
|
||||
enum PathState {
|
||||
Normal,
|
||||
HasLineBreak(String),
|
||||
}
|
||||
|
||||
impl<'s> AngleLink<'s> {
|
||||
/// Remove line breaks but preserve multiple consecutive spaces.
|
||||
pub fn get_path(&self) -> Cow<'s, str> {
|
||||
let mut state = PathState::Normal;
|
||||
for (offset, c) in self.path.char_indices() {
|
||||
match (&mut state, c) {
|
||||
(PathState::Normal, '\n') => {
|
||||
let mut ret = String::with_capacity(self.path.len());
|
||||
ret.push_str(&self.path[..offset]);
|
||||
state = PathState::HasLineBreak(ret);
|
||||
}
|
||||
(PathState::Normal, _) => {}
|
||||
(PathState::HasLineBreak(_), '\n') => {}
|
||||
(PathState::HasLineBreak(ret), _) => {
|
||||
ret.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
match state {
|
||||
PathState::Normal => Cow::Borrowed(self.path),
|
||||
PathState::HasLineBreak(ret) => Cow::Owned(ret),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user