Format fixes

This commit is contained in:
Thomas Gideon 2024-04-09 15:24:19 -04:00
parent 70d5aa194b
commit 2edc3082d3

View file

@ -97,14 +97,19 @@ fn format_attachments(depth: usize, attachments: &[Attachment]) -> String {
// line, breaking the desired formatting // line, breaking the desired formatting
fn apply_block_quote<S: AsRef<str>>(depth: usize, content: S) -> String { fn apply_block_quote<S: AsRef<str>>(depth: usize, content: S) -> String {
let prefix = quote_prefix(depth); let prefix = quote_prefix(depth);
// TODO use OnceLock
let empty = Regex::new("\n\\s").expect("Failed to compiled regex for nested empty lines!"); let empty = Regex::new("\n\\s").expect("Failed to compiled regex for nested empty lines!");
let non_empty = let non_empty =
Regex::new("\n(?P<initial>[^>\\s])").expect("Failed to compile regex for nested lines!"); Regex::new("\n(?P<initial>[^>\\s])").expect("Failed to compile regex for nested lines!");
// TODO break into separate function
// parsing some multiline content adds paragraph tags, convert those back to new lines to apply // parsing some multiline content adds paragraph tags, convert those back to new lines to apply
// the block quote level to each line // the block quote level to each line
let content = content.as_ref().replace("</p><p>", "\n\n"); let content = content.as_ref().replace("</p><p>", "\n\n");
let content = content.replace("<p>", ""); let content = content.replace("<p>", "");
let content = content.replace("</p>", ""); let content = content.replace("</p>", "");
// TODO refactor into separate function
let content = content.replace("\\*", "*");
let content = content.replace(":totoro:", "\\:totoro\\:");
// replace separately to avoid trailing spaces when replacing empty lines with the prefix // replace separately to avoid trailing spaces when replacing empty lines with the prefix
let content = empty.replace_all(content.as_ref(), format!("\n{}\n", prefix.trim())); let content = empty.replace_all(content.as_ref(), format!("\n{}\n", prefix.trim()));
let content = non_empty.replace_all(&content, |c: &Captures| { let content = non_empty.replace_all(&content, |c: &Captures| {