Support GIFs in comments (#217)

* Support GIFs in comments

* Fix removing Giphy links so it only removes Giphy links

* Remove removing link to Giphy
pull/220/head
imabritishcow 2 years ago committed by GitHub
parent c1560f4eba
commit 97a0680bd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 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…
Cancel
Save