MMM: Profile field parsing and skipping Matrix handles
This commit is contained in:
parent
c6a282c26e
commit
f34be3a104
|
@ -635,6 +635,16 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_profile_fields(&self, input: &str) -> Token {
|
||||||
|
match self.inline_profile_fields(Span::new_extra(input, SpanMeta::default())) {
|
||||||
|
Ok((_, t)) => t.merged(),
|
||||||
|
Err(e) => {
|
||||||
|
trace!(input = input, "Profile field parser fail: {:?}", e);
|
||||||
|
Token::PlainText(e.to_compact_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial(
|
fn partial(
|
||||||
&self,
|
&self,
|
||||||
|
@ -666,6 +676,19 @@ impl Context {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn inline_profile_fields<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> {
|
||||||
|
map(
|
||||||
|
many1(alt((
|
||||||
|
self.partial(Self::unicode_emoji),
|
||||||
|
self.partial(Self::tag_mention),
|
||||||
|
self.partial(Self::tag_hashtag),
|
||||||
|
self.partial(Self::raw_url),
|
||||||
|
self.partial(Self::tag_raw_text),
|
||||||
|
))),
|
||||||
|
Token::Sequence,
|
||||||
|
)(input)
|
||||||
|
}
|
||||||
|
|
||||||
fn inline_ui<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> {
|
fn inline_ui<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> {
|
||||||
map(
|
map(
|
||||||
many1(alt((
|
many1(alt((
|
||||||
|
@ -1437,6 +1460,7 @@ impl Context {
|
||||||
return Ok((plain_out, Token::PlainText(plain.into())));
|
return Ok((plain_out, Token::PlainText(plain.into())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let start = input;
|
||||||
let tags = one_of("@!");
|
let tags = one_of("@!");
|
||||||
let (input, mention_type) = map(tags, |c| match c {
|
let (input, mention_type) = map(tags, |c| match c {
|
||||||
'@' => MentionType::User,
|
'@' => MentionType::User,
|
||||||
|
@ -1462,9 +1486,19 @@ impl Context {
|
||||||
)(input)?;
|
)(input)?;
|
||||||
|
|
||||||
let host = host.map(|h| h.trim_end_matches(|c| matches!(c, '.' | '-' | '_')));
|
let host = host.map(|h| h.trim_end_matches(|c| matches!(c, '.' | '-' | '_')));
|
||||||
|
let input = host.map(|c| before.slice(c.len() + 1..)).unwrap_or(before);
|
||||||
|
|
||||||
|
if let (input, Some(_)) =
|
||||||
|
peek(opt(tuple((recognize(tag(":")), alphanumeric1_unicode))))(input)?
|
||||||
|
{
|
||||||
|
return Ok((
|
||||||
|
input,
|
||||||
|
Token::PlainText(start.up_to(&input).into_fragment().into()),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
host.map(|c| before.slice(c.len() + 1..)).unwrap_or(before),
|
input,
|
||||||
Token::Mention {
|
Token::Mention {
|
||||||
mention_type,
|
mention_type,
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
|
@ -2145,6 +2179,11 @@ text</center>"#
|
||||||
Token::PlainText(" test".into())
|
Token::PlainText(" test".into())
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
parse_full("@tag:domain.com"),
|
||||||
|
Token::PlainText("@tag:domain.com".into())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue