Move HTMLRouge into lib (#403)

* Move HTMLRouge into lib

* Fix lint
This commit is contained in:
Mac Siri 2018-06-12 16:53:58 -04:00 committed by Ben Halpern
parent 75c912c593
commit 8d36c74d3c
4 changed files with 20 additions and 16 deletions

View file

@ -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

View file

@ -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)

View 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

View file

@ -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,