Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / config / initializers / redcloth.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 module RedClothArvadosLinkExtension
6
7   class RedClothViewBase < ActionView::Base
8     include ApplicationHelper
9     include ActionView::Helpers::UrlHelper
10     include Rails.application.routes.url_helpers
11
12     def helper_link_to_if_arvados_object(link, opts)
13       link_to_if_arvados_object(link, opts)
14     end
15   end
16
17   def refs_arvados(text)
18     text.gsub!(/"(?!\s)([^"]*\S)":(\S+)/) do
19       text, link = $~[1..2]
20       arvados_link = RedClothViewBase.new.helper_link_to_if_arvados_object(link, { :link_text => text })
21       # if it's not an arvados_link the helper will return the link unprocessed and so we will reconstruct the textile link string so it can be processed normally
22       (arvados_link == link) ? "\"#{text}\":#{link}" : arvados_link
23     end
24   end
25 end
26
27 RedCloth.send(:include, RedClothArvadosLinkExtension)