diff --git a/lib/custom_markdown_renderer.rb b/lib/custom_markdown_renderer.rb index 3b262b69f..0cab0cdf9 100644 --- a/lib/custom_markdown_renderer.rb +++ b/lib/custom_markdown_renderer.rb @@ -1,5 +1,6 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer 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)} @@ -41,23 +42,19 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer def render_embedded_content(node) link_url = node.url + embedding_methods = { + YOUTUBE_REGEX => :make_youtube_embed, + VIMEO_REGEX => :make_vimeo_embed, + MP4_REGEX => :make_video_embed, + LOOM_REGEX => :make_loom_embed + } - youtube_match = link_url.match(YOUTUBE_REGEX) - if youtube_match - out(make_youtube_embed(youtube_match)) - return true - end - - vimeo_match = link_url.match(VIMEO_REGEX) - if vimeo_match - out(make_vimeo_embed(vimeo_match)) - return true - end - - mp4_match = link_url.match(MP4_REGEX) - if mp4_match - out(make_video_embed(link_url)) - return true + embedding_methods.each do |regex, method| + match = link_url.match(regex) + if match + out(send(method, match)) + return true + end end false @@ -76,28 +73,40 @@ class CustomMarkdownRenderer < CommonMarker::HtmlRenderer def make_youtube_embed(youtube_match) video_id = youtube_match[1] %( - + + ) + end + + def make_loom_embed(loom_match) + video_id = loom_match[1] + %( +