move strip to utils

This commit is contained in:
VC
2023-11-07 18:43:15 +01:00
parent 5059abe685
commit 2804a8ab38
2 changed files with 18 additions and 18 deletions

View File

@@ -1,11 +1,24 @@
use dissolve::strip_html_tags;
use megalodon::entities::status::Tag;
use regex::Regex;
use std::error::Error;
pub fn strip_mastodon_tags(content: &mut String, tags: &Vec<Tag>) -> Result<(), Box<dyn Error>> {
pub fn strip_everything(content: &str, tags: &Vec<Tag>) -> Result<String, Box<dyn Error>> {
let mut res =
strip_html_tags(&content.replace("</p><p>", "\n\n").replace("<br />", "\n")).join("");
strip_mastodon_tags(&mut res, tags).unwrap();
res = res.trim_end_matches('\n').trim_end_matches(' ').to_string();
Ok(res)
}
fn strip_mastodon_tags(content: &mut String, tags: &Vec<Tag>) -> Result<(), Box<dyn Error>> {
for tag in tags {
let re = Regex::new(&format!("(?i)(#{} ?)", &tag.name))?;
*content = re.replace(content, "").to_string();
}
Ok(())
}