fix youtu.be links
This commit is contained in:
parent
42f5f7fc32
commit
502f467012
2 changed files with 19 additions and 1 deletions
|
|
@ -70,7 +70,7 @@ module MarkdownifyHelper
|
|||
captures = [$1,$2,$3]
|
||||
if !captures[0].nil?
|
||||
m
|
||||
elsif m.match(/(youtube|vimeo)/)
|
||||
elsif m.match(/(youtu.?be|vimeo)/)
|
||||
m.gsub(/(\*|_)/) { |m| "\\#{$1}" } #remove markers on markdown chars to not markdown inside links
|
||||
else
|
||||
res = %{<a target="_blank" href="#{captures[1]}://#{captures[2]}">#{captures[2]}</a>}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,15 @@ describe MarkdownifyHelper do
|
|||
markdownify(proto+"://"+url).should == "<a target=\"_blank\" href=\""+proto+"://"+url+"\">"+url+"</a>"
|
||||
end
|
||||
|
||||
it "doesn't double parse video links" do
|
||||
message = "http://www.vimeo.com/17449557
|
||||
http://www.youtube.com/watch?v=0x__dDWdf23&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1
|
||||
http://youtu.be/x_CzD0GBD-4"
|
||||
res = markdownify(message)
|
||||
res.should =~ /href.+href.+href/
|
||||
res.should_not =~ /href.+href.+href.+href/
|
||||
end
|
||||
|
||||
describe "video links" do
|
||||
it "recognizes vimeo links" do
|
||||
video_id = "17449557"
|
||||
|
|
@ -62,6 +71,15 @@ describe MarkdownifyHelper do
|
|||
res.should =~ /data-video-id="#{video_id}"/
|
||||
end
|
||||
|
||||
it "recognizes youtu.be links" do
|
||||
video_id = "x_CzD0GBD-4"
|
||||
url = "http://youtu.be/#{video_id}"
|
||||
res = markdownify(url)
|
||||
res.should =~ /Youtube:/
|
||||
res.should =~ /data-host="youtube.com"/
|
||||
res.should =~ /data-video-id="#{video_id}"/
|
||||
end
|
||||
|
||||
it "recognizes youtube links with hyphens" do
|
||||
video_id = "ABYnqp-bxvg"
|
||||
url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
||||
|
|
|
|||
Loading…
Reference in a new issue