diff --git a/lib/custom_markdown_renderer.rb b/lib/custom_markdown_renderer.rb index 75dc43700..902fc20a3 100644 --- a/lib/custom_markdown_renderer.rb +++ b/lib/custom_markdown_renderer.rb @@ -7,6 +7,7 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer MP4_REGEX = %r{https?://(?:www\.)?.+\.(mp4)} ARCADE_REGEX = %r{https?://(?:www\.)?app\.arcade\.software/share/([^&/]+)} WISTIA_REGEX = %r{https?://(?:www\.)?([^/]+)\.wistia\.com/medias/([^&/]+)} + BUNNY_REGEX = %r{https?://iframe\.mediadelivery\.net/play/(\d+)/([^&/?]+)} def text(node) content = node.string_content @@ -52,7 +53,8 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer MP4_REGEX => :make_video_embed, LOOM_REGEX => :make_loom_embed, ARCADE_REGEX => :make_arcade_embed, - WISTIA_REGEX => :make_wistia_embed + WISTIA_REGEX => :make_wistia_embed, + BUNNY_REGEX => :make_bunny_embed } embedding_methods.each do |regex, method| @@ -104,4 +106,10 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer video_id = arcade_match[1] EmbedRenderer.arcade(video_id) end + + def make_bunny_embed(bunny_match) + library_id = bunny_match[1] + video_id = bunny_match[2] + EmbedRenderer.bunny(library_id, video_id) + end end diff --git a/lib/embed_renderer.rb b/lib/embed_renderer.rb index 0a747bbb3..78f620376 100644 --- a/lib/embed_renderer.rb +++ b/lib/embed_renderer.rb @@ -84,4 +84,19 @@ module EmbedRenderer ) end + + def self.bunny(library_id, video_id) + %( +
+ +
+ ) + end end diff --git a/spec/lib/custom_markdown_renderer_spec.rb b/spec/lib/custom_markdown_renderer_spec.rb index 939965e91..23574e8c4 100644 --- a/spec/lib/custom_markdown_renderer_spec.rb +++ b/spec/lib/custom_markdown_renderer_spec.rb @@ -162,5 +162,22 @@ describe CustomMarkdownRenderer do expect(output).to include('src="https://www.youtube-nocookie.com/embed/VIDEO_ID"') end end + + context 'when link is a Bunny.net URL' do + let(:bunny_url) { 'https://iframe.mediadelivery.net/play/431789/1f105841-cad9-46fe-a70e-b7623c60797c' } + + it 'renders an iframe with Bunny embed code' do + output = render_markdown_link(bunny_url) + expect(output).to include('src="https://iframe.mediadelivery.net/embed/431789/1f105841-cad9-46fe-a70e-b7623c60797c?autoplay=false&loop=false&muted=false&preload=true&responsive=true"') + expect(output).to include('allowfullscreen') + expect(output).to include('allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"') + end + + it 'wraps iframe in responsive container' do + output = render_markdown_link(bunny_url) + expect(output).to include('position: relative; padding-top: 56.25%;') + expect(output).to include('position: absolute; top: 0; height: 100%; width: 100%;') + end + end end end