Remove line breaks from path and do not allow search option for protocol links.
This commit is contained in:
parent
aa253c38dd
commit
d987b9b75b
@ -3024,7 +3024,7 @@ fn compare_angle_link<'b, 's>(
|
||||
),
|
||||
(
|
||||
EmacsField::Required(":path"),
|
||||
|r| Some(r.path),
|
||||
|r| Some(r.get_path()),
|
||||
compare_property_quoted_string
|
||||
),
|
||||
(
|
||||
|
@ -138,16 +138,13 @@ fn parse_protocol_angle_link<'b, 'g, 'r, 's>(
|
||||
tuple((parser_with_context!(protocol)(context), tag(":"))),
|
||||
|(protocol, _)| LinkType::Protocol(protocol.into()),
|
||||
)(input)?;
|
||||
let (remaining, path) = alt((take_until("::"), rest))(remaining)?;
|
||||
let (remaining, search_option) = opt(map(tuple((tag("::"), rest)), |(_, search_option)| {
|
||||
search_option
|
||||
}))(remaining)?;
|
||||
let (remaining, path) = rest(remaining)?;
|
||||
Ok((
|
||||
remaining,
|
||||
PathAngle {
|
||||
link_type,
|
||||
path: path.into(),
|
||||
search_option: search_option.map(Into::<&str>::into),
|
||||
search_option: None,
|
||||
application: None,
|
||||
},
|
||||
))
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user