diff --git a/src/Markdig.Tests/Specs/MediaSpecs.generated.cs b/src/Markdig.Tests/Specs/MediaSpecs.generated.cs index a512604b5..8cfa06cec 100644 --- a/src/Markdig.Tests/Specs/MediaSpecs.generated.cs +++ b/src/Markdig.Tests/Specs/MediaSpecs.generated.cs @@ -1,4 +1,4 @@ -// Generated: 2019-05-15 02:46:20 +// Generated: 2020-05-12 19:59:34 // -------------------------------- // Media @@ -17,7 +17,7 @@ public class TestExtensionsMediaLinks // Adds support for media links: // // ## Media links - // + // // Allows to embed audio/video links to popular website: [Test] public void ExtensionsMediaLinks_Example001() @@ -35,7 +35,7 @@ public void ExtensionsMediaLinks_Example001() // ![youtu.be with t](https://youtu.be/mswPy5bt3TQ?t=100) // // ![youtube.com/embed 1](https://www.youtube.com/embed/mswPy5bt3TQ?start=100&rel=0) - // + // // ![youtube.com/embed 2](https://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6) // // ![vimeo](https://vimeo.com/8607834) @@ -47,19 +47,19 @@ public void ExtensionsMediaLinks_Example001() // ![ok.ru](https://ok.ru/video/26870090463) // // Should be rendered as: - //

- //

- //

- //

- //

- //

- //

+ //

+ //

+ //

+ //

+ //

+ //

+ //

//

- //

- //

+ //

+ //

Console.WriteLine("Example 1\nSection Extensions / Media links\n"); - TestParser.TestSpec("![youtube.com](https://www.youtube.com/watch?v=mswPy5bt3TQ)\n\n![youtube.com with t](https://www.youtube.com/watch?v=mswPy5bt3TQ&t=100)\n\n![youtu.be](https://youtu.be/mswPy5bt3TQ)\n\n![youtu.be with t](https://youtu.be/mswPy5bt3TQ?t=100)\n\n![youtube.com/embed 1](https://www.youtube.com/embed/mswPy5bt3TQ?start=100&rel=0)\n \n![youtube.com/embed 2](https://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6)\n\n![vimeo](https://vimeo.com/8607834)\n\n![static mp4](https://sample.com/video.mp4)\n\n![yandex.ru](https://music.yandex.ru/album/411845/track/4402274)\n\n![ok.ru](https://ok.ru/video/26870090463)", "

\n

\n

\n

\n

\n

\n

\n

\n

\n

", "medialinks|advanced+medialinks"); + TestParser.TestSpec("![youtube.com](https://www.youtube.com/watch?v=mswPy5bt3TQ)\n\n![youtube.com with t](https://www.youtube.com/watch?v=mswPy5bt3TQ&t=100)\n\n![youtu.be](https://youtu.be/mswPy5bt3TQ)\n\n![youtu.be with t](https://youtu.be/mswPy5bt3TQ?t=100)\n\n![youtube.com/embed 1](https://www.youtube.com/embed/mswPy5bt3TQ?start=100&rel=0)\n\n![youtube.com/embed 2](https://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6)\n\n![vimeo](https://vimeo.com/8607834)\n\n![static mp4](https://sample.com/video.mp4)\n\n![yandex.ru](https://music.yandex.ru/album/411845/track/4402274)\n\n![ok.ru](https://ok.ru/video/26870090463)", "

\n

\n

\n

\n

\n

\n

\n

\n

\n

", "medialinks|advanced+medialinks"); } } } diff --git a/src/Markdig.Tests/Specs/MediaSpecs.md b/src/Markdig.Tests/Specs/MediaSpecs.md index 55eb3b22a..ac5ab49f2 100644 --- a/src/Markdig.Tests/Specs/MediaSpecs.md +++ b/src/Markdig.Tests/Specs/MediaSpecs.md @@ -3,7 +3,7 @@ Adds support for media links: ## Media links - + Allows to embed audio/video links to popular website: ```````````````````````````````` example @@ -16,7 +16,7 @@ Allows to embed audio/video links to popular website: ![youtu.be with t](https://youtu.be/mswPy5bt3TQ?t=100) ![youtube.com/embed 1](https://www.youtube.com/embed/mswPy5bt3TQ?start=100&rel=0) - + ![youtube.com/embed 2](https://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6) ![vimeo](https://vimeo.com/8607834) @@ -27,14 +27,14 @@ Allows to embed audio/video links to popular website: ![ok.ru](https://ok.ru/video/26870090463) . -

-

-

-

-

-

-

+

+

+

+

+

+

+

-

-

+

+

```````````````````````````````` \ No newline at end of file diff --git a/src/Markdig.Tests/TestMediaLinks.cs b/src/Markdig.Tests/TestMediaLinks.cs index 79514a103..27ba34262 100644 --- a/src/Markdig.Tests/TestMediaLinks.cs +++ b/src/Markdig.Tests/TestMediaLinks.cs @@ -15,14 +15,22 @@ private MarkdownPipeline GetPipeline(MediaOptions options = null) .Build(); } + private MarkdownPipeline GetPipelineWithBootstrap(MediaOptions options = null) + { + return new MarkdownPipelineBuilder() + .UseBootstrap() + .UseMediaLinks(options) + .Build(); + } + [Test] [TestCase("![static mp4](https://sample.com/video.mp4)", "

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

\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")] - [TestCase("![ok.ru](https://ok.ru/video/26870090463)", "

\n")] - [TestCase("![ok.ru](//ok.ru/video/26870090463)", "

\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")] + [TestCase("![ok.ru](https://ok.ru/video/26870090463)", "

\n")] + [TestCase("![ok.ru](//ok.ru/video/26870090463)", "

\n")] public void TestBuiltInHosts(string markdown, string expected) { string html = Markdown.ToHtml(markdown, GetPipeline()); @@ -55,9 +63,9 @@ public TestHostProvider(string provider, string replace) } [Test] - [TestCase("![p1](https://sample.com/video.mp4)", "

\n", @"^https?://sample.com/(.+)$", @"https://example.com/$1")] - [TestCase("![p1](//sample.com/video.mp4)", "

\n", @"^//sample.com/(.+)$", @"https://example.com/$1")] - [TestCase("![p1](https://sample.com/video.mp4)", "

\n", @"^https?://sample.com/(.+)$", @"https://example.com/$1?token=aaabbb")] + [TestCase("![p1](https://sample.com/video.mp4)", "

\n", @"^https?://sample.com/(.+)$", @"https://example.com/$1")] + [TestCase("![p1](//sample.com/video.mp4)", "

\n", @"^//sample.com/(.+)$", @"https://example.com/$1")] + [TestCase("![p1](https://sample.com/video.mp4)", "

\n", @"^https?://sample.com/(.+)$", @"https://example.com/$1?token=aaabbb")] public void TestCustomHostProvider(string markdown, string expected, string provider, string replace) { string html = Markdown.ToHtml(markdown, GetPipeline(new MediaOptions @@ -72,9 +80,9 @@ public void TestCustomHostProvider(string markdown, string expected, string prov [Test] [TestCase("![static mp4](//sample.com/video.mp4)", "

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

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

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

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

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

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

\n", "k")] public void TestCustomClass(string markdown, string expected, string klass) { string html = Markdown.ToHtml(markdown, GetPipeline(new MediaOptions @@ -83,5 +91,14 @@ public void TestCustomClass(string markdown, string expected, string klass) })); Assert.AreEqual(html, expected); } + + [Test] + [TestCase("![static mp4](//sample.com/video.mp4)", "

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

\n")] + public void TestWithBootstrap(string markdown, string expected) + { + string html = Markdown.ToHtml(markdown, GetPipelineWithBootstrap()); + Assert.AreEqual(html, expected); + } } } diff --git a/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs b/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs index c8db9287e..063982c00 100644 --- a/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs +++ b/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs @@ -113,7 +113,7 @@ private bool TryGuessAudioVideoFile(Uri uri, bool isSchemaRelative, HtmlRenderer htmlAttributes.AddPropertyIfNotExist("controls", null); if (!string.IsNullOrEmpty(Options.Class)) - htmlAttributes.AddPropertyIfNotExist("class", Options.Class); + htmlAttributes.AddClass(Options.Class); renderer.WriteAttributes(htmlAttributes); @@ -153,11 +153,11 @@ private bool TryRenderIframeFromKnownProviders(Uri uri, bool isSchemaRelative, H if (!string.IsNullOrEmpty(Options.Height)) htmlAttributes.AddPropertyIfNotExist("height", Options.Height); - if (!string.IsNullOrEmpty(Options.Class) || !string.IsNullOrEmpty(foundProvider.Class)) - htmlAttributes.AddPropertyIfNotExist("class", - (!string.IsNullOrEmpty(Options.Class) && !string.IsNullOrEmpty(foundProvider.Class)) - ? Options.Class + " " + foundProvider.Class - : Options.Class + foundProvider.Class); + if (!string.IsNullOrEmpty(Options.Class)) + htmlAttributes.AddClass(Options.Class); + + if (!string.IsNullOrEmpty(foundProvider.Class)) + htmlAttributes.AddClass(foundProvider.Class); htmlAttributes.AddPropertyIfNotExist("frameborder", "0"); if (foundProvider.AllowFullScreen)