diff --git a/src/Markdig.Tests/TestMediaLinks.cs b/src/Markdig.Tests/TestMediaLinks.cs index 69fff8a5..90d7f6a4 100644 --- a/src/Markdig.Tests/TestMediaLinks.cs +++ b/src/Markdig.Tests/TestMediaLinks.cs @@ -25,6 +25,7 @@ private MarkdownPipeline GetPipelineWithBootstrap(MediaOptions options = null) [Test] [TestCase("![static mp4](https://sample.com/video.mp4)", "

\n")] [TestCase("![static mp4](//sample.com/video.mp4)", "

\n")] + [TestCase(@"![youtube short](https://www.youtube.com/shorts/6BUptHVuvyI?feature=share)", "

\n")] [TestCase(@"![youtube.com](https://www.youtube.com/watch?v=mswPy5bt3TQ)", "

\n")] [TestCase("![yandex.ru](https://music.yandex.ru/album/411845/track/4402274)", "

\n")] [TestCase("![vimeo](https://vimeo.com/8607834)", "

\n")] @@ -33,7 +34,7 @@ private MarkdownPipeline GetPipelineWithBootstrap(MediaOptions options = null) public void TestBuiltInHosts(string markdown, string expected) { string html = Markdown.ToHtml(markdown, GetPipeline()); - Assert.AreEqual(html, expected); + Assert.AreEqual(expected, html); } [TestCase("![static video relative path](./video.mp4)", @@ -43,7 +44,7 @@ public void TestBuiltInHosts(string markdown, string expected) public void TestBuiltInHostsWithRelativePaths(string markdown, string expected) { string html = Markdown.ToHtml(markdown, GetPipeline()); - Assert.AreEqual(html, expected); + Assert.AreEqual(expected, html); } private class TestHostProvider : IHostProvider diff --git a/src/Markdig/Extensions/MediaLinks/HostProviderBuilder.cs b/src/Markdig/Extensions/MediaLinks/HostProviderBuilder.cs index 419f38d2..38377ac8 100644 --- a/src/Markdig/Extensions/MediaLinks/HostProviderBuilder.cs +++ b/src/Markdig/Extensions/MediaLinks/HostProviderBuilder.cs @@ -58,6 +58,7 @@ public static IHostProvider Create(string hostPrefix, Func handler internal static Dictionary KnownHosts { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase) { + ["YouTubeShort"] = Create("www.youtube.com", YouTubeShort, iframeClass: "youtubeshort"), ["YouTube"] = Create("www.youtube.com", YouTube, iframeClass: "youtube"), ["YouTubeShortened"] = Create("youtu.be", YouTubeShortened, iframeClass: "youtube"), ["Vimeo"] = Create("vimeo.com", Vimeo, iframeClass: "vimeo"), @@ -92,6 +93,19 @@ private static string[] SplitQuery(Uri uri) ); } + private static string? YouTubeShort(Uri uri) + { + string uriPath = uri.AbsolutePath; + bool isYouTubeShort = uriPath.StartsWith("/shorts/", StringComparison.OrdinalIgnoreCase); + if (!isYouTubeShort) + { + return null; + } + + var shortId = uriPath.Substring("/shorts/".Length).Split('?').FirstOrDefault(); // the format might be "/shorts/6BUptHVuvyI?feature=share" + return BuildYouTubeIframeUrl(shortId, null); + } + private static string? YouTubeShortened(Uri uri) { return BuildYouTubeIframeUrl(