mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-30 02:32:29 +00:00
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 <sojan@pepalo.com>
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
class CustomMarkdownRenderer < CommonMarker::HtmlRenderer
|
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/)([^&/]+)}
|
YOUTUBE_REGEX = %r{https?://(?:www\.)?(?:youtube\.com/watch\?v=|youtu\.be/)([^&/]+)}
|
||||||
LOOM_REGEX = %r{https?://(?:www\.)?loom\.com/share/([^&/]+)}
|
LOOM_REGEX = %r{https?://(?:www\.)?loom\.com/share/([^&/]+)}
|
||||||
VIMEO_REGEX = %r{https?://(?:www\.)?vimeo\.com/(\d+)}
|
VIMEO_REGEX = %r{https?://(?:www\.)?vimeo\.com/(\d+)}
|
||||||
MP4_REGEX = %r{https?://(?:www\.)?.+\.(mp4)}
|
MP4_REGEX = %r{https?://(?:www\.)?.+\.(mp4)}
|
||||||
|
ARCADE_REGEX = %r{https?://(?:www\.)?app\.arcade\.software/share/([^&/]+)}
|
||||||
|
|
||||||
def text(node)
|
def text(node)
|
||||||
content = node.string_content
|
content = node.string_content
|
||||||
@@ -46,7 +49,8 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer
|
|||||||
YOUTUBE_REGEX => :make_youtube_embed,
|
YOUTUBE_REGEX => :make_youtube_embed,
|
||||||
VIMEO_REGEX => :make_vimeo_embed,
|
VIMEO_REGEX => :make_vimeo_embed,
|
||||||
MP4_REGEX => :make_video_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|
|
embedding_methods.each do |regex, method|
|
||||||
@@ -118,4 +122,21 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer
|
|||||||
</video>
|
</video>
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def make_arcade_embed(arcade_match)
|
||||||
|
video_id = arcade_match[1]
|
||||||
|
%(
|
||||||
|
<div style="position: relative; padding-bottom: 62.5%; height: 0;">
|
||||||
|
<iframe
|
||||||
|
src="https://app.arcade.software/embed/#{video_id}"
|
||||||
|
frameborder="0"
|
||||||
|
webkitallowfullscreen
|
||||||
|
mozallowfullscreen
|
||||||
|
allowfullscreen
|
||||||
|
allow="fullscreen"
|
||||||
|
style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;">
|
||||||
|
</iframe>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -137,5 +137,33 @@ describe CustomMarkdownRenderer do
|
|||||||
expect(output).to include('src="https://player.vimeo.com/video/1234567"')
|
expect(output).to include('src="https://player.vimeo.com/video/1234567"')
|
||||||
end
|
end
|
||||||
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('<iframe')
|
||||||
|
expect(output).to include('webkitallowfullscreen')
|
||||||
|
expect(output).to include('mozallowfullscreen')
|
||||||
|
expect(output).to include('allowfullscreen')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'wraps iframe in responsive container' do
|
||||||
|
output = render_markdown_link(arcade_url)
|
||||||
|
expect(output).to include('position: relative; padding-bottom: 62.5%; height: 0;')
|
||||||
|
expect(output).to include('position: absolute; top: 0; left: 0; width: 100%; height: 100%;')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when multiple links including Arcade are present' do
|
||||||
|
it 'renders Arcade embed along with other content types' do
|
||||||
|
markdown = "\n[arcade](https://app.arcade.software/share/ARCADE_ID)\n\n[youtube](https://www.youtube.com/watch?v=VIDEO_ID)\n"
|
||||||
|
output = render_markdown(markdown)
|
||||||
|
expect(output).to include('src="https://app.arcade.software/embed/ARCADE_ID"')
|
||||||
|
expect(output).to include('src="https://www.youtube.com/embed/VIDEO_ID"')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user