diff --git a/cove/src/euph/highlight.rs b/cove/src/euph/highlight.rs index e69fd10..0e7fb56 100644 --- a/cove/src/euph/highlight.rs +++ b/cove/src/euph/highlight.rs @@ -138,8 +138,8 @@ pub fn apply_spans( let text = &content[range.start..range.end]; result = match span { - SpanType::Mention if exact => result.and_then(util::style_nick_exact(text, base)), - SpanType::Mention => result.and_then(util::style_nick(text, base)), + SpanType::Mention if exact => result.and_then(util::style_mention_exact(text, base)), + SpanType::Mention => result.and_then(util::style_mention(text, base)), SpanType::Room => result.then(text, base.blue().bold()), SpanType::Emoji if exact => result.then(text, base.magenta()), SpanType::Emoji => { diff --git a/cove/src/euph/util.rs b/cove/src/euph/util.rs index aff2192..c2928ab 100644 --- a/cove/src/euph/util.rs +++ b/cove/src/euph/util.rs @@ -55,3 +55,17 @@ pub fn style_nick(nick: &str, base: Style) -> Styled { pub fn style_nick_exact(nick: &str, base: Style) -> Styled { Styled::new(nick, nick_style(nick, base)) } + +pub fn style_mention(mention: &str, base: Style) -> Styled { + let nick = mention + .strip_prefix('@') + .expect("mention must start with @"); + Styled::new(EMOJI.replace(mention), nick_style(nick, base)) +} + +pub fn style_mention_exact(mention: &str, base: Style) -> Styled { + let nick = mention + .strip_prefix('@') + .expect("mention must start with @"); + Styled::new(mention, nick_style(nick, base)) +}