fix plain markdown images collector
Some checks are pending
Linux / build (push) Waiting to run

This commit is contained in:
yggverse 2026-03-30 13:26:32 +03:00
parent a68a4fdde9
commit e3dfaeee71

View file

@ -263,20 +263,32 @@ fn cleanup(target: &PathBuf, keep: &HashSet<PathBuf>) -> Result<()> {
} }
fn pre_format(data: &str, uploads: &mut HashSet<PathBuf>) -> String { fn pre_format(data: &str, uploads: &mut HashSet<PathBuf>) -> String {
let md = html_escape::decode_html_entities(&strip_tags::strip_tags(
&Regex::new(
// * keep leading `\s+url` to skip the `thumbnail_url` match // * keep leading `\s+url` to skip the `thumbnail_url` match
const R: &str = r#"(?s)<UPL-IMAGE-PREVIEW\s+alt="([^"]*)"\s+.*?\s+url="([^"]*)"\s+[^>]*>[^<]*</UPL-IMAGE-PREVIEW>"#; r#"(?s)<UPL-IMAGE-PREVIEW\s+alt="([^"]*)"\s+.*?\s+url="([^"]*)"\s+[^>]*>[^<]*</UPL-IMAGE-PREVIEW>"#
html_escape::decode_html_entities(&strip_tags::strip_tags( )
&Regex::new(R).unwrap().replace_all(data, |c: &Captures| { .unwrap()
let rel = c[2].trim_start_matches("/").trim_start_matches("d/"); .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()) { if uploads.insert(rel.into()) {
debug!("Register upload from the thumb capture: `{rel}`") debug!("Register FoF/upload entry to handle: `{rel}`")
} }
format!( format!(
"![{}]({rel})", "![{}]({rel})",
c.get(1).map(|s| s.as_str()).unwrap_or_default() c.get(1).map(|s| s.as_str()).unwrap_or_default()
) )
}), })
))
.into() .into()
} }