mirror of
https://github.com/YGGverse/flarumdown.git
synced 2026-03-31 08:45:28 +00:00
This commit is contained in:
parent
a68a4fdde9
commit
e3dfaeee71
1 changed files with 21 additions and 9 deletions
26
src/main.rs
26
src/main.rs
|
|
@ -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!(
|
||||||
"",
|
"",
|
||||||
c.get(1).map(|s| s.as_str()).unwrap_or_default()
|
c.get(1).map(|s| s.as_str()).unwrap_or_default()
|
||||||
)
|
)
|
||||||
}),
|
})
|
||||||
))
|
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue