diff --git a/src/main.rs b/src/main.rs index 1dca899..8f81ee9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -263,21 +263,33 @@ fn cleanup(target: &PathBuf, keep: &HashSet) -> Result<()> { } fn pre_format(data: &str, uploads: &mut HashSet) -> String { - // * keep leading `\s+url` to skip the `thumbnail_url` match - const R: &str = r#"(?s)]*>[^<]*"#; - html_escape::decode_html_entities(&strip_tags::strip_tags( - &Regex::new(R).unwrap().replace_all(data, |c: &Captures| { - let rel = c[2].trim_start_matches("/").trim_start_matches("d/"); + let md = html_escape::decode_html_entities(&strip_tags::strip_tags( + &Regex::new( + // * keep leading `\s+url` to skip the `thumbnail_url` match + r#"(?s)]*>[^<]*"# + ) + .unwrap() + .replace_all(data, |c: &Captures| { + format!( + "![{}]({})", + c.get(1).map(|s| s.as_str()).unwrap_or_default(), + &c[2] + ) + }), + )).to_string(); + Regex::new(r#"!\[([^\]]*)\]\(([^)]+)\)"#) + .unwrap() + .replace_all(&md, |c: &Captures| { + let rel = c[2].trim_start_matches('/').trim_start_matches("d/"); if uploads.insert(rel.into()) { - debug!("Register upload from the thumb capture: `{rel}`") + debug!("Register FoF/upload entry to handle: `{rel}`") } format!( "![{}]({rel})", c.get(1).map(|s| s.as_str()).unwrap_or_default() ) - }), - )) - .into() + }) + .into() } fn post_format(data: &str) -> String {