2022-01-16 13:13:07 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-12-30 09:13:52 -08:00
|
|
|
module SharedMarkers
|
2021-12-31 13:21:05 -08:00
|
|
|
include ActionView::Helpers::TagHelper
|
|
|
|
|
2022-01-16 13:13:07 -08:00
|
|
|
def process_link(link, text = nil)
|
|
|
|
href = if ALLOWED_HOSTS_IN_MARKDOWN.include?(URI(link).host) || URI(link).relative?
|
2022-01-02 10:26:04 -08:00
|
|
|
link
|
|
|
|
else
|
|
|
|
linkfilter_path(url: link)
|
|
|
|
end
|
|
|
|
|
2022-01-16 13:13:07 -08:00
|
|
|
options = { href: href }
|
|
|
|
|
|
|
|
unless URI(link).relative?
|
|
|
|
options = options.merge({
|
|
|
|
target: "_blank",
|
|
|
|
rel: "nofollow"
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2022-07-11 10:37:53 -07:00
|
|
|
# Marking the text content as HTML safe as <tt>content_tag</tt> already escapes it for us
|
|
|
|
content_tag(:a, text.nil? ? link : text.html_safe, options)
|
2022-01-02 10:23:59 -08:00
|
|
|
rescue
|
|
|
|
link
|
2021-12-30 09:13:52 -08:00
|
|
|
end
|
2022-01-16 13:13:07 -08:00
|
|
|
|
|
|
|
def autolink(link, _link_type)
|
|
|
|
process_link(link)
|
|
|
|
end
|
|
|
|
|
|
|
|
def link(link, _title, content)
|
|
|
|
process_link(link, content)
|
|
|
|
end
|
|
|
|
end
|