From 932244a1ec5bd0b06ed0a06c0658ede08f5654dd Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:17:42 +0530 Subject: [PATCH] feat: Add support for Arcade videos on articles (#10585) Fixes https://linear.app/chatwoot/issue/CW-3779/add-support-for-arcade-videos-on-articles-loom-alternative **Loom video** https://www.loom.com/share/917bdecb4eaf4d3f9782b4fa84ee4bd4?sid=d11f0d71-0cf5-424a-9268-9d9fb3797ee2 Co-authored-by: Sojan Jose --- lib/custom_markdown_renderer.rb | 23 ++++++++++++++++++- spec/lib/custom_markdown_renderer_spec.rb | 28 +++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/custom_markdown_renderer.rb b/lib/custom_markdown_renderer.rb index 0cab0cdf9..dfd3ce700 100644 --- a/lib/custom_markdown_renderer.rb +++ b/lib/custom_markdown_renderer.rb @@ -1,8 +1,11 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer + # TODO: let move this regex from here to a config file where we can update this list much more easily + # the config file will also have the matching embed template as well. YOUTUBE_REGEX = %r{https?://(?:www\.)?(?:youtube\.com/watch\?v=|youtu\.be/)([^&/]+)} LOOM_REGEX = %r{https?://(?:www\.)?loom\.com/share/([^&/]+)} VIMEO_REGEX = %r{https?://(?:www\.)?vimeo\.com/(\d+)} MP4_REGEX = %r{https?://(?:www\.)?.+\.(mp4)} + ARCADE_REGEX = %r{https?://(?:www\.)?app\.arcade\.software/share/([^&/]+)} def text(node) content = node.string_content @@ -46,7 +49,8 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer YOUTUBE_REGEX => :make_youtube_embed, VIMEO_REGEX => :make_vimeo_embed, MP4_REGEX => :make_video_embed, - LOOM_REGEX => :make_loom_embed + LOOM_REGEX => :make_loom_embed, + ARCADE_REGEX => :make_arcade_embed } embedding_methods.each do |regex, method| @@ -118,4 +122,21 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer ) end + + def make_arcade_embed(arcade_match) + video_id = arcade_match[1] + %( +
+ +
+ ) + end end diff --git a/spec/lib/custom_markdown_renderer_spec.rb b/spec/lib/custom_markdown_renderer_spec.rb index 74c6d4398..70593f308 100644 --- a/spec/lib/custom_markdown_renderer_spec.rb +++ b/spec/lib/custom_markdown_renderer_spec.rb @@ -137,5 +137,33 @@ describe CustomMarkdownRenderer do expect(output).to include('src="https://player.vimeo.com/video/1234567"') end end + + context 'when link is an Arcade URL' do + let(:arcade_url) { 'https://app.arcade.software/share/ARCADE_ID' } + + it 'renders an iframe with Arcade embed code' do + output = render_markdown_link(arcade_url) + expect(output).to include('src="https://app.arcade.software/embed/ARCADE_ID"') + expect(output).to include('