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:
imabritishcow 2021-05-09 01:22:26 +00:00 committed by GitHub
parent c1560f4eba
commit 97a0680bd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

View File

@ -445,9 +445,21 @@ pub fn format_url(url: &str) -> String {
} }
// Rewrite Reddit links to Libreddit in body of text // Rewrite Reddit links to Libreddit in body of text
pub fn rewrite_urls(text: &str) -> String { pub fn rewrite_urls(input_text: &str) -> String {
match Regex::new(r#"href="(https|http|)://(www.|old.|np.|amp.|)(reddit).(com)/"#) { let text1 = match Regex::new(r#"href="(https|http|)://(www.|old.|np.|amp.|)(reddit).(com)/"#) {
Ok(re) => re.replace_all(text, r#"href="/"#).to_string(), 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(), Err(_) => String::new(),
} }
} }