retrospring/app/services/shared_markers.rb
Andreas Nedbal 3bdca34c2d QuestionMarkdown adjustments
* Using `Redcarpet::Render::StripDown` as base now
* Support for autolinks and named links in Markdown
* Named links in questions just return the actual link as text
* Fixed codestyle in files
2022-01-16 22:33:48 +01:00

34 lines
763 B
Ruby

# 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
content_tag(:a, text.nil? ? link : text, options)
rescue
link
end
def autolink(link, _link_type)
process_link(link)
end
def link(link, _title, content)
process_link(link, content)
end
end