diff --git a/Cargo.lock b/Cargo.lock index a5a48de..2310fc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,6 +273,7 @@ dependencies = [ "chrono", "clap", "html-to-markdown-rs", + "regex", "rusqlite", ] diff --git a/Cargo.toml b/Cargo.toml index 35124cf..b998c67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ anyhow = "1.0.102" chrono = "0.4.44" clap = { version = "4.6.0", features = ["derive"] } html-to-markdown-rs = "2.28.2" +regex = "1.12.3" rusqlite = { version = "0.39.0", features = ["chrono"]} diff --git a/src/main.rs b/src/main.rs index 8b956be..51351fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,7 +109,7 @@ fn main() -> Result<()> { let mut content = Vec::new(); for post in discussion.posts { content.push(format!( - "@{} / {}{}", + "_@{} / {}{}_", users.get(&post.user_id).unwrap().username, post.created_at, post.edited_at @@ -117,7 +117,7 @@ fn main() -> Result<()> { .unwrap_or_default() )); content.push("---".into()); - content.push(convert(&post.content, None)?) + content.push(convert(&strip_tags(&post.content), None)?) } content.join("\n") }); @@ -129,3 +129,21 @@ fn main() -> Result<()> { Ok(()) } + +fn strip_tags(data: &str) -> String { + use regex::Regex; + + let s = Regex::new(r"[^<]+").unwrap(); + let e = Regex::new(r"[^<]+").unwrap(); + + e.replace_all(&s.replace_all(data, ""), "") + .replace("", "") + .replace("", "") + .replace("", "") + .replace(" url=", " href=") + .replace("", "") + .replace("", "") +}