parent
75c912c593
commit
8d36c74d3c
4 changed files with 20 additions and 16 deletions
|
|
@ -1,12 +0,0 @@
|
|||
require "rouge/plugins/redcarpet"
|
||||
|
||||
class HtmlRouge < Redcarpet::Render::HTML
|
||||
include Rouge::Plugins::Redcarpet
|
||||
|
||||
def link(link, _title, content)
|
||||
# Probably not the best fix but it does it's job of preventing
|
||||
# a nested links.
|
||||
return nil if /<a\s.+\/a>/ =~ content
|
||||
%(<a href="#{link}">#{content}</a>)
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@ class MarkdownParser
|
|||
|
||||
def evaluate_markdown
|
||||
return if @content.blank?
|
||||
renderer = HtmlRouge.new(hard_wrap: true, filter_html: false)
|
||||
renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false)
|
||||
markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG)
|
||||
tag_whitelist = %w(strong em p h1 h2 h3 h4 h5 h6 i u b code pre
|
||||
br ul ol li small sup sub img a span hr blockquote)
|
||||
|
|
@ -23,7 +23,7 @@ class MarkdownParser
|
|||
|
||||
def evaluate_limited_markdown
|
||||
return if @content.blank?
|
||||
renderer = HtmlRouge.new(hard_wrap: true, filter_html: false)
|
||||
renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false)
|
||||
markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG)
|
||||
tag_whitelist = %w(strong i u b em p br)
|
||||
attribute_whitelist = %w(href strong em ref rel src title alt class)
|
||||
|
|
@ -66,7 +66,7 @@ class MarkdownParser
|
|||
private
|
||||
|
||||
def parse_it
|
||||
renderer = HtmlRouge.new(hard_wrap: true, filter_html: false)
|
||||
renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false)
|
||||
markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG)
|
||||
catch_xss_attempts(@content)
|
||||
escaped_content = escape_liquid_tags_in_codeblock(@content)
|
||||
|
|
|
|||
16
app/lib/redcarpet/render/html_rouge.rb
Normal file
16
app/lib/redcarpet/render/html_rouge.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
require "rouge/plugins/redcarpet"
|
||||
|
||||
module Redcarpet
|
||||
module Render
|
||||
class HTMLRouge < HTML
|
||||
include Rouge::Plugins::Redcarpet
|
||||
|
||||
def link(link, _title, content)
|
||||
# Probably not the best fix but it does it's job of preventing
|
||||
# a nested links.
|
||||
return nil if /<a\s.+\/a>/.match?(content)
|
||||
%(<a href="#{link}">#{content}</a>)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -9,7 +9,7 @@ class DisplayAd < ApplicationRecord
|
|||
private
|
||||
|
||||
def process_markdown
|
||||
renderer = HtmlRouge.new(hard_wrap: true, filter_html: false)
|
||||
renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false)
|
||||
markdown = Redcarpet::Markdown.new(renderer)
|
||||
initial_html = markdown.render(body_markdown)
|
||||
stripped_html = ActionController::Base.helpers.sanitize initial_html.html_safe,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue