3354: Rename render_content_from_database helper to render_markup, as a more directly...
[arvados.git] / apps / workbench / config / initializers / redcloth.rb
1 module RedClothArvadosLinkExtension
2
3   class RedClothViewBase < ActionView::Base
4     include ApplicationHelper
5     include ActionView::Helpers::UrlHelper
6     include Rails.application.routes.url_helpers
7
8     def helper_link_to_if_arvados_object(link, opts)
9       link_to_if_arvados_object(link, opts)
10     end
11   end
12
13   def refs_arvados(text)
14     text.gsub!(/"(?!\s)([^"]*\S)":(\S+)/) do
15       text, link = $~[1..2]
16       arvados_link = RedClothViewBase.new.helper_link_to_if_arvados_object(link, { :link_text => text })
17       arvados_link ? arvados_link : "#{text}:#{link}"
18     end
19   end
20 end
21
22 RedCloth.send(:include, RedClothArvadosLinkExtension)