Add linkfilter logic to existing renderers
This commit is contained in:
parent
67ee589b5b
commit
02a5e7029e
|
@ -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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class FlavoredMarkdown < Redcarpet::Render::HTML
|
||||
include Rails.application.routes.url_helpers
|
||||
include SharedMarkers
|
||||
|
||||
def preprocess(text)
|
||||
wrap_mentions(text)
|
||||
|
|
|
@ -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
|
|
@ -25,3 +25,8 @@ RAW_MARKDOWN_OPTS = {
|
|||
strikethrough: true,
|
||||
superscript: false
|
||||
}
|
||||
|
||||
ALLOWED_HOSTS = [
|
||||
APP_CONFIG['hostname'],
|
||||
*APP_CONFIG['allowed_hosts']
|
||||
]
|
|
@ -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: ''
|
||||
|
|
Loading…
Reference in New Issue