Support GIFs in comments (#217)
* Support GIFs in comments * Fix removing Giphy links so it only removes Giphy links * Remove removing link to Giphy
This commit is contained in:
parent
c1560f4eba
commit
97a0680bd0
18
src/utils.rs
18
src/utils.rs
@ -445,9 +445,21 @@ pub fn format_url(url: &str) -> String {
|
||||
}
|
||||
|
||||
// Rewrite Reddit links to Libreddit in body of text
|
||||
pub fn rewrite_urls(text: &str) -> String {
|
||||
match Regex::new(r#"href="(https|http|)://(www.|old.|np.|amp.|)(reddit).(com)/"#) {
|
||||
Ok(re) => re.replace_all(text, r#"href="/"#).to_string(),
|
||||
pub fn rewrite_urls(input_text: &str) -> String {
|
||||
let text1 = match Regex::new(r#"href="(https|http|)://(www.|old.|np.|amp.|)(reddit).(com)/"#) {
|
||||
Ok(re) => re.replace_all(input_text, r#"href="/"#).to_string(),
|
||||
Err(_) => String::new(),
|
||||
};
|
||||
|
||||
// Rewrite external media previews to Libreddit
|
||||
match Regex::new(r"https://external-preview\.redd\.it(.*)[^?]") {
|
||||
Ok(re) => {
|
||||
if re.is_match(&text1) {
|
||||
re.replace_all(&text1, format_url(re.find(&text1).unwrap().as_str())).to_string()
|
||||
} else {
|
||||
text1
|
||||
}
|
||||
},
|
||||
Err(_) => String::new(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user