Use the regex crate with lazy_static! to compile patterns once and replace_all to transform text.
use lazy_static::lazy_static;
use regex::Regex;
lazy_static! {
static ref EXTRA_SPACE: Regex = Regex::new("(?m)^ >").unwrap();
}
fn cleanup(input: String) -> String {
EXTRA_SPACE.replace_all(&input, ">").to_string()
}
This pattern matches a space after > at the start of a line and removes it, as seen in cleanup_blockquotes.rs.