From 46d7bed409aa0355ffa4acff098c7ee803c57593 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 25 May 2024 19:12:05 -0400 Subject: [PATCH] hack to preserve youtube urls --- .../lib/markdown/src/markdown_with_socials_to_html.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/lib/markdown/src/markdown_with_socials_to_html.rs b/crates/lib/markdown/src/markdown_with_socials_to_html.rs index c2c7f8962a..093b177001 100644 --- a/crates/lib/markdown/src/markdown_with_socials_to_html.rs +++ b/crates/lib/markdown/src/markdown_with_socials_to_html.rs @@ -94,6 +94,11 @@ static YOUTUBE_CHANNEL: Lazy = Lazy::new(|| { }); fn replace_youtube_channel(input: &str) -> Cow { + if input.contains("/channel/") { + // TODO(bt,2024-05-25): Regex crate does not support lookahead. + // This is a temporary hack to prevent clobbering actual YouTube URLs. + return Cow::Borrowed(input); + } YOUTUBE_CHANNEL.replace(input, |caps: &Captures| { format!("[{}](https://www.youtube.com/@{})", &caps[1], &caps[4]) }) @@ -270,6 +275,12 @@ mod tests { mod youtube { use super::*; + #[test] + pub fn full_channels_not_changed() { + assert_eq!(&markdown_with_socials_to_html("https://www.youtube.com/channel/UCEU3gjhuT1V86Ru_RoCTcCA "), + "

https://www.youtube.com/channel/UCEU3gjhuT1V86Ru_RoCTcCA

\n"); + } + pub mod with_at { use super::*;