mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-22 19:41:03 +00:00
parent
16124e890e
commit
6b58dcfda5
1 changed files with 8 additions and 2 deletions
|
@ -28,10 +28,15 @@ pub fn md_to_html(md: &str) -> (String, Vec<String>) {
|
|||
Event::Text(txt) => {
|
||||
let (evts, _, _, _, new_mentions) = txt.chars().fold((vec![], false, String::new(), 0, vec![]), |(mut events, in_mention, text_acc, n, mut mentions), c| {
|
||||
if in_mention {
|
||||
if (c.is_alphanumeric() || c == '@' || c == '.' || c == '-' || c == '_') && (n < (txt.chars().count() - 1)) {
|
||||
let char_matches = c.is_alphanumeric() || c == '@' || c == '.' || c == '-' || c == '_';
|
||||
if char_matches && (n < (txt.chars().count() - 1)) {
|
||||
(events, in_mention, text_acc + c.to_string().as_ref(), n + 1, mentions)
|
||||
} else {
|
||||
let mention = text_acc + c.to_string().as_ref();
|
||||
let mention = if char_matches {
|
||||
text_acc + c.to_string().as_ref()
|
||||
} else {
|
||||
text_acc
|
||||
};
|
||||
let short_mention = mention.clone();
|
||||
let short_mention = short_mention.splitn(1, '@').nth(0).unwrap_or("");
|
||||
let link = Tag::Link(format!("/@/{}/", mention).into(), short_mention.to_string().into());
|
||||
|
@ -84,6 +89,7 @@ mod tests {
|
|||
("mention at @end", vec!["end"]),
|
||||
("between parenthesis (@test)", vec!["test"]),
|
||||
("with some punctuation @test!", vec!["test"]),
|
||||
(" @spaces ", vec!["spaces"]),
|
||||
];
|
||||
|
||||
for (md, mentions) in tests {
|
||||
|
|
Loading…
Reference in a new issue