diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fc744c270..1b3cfd61c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -10,10 +10,6 @@ module ApplicationHelper content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time end - def modern_browser? - false - end - def page_title text=nil title = "" if text.blank? @@ -68,7 +64,7 @@ module ApplicationHelper param_string << "#{k}=#{v}" end end - "
  • +"
  • #{aspect.name} @@ -210,25 +206,29 @@ module ApplicationHelper def process_youtube(message, youtube_maps) regex = /( |^)(http:\/\/)?www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_\-]+)(&[^ ]*|)/ - while youtube = message.match(regex) - video_id = youtube[3] + processed_message = message.gsub(regex) do |matched_string| + match_data = matched_string.match(regex) + video_id = match_data[3] if youtube_maps && youtube_maps[video_id] title = h(CGI::unescape(youtube_maps[video_id])) else title = I18n.t 'application.helper.video_title.unknown' end - message.gsub!(youtube[0], 'Youtube: ' + title + '') + 'Youtube: ' + title + '' end - return message + return processed_message end def process_autolinks(message) message.gsub!(/( |^)(www\.[^\s]+\.[^\s])/, '\1http://\2') message.gsub!(/(#{$3}} + res = %{#{captures[2]}} res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } res end @@ -253,23 +253,23 @@ module ApplicationHelper def process_vimeo(message, vimeo_maps) regex = /https?:\/\/(?:w{3}\.)?vimeo.com\/(\d{6,})/ - while vimeo = message.match(regex) - video_id = vimeo[1] + processed_message = message.gsub(regex) do |matched_string| + match_data = message.match(regex) + video_id = match_data[1] if vimeo_maps && vimeo_maps[video_id] title = h(CGI::unescape(vimeo_maps[video_id])) else title = I18n.t 'application.helper.video_title.unknown' end - message.gsub!(vimeo[0], 'Vimeo: ' + title + '') + 'Vimeo: ' + title + '' end - return message + return processed_message end def info_text(text) image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text end - def get_javascript_strings_for(language) defaults = I18n.t('javascripts', :locale => DEFAULT_LANGUAGE) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 4c90b27e7..9b339d2bc 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -106,6 +106,22 @@ describe ApplicationHelper do res.should =~ /data-host="youtube.com"/ res.should =~ /data-video-id="#{video_id}"/ end + + it "leaves the links in the href of the #a tag" do + video_id = "ABYnqp-bxvg" + start_url ="http://www.youtube.com/watch?v=" + video_id + url = start_url + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" + res = markdownify(url) + res.should =~ /href=[\S]+v=#{video_id}/ + end + it 'does not autolink inside the link' do + video_id = "ABYnqp-bxvg" + start_url ="http://www.youtube.com/watch?v=" + video_id + url = start_url + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" + res = markdownify(url) + pp res + res.match(/href="