Add linkfilter logic to existing renderers

This commit is contained in:
Andreas Nedbal 2021-12-30 18:13:52 +01:00 committed by Andreas Nedbal
parent 67ee589b5b
commit 02a5e7029e
5 changed files with 27 additions and 0 deletions

View File

@ -15,6 +15,11 @@ module MarkdownHelper
CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip
end
def question_markdown(content)
md = Redcarpet::Markdown.new(QuestionMarkdown.new, MARKDOWN_OPTS)
Sanitize.fragment(md.render(content), EVIL_TAGS).html_safe
end
def raw_markdown(content)
md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, RAW_MARKDOWN_OPTS)
raw md.render content

View File

@ -1,5 +1,6 @@
class FlavoredMarkdown < Redcarpet::Render::HTML
include Rails.application.routes.url_helpers
include SharedMarkers
def preprocess(text)
wrap_mentions(text)

View File

@ -0,0 +1,9 @@
module SharedMarkers
def autolink(link, _link_type)
if ALLOWED_HOSTS.include? URI(link).host
return "<a href=\"#{link}\" target=\"_blank\">#{link}</a>"
end
"<a href=\"#{linkfilter_path(url: link)}\" target=\"_blank\">#{link}</a>"
end
end

View File

@ -25,3 +25,8 @@ RAW_MARKDOWN_OPTS = {
strikethrough: true,
superscript: false
}
ALLOWED_HOSTS = [
APP_CONFIG['hostname'],
*APP_CONFIG['allowed_hosts']
]

View File

@ -73,5 +73,12 @@ accepted_image_formats:
- image/gif
- .gif
# This list controls which hosts are excempt from the linkfilter
# Note: `hostname` is always included by default
allowed_hosts:
- twitter.com
- youtube.com
- youtu.be
# Sentry connection string
sentry_dsn: ''