From 6e0363aa91b64efb52319e4fdd7af1474e16987b Mon Sep 17 00:00:00 2001 From: Rudey Date: Tue, 12 May 2020 21:29:28 +0200 Subject: [PATCH 1/5] Fix media link classes not being added --- .../Extensions/MediaLinks/MediaLinkExtension.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs b/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs index c8db9287e..d91d16256 100644 --- a/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs +++ b/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs @@ -154,10 +154,12 @@ private bool TryRenderIframeFromKnownProviders(Uri uri, bool isSchemaRelative, H 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) From 42462d71aca8747649dca9c515b23a498e0c2d0d Mon Sep 17 00:00:00 2001 From: Rudey Date: Tue, 12 May 2020 21:41:52 +0200 Subject: [PATCH 2/5] Reorder class attribute in test cases --- src/Markdig.Tests/TestMediaLinks.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Markdig.Tests/TestMediaLinks.cs b/src/Markdig.Tests/TestMediaLinks.cs index 79514a103..96fcf7d5f 100644 --- a/src/Markdig.Tests/TestMediaLinks.cs +++ b/src/Markdig.Tests/TestMediaLinks.cs @@ -18,11 +18,11 @@ private MarkdownPipeline GetPipeline(MediaOptions options = null) [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 +55,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 +72,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 From ba192ce0657d07f6c9015a1bc853089f7d76c9f2 Mon Sep 17 00:00:00 2001 From: Rudey Date: Tue, 12 May 2020 21:45:50 +0200 Subject: [PATCH 3/5] Remove redundancy, apply same fix to audio/video --- .../Extensions/MediaLinks/MediaLinkExtension.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs b/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs index d91d16256..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,13 +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)) - { - if (!string.IsNullOrEmpty(Options.Class)) - htmlAttributes.AddClass(Options.Class); - if (!string.IsNullOrEmpty(foundProvider.Class)) - htmlAttributes.AddClass(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) From d53128d56d18eedc50ca227218d41c8b9bccd79c Mon Sep 17 00:00:00 2001 From: Rudey Date: Tue, 12 May 2020 22:02:01 +0200 Subject: [PATCH 4/5] Reorder class attribute in spec tests --- .../Specs/MediaSpecs.generated.cs | 26 +++++++++---------- src/Markdig.Tests/Specs/MediaSpecs.md | 22 ++++++++-------- 2 files changed, 24 insertions(+), 24 deletions(-) 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 From ea67a295b2cc118389ffc00ee6057df007c2e0ce Mon Sep 17 00:00:00 2001 From: Rudey Date: Tue, 12 May 2020 22:32:05 +0200 Subject: [PATCH 5/5] Test CSS classes using both Bootstrap and MediaLinks --- src/Markdig.Tests/TestMediaLinks.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Markdig.Tests/TestMediaLinks.cs b/src/Markdig.Tests/TestMediaLinks.cs index 96fcf7d5f..27ba34262 100644 --- a/src/Markdig.Tests/TestMediaLinks.cs +++ b/src/Markdig.Tests/TestMediaLinks.cs @@ -15,6 +15,14 @@ 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")] @@ -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); + } } }