Retrospring/app/services/shared_markers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
867 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module SharedMarkers
include ActionView::Helpers::TagHelper
def process_link(link, text = nil)
href = if ALLOWED_HOSTS_IN_MARKDOWN.include?(URI(link).host) || URI(link).relative?
link
else
linkfilter_path(url: link)
end
options = { href: href }
unless URI(link).relative?
options = options.merge({
target: "_blank",
rel: "nofollow"
})
end
# 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)
rescue
link
end
def autolink(link, _link_type)
process_link(link)
end
def link(link, _title, content)
process_link(link, content)
end
end