Add rudimentary support for embedding videos

This commit is contained in:
Jason Zimdars
2025-01-30 16:47:42 -06:00
parent e918b813a0
commit 9b7d297027
3 changed files with 20 additions and 2 deletions
+14
View File
@@ -37,6 +37,8 @@ class MarkdownRenderer < Redcarpet::Render::HTML
end
def link(url, title, content)
return video_tag(url, title) if video_url?(url)
attributes = { href: url }
attributes[:title] = title if title
attributes["data-turbo-frame"] = "_top"
@@ -64,4 +66,16 @@ class MarkdownRenderer < Redcarpet::Render::HTML
id_counts[base_id] > 1 ? "#{base_id}-#{id_counts[base_id]}" : base_id
end
end
def video_url?(url)
File.extname(url).downcase.match?(/\.(mp4|webm|ogg)/)
end
def video_tag(url, title)
<<~HTML.chomp
<video controls title="#{title}" width="1024">
<source src="#{url}" type="video/#{File.extname(url).delete('.')}">
</video>
HTML
end
end