diff options
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/video_link_filter.rb | 42 | ||||
-rw-r--r-- | lib/banzai/pipeline/gfm_pipeline.rb | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/banzai/filter/video_link_filter.rb b/lib/banzai/filter/video_link_filter.rb new file mode 100644 index 00000000000..0ae885708f7 --- /dev/null +++ b/lib/banzai/filter/video_link_filter.rb @@ -0,0 +1,42 @@ +module Banzai + module Filter + + # HTML Filter that handles video uploads. + + class VideoLinkFilter < HTML::Pipeline::Filter + include ActionView::Helpers::TagHelper + include ActionView::Context + + EXTENSIONS = %w(.mov .mp4 .ogg .webm .flv) + + def call + doc.search('img').each do |el| + if video?(el) + el.replace video_node(el) + end + end + + doc + end + + private + + def video?(element) + EXTENSIONS.include? File.extname(element.attribute('src').value) + end + + # Return a video tag Nokogiri node + # + def video_node(element) + vtag = content_tag(:video, "", { + src: element.attribute('src').value, + class: 'video-js', preload: 'auto', + controls: true + }) + + Nokogiri::HTML::DocumentFragment.parse(vtag) + end + end + + end +end diff --git a/lib/banzai/pipeline/gfm_pipeline.rb b/lib/banzai/pipeline/gfm_pipeline.rb index b27ecf3c923..d9edca7046c 100644 --- a/lib/banzai/pipeline/gfm_pipeline.rb +++ b/lib/banzai/pipeline/gfm_pipeline.rb @@ -8,6 +8,7 @@ module Banzai Filter::UploadLinkFilter, Filter::ImageLinkFilter, + Filter::VideoLinkFilter, Filter::EmojiFilter, Filter::TableOfContentsFilter, Filter::AutolinkFilter, |