4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/html/pipeline/youtube/youtube_filter.rb', line 4
def call
regex = /(?<=^|\s|<div>|<br>)https?:\/\/(?:www.)?(?:youtube\.com\/(?:embed\/|watch\?(?:feature=player_embedded&)?v=)|youtu\.be\/)([A-Za-z0-9_-]*)[&?\w-]*/
@text.gsub(regex) do
youtube_id = $1
width = context[:video_width] || 420
height = context[:video_height] || 315
frameborder = context[:video_frameborder] || 0
wmode = context[:video_wmode]
autoplay = context[:video_autoplay] || false
hide_related = context[:video_hide_related] || false
src = "//www.youtube.com/embed/#{youtube_id}"
params = []
params << "wmode=#{wmode}" if wmode
params << "autoplay=1" if autoplay
params << "rel=0" if hide_related
src += "?#{params.join '&'}" unless params.empty?
%{\n\n<div class="video youtube"><iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe></div>}
end
end
|