Deduplicate tags and mentions
Use set to work on tags and mentions, allowing deduplication of them, and clearer code May also help with distinguishing tags and hashtags latter
This commit is contained in:
committed by
Baptiste Gelez
parent
83d6da29a5
commit
1689813df4
@@ -5,6 +5,7 @@ use rocket::{
|
||||
http::uri::Uri,
|
||||
response::{Redirect, Flash}
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// Remove non alphanumeric characters and CamelCase a string
|
||||
pub fn make_actor_id(name: String) -> String {
|
||||
@@ -29,7 +30,7 @@ enum State {
|
||||
}
|
||||
|
||||
/// Returns (HTML, mentions, hashtags)
|
||||
pub fn md_to_html(md: &str) -> (String, Vec<String>, Vec<String>) {
|
||||
pub fn md_to_html(md: &str) -> (String, HashSet<String>, HashSet<String>) {
|
||||
let parser = Parser::new_ext(md, Options::all());
|
||||
|
||||
let (parser, mentions, hashtags): (Vec<Vec<Event>>, Vec<Vec<String>>, Vec<Vec<String>>) = parser.map(|evt| match evt {
|
||||
@@ -129,8 +130,7 @@ pub fn md_to_html(md: &str) -> (String, Vec<String>, Vec<String>) {
|
||||
|
||||
let mut buf = String::new();
|
||||
html::push_html(&mut buf, parser);
|
||||
let hashtags = hashtags.collect();
|
||||
(buf, mentions.collect(), hashtags)
|
||||
(buf, mentions.collect(), hashtags.collect())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user