From f98cfb59d2a362294873f9fa87bd78e5119afd9e Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Sun, 27 Dec 2020 01:19:09 +0700 Subject: [PATCH] Move constant from initializer to app/lib/constants (#12034) --- app/labor/markdown_parser.rb | 10 +++++----- app/lib/constants/redcarpet.rb | 15 +++++++++++++++ app/liquid_tags/reddit_tag.rb | 2 +- config/initializers/redcarpet.rb | 11 ----------- 4 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 app/lib/constants/redcarpet.rb delete mode 100644 config/initializers/redcarpet.rb diff --git a/app/labor/markdown_parser.rb b/app/labor/markdown_parser.rb index 97297c715..0f2480db8 100644 --- a/app/labor/markdown_parser.rb +++ b/app/labor/markdown_parser.rb @@ -20,7 +20,7 @@ class MarkdownParser def finalize(link_attributes: {}) options = { hard_wrap: true, filter_html: false, link_attributes: link_attributes } renderer = Redcarpet::Render::HTMLRouge.new(options) - markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG) + markdown = Redcarpet::Markdown.new(renderer, Constants::Redcarpet::CONFIG) catch_xss_attempts(@content) escaped_content = escape_liquid_tags_in_codeblock(@content) html = markdown.render(escaped_content) @@ -55,7 +55,7 @@ class MarkdownParser return if @content.blank? renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false) - markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG) + markdown = Redcarpet::Markdown.new(renderer, Constants::Redcarpet::CONFIG) allowed_tags = %w[strong abbr aside 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 kbd] allowed_attributes = %w[href strong em ref rel src title alt class] @@ -68,7 +68,7 @@ class MarkdownParser return if @content.blank? renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false) - markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG) + markdown = Redcarpet::Markdown.new(renderer, Constants::Redcarpet::CONFIG) allowed_tags = %w[strong i u b em p br code] allowed_attributes = %w[href strong em ref rel src title alt class] ActionController::Base.helpers.sanitize markdown.render(@content), @@ -80,7 +80,7 @@ class MarkdownParser return if @content.blank? renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false) - markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG) + markdown = Redcarpet::Markdown.new(renderer, Constants::Redcarpet::CONFIG) allowed_tags = %w[strong i u b em code] allowed_attributes = %w[href strong em ref rel src title alt class] ActionController::Base.helpers.sanitize markdown.render(@content), @@ -92,7 +92,7 @@ class MarkdownParser return if @content.blank? renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false) - markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG) + markdown = Redcarpet::Markdown.new(renderer, Constants::Redcarpet::CONFIG) allowed_tags = %w[strong abbr aside em p h4 h5 h6 i u b code pre br ul ol li small sup sub a span hr blockquote kbd] allowed_attributes = %w[href strong em ref rel src title alt class] diff --git a/app/lib/constants/redcarpet.rb b/app/lib/constants/redcarpet.rb new file mode 100644 index 000000000..f9a8edfe1 --- /dev/null +++ b/app/lib/constants/redcarpet.rb @@ -0,0 +1,15 @@ +module Constants + module Redcarpet + CONFIG = { + autolink: true, + no_intra_emphasis: true, + fenced_code_blocks: true, + lax_html_blocks: true, + lax_spacing: true, + strikethrough: true, + superscript: false, + tables: true, + footnotes: true + }.freeze + end +end diff --git a/app/liquid_tags/reddit_tag.rb b/app/liquid_tags/reddit_tag.rb index ebde37a4b..209948cc5 100644 --- a/app/liquid_tags/reddit_tag.rb +++ b/app/liquid_tags/reddit_tag.rb @@ -54,7 +54,7 @@ class RedditTag < LiquidTagBase end def parse_markdown_content(content) - markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTMLRouge, REDCARPET_CONFIG) + markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTMLRouge, Constants::Redcarpet::CONFIG) text = markdown.render(content) sanitize(HTML_Truncator.truncate(text, 60)) diff --git a/config/initializers/redcarpet.rb b/config/initializers/redcarpet.rb deleted file mode 100644 index 09702983a..000000000 --- a/config/initializers/redcarpet.rb +++ /dev/null @@ -1,11 +0,0 @@ -::REDCARPET_CONFIG = { - autolink: true, - no_intra_emphasis: true, - fenced_code_blocks: true, - lax_html_blocks: true, - lax_spacing: true, - strikethrough: true, - superscript: false, - tables: true, - footnotes: true -}.freeze