mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-21 04:51:17 +02:00
move strip to utils
This commit is contained in:
15
src/utils.rs
15
src/utils.rs
@@ -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(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user