diff --git a/src/main.rs b/src/main.rs
index 28c5fc0..1f8ffdc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ use clap::Parser;
use config::Config;
use database::Database;
use html_to_markdown_rs::convert;
+use regex::Regex;
use std::{
collections::HashMap,
fs::{File, create_dir_all, remove_dir_all},
@@ -104,20 +105,23 @@ fn main() -> Result<()> {
file.write_all(
{
let mut page = Vec::new();
- page.push(format!("# {}", discussion.title));
+ page.push(format!("# {}\n", discussion.title.trim()));
page.push({
let mut content = Vec::new();
for post in discussion.posts {
content.push(format!(
- "_@{} / {}{}_",
+ "_@{} / {}{}_\n",
users.get(&post.user_id).unwrap().username,
post.created_at,
post.edited_at
.map(|edited_at| format!(" / {}", edited_at))
.unwrap_or_default()
));
- content.push("---".into());
- content.push(convert(strip_tags(&post.content).trim(), None)?)
+ content.push(post_format(&convert(
+ pre_format(&post.content).trim(),
+ None,
+ )?));
+ content.push("---\n".into())
}
content.join("\n")
});
@@ -130,9 +134,7 @@ fn main() -> Result<()> {
Ok(())
}
-fn strip_tags(data: &str) -> String {
- use regex::Regex;
-
+fn pre_format(data: &str) -> String {
let s = Regex::new(r"[^<]+").unwrap();
let e = Regex::new(r"[^<]+").unwrap();
@@ -147,3 +149,10 @@ fn strip_tags(data: &str) -> String {
.replace("", "")
.replace("", "")
}
+
+fn post_format(data: &str) -> String {
+ Regex::new(r"\n{3,}")
+ .unwrap()
+ .replace(data, "\n\n")
+ .to_string()
+}