diff --git a/src/utils.rs b/src/utils.rs index 6f977754..5d060d9a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -909,7 +909,7 @@ pub fn format_url(url: &str) -> String { // These are links we want to replace in-body static REDDIT_REGEX: Lazy = Lazy::new(|| Regex::new(r#"href="(https|http|)://(www\.|old\.|np\.|amp\.|new\.|)(reddit\.com|redd\.it)/"#).unwrap()); -static REDDIT_PREVIEW_REGEX: Lazy = Lazy::new(|| Regex::new(r"https?://(external-preview|preview|i)\.redd\.it(.*)[^?]").unwrap()); +static REDDIT_PREVIEW_REGEX: Lazy = Lazy::new(|| Regex::new(r"https?://(external-preview|preview|i)\.redd\.it(.*)").unwrap()); static REDDIT_EMOJI_REGEX: Lazy = Lazy::new(|| Regex::new(r"https?://(www|).redditstatic\.com/(.*)").unwrap()); static REDLIB_PREVIEW_LINK_REGEX: Lazy = Lazy::new(|| Regex::new(r#"/(img|preview/)(pre|external-pre)?/(.*?)>"#).unwrap()); static REDLIB_PREVIEW_TEXT_REGEX: Lazy = Lazy::new(|| Regex::new(r">(.*?)").unwrap()); @@ -934,6 +934,8 @@ pub fn rewrite_urls(input_text: &str) -> String { // Remove (html-encoded) "\" from URLs. text1 = text1.replace("%5C", "").replace("\\_", "_"); + println!("text1 before: {text1}"); + // Rewrite external media previews to Redlib loop { if REDDIT_PREVIEW_REGEX.find(&text1).is_none() { @@ -951,7 +953,7 @@ pub fn rewrite_urls(input_text: &str) -> String { } // image_url contains > at the end of it, and right above this we remove image_text's front >, leaving us with just a single > between them - let image_to_replace = format!(""); + let image_to_replace = format!("

"); // _image_replacement needs to be in scope for the replacement at the bottom of the loop let mut _image_replacement = String::new(); @@ -1367,7 +1369,7 @@ async fn test_fetching_ws() { fn test_rewriting_image_links() { let input = r#"

caption 1

"#; - let output = r#"

caption 1
caption 1
"#; assert_eq!(rewrite_urls(input), output); }