From 3c12dd654953906253437ca2d82f640caf9d9d0a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 22 Sep 2016 16:50:05 -0400 Subject: [PATCH] FIX: Consider lazyYT divs as links when extracting --- lib/pretty_text.rb | 5 +++++ spec/components/pretty_text_spec.rb | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 23088e980ff..691ff158b5b 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -294,6 +294,11 @@ module PrettyText links << DetectedLink.new(url, true) end + # Extract Youtube links + doc.css("div[data-youtube-id]").each do |d| + links << DetectedLink.new("https://www.youtube.com/watch?v=#{d['data-youtube-id']}", false) + end + links end diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 4799e12e40f..eb840cbcd8a 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -204,6 +204,10 @@ HTML expect(extract_urls("")).to eq(["/t/topic/321"]) end + it "should lazyYT videos" do + expect(extract_urls("
")).to eq(["https://www.youtube.com/watch?v=yXEuEUQIP3Q"]) + end + it "should extract links to posts" do expect(extract_urls("")).to eq(["/t/topic/1234/4567"]) end