Properly escape HTML in code blocks

lolsob-rspec
Thibaut Girka 2019-05-17 10:43:17 +02:00 committed by ThibG
parent 7aece1eec5
commit 3d03d084cd
1 changed files with 11 additions and 1 deletions

View File

@ -5,13 +5,23 @@ require_relative './sanitize_config'
class HTMLRenderer < Redcarpet::Render::HTML
def block_code(code, language)
"<pre><code>#{code.gsub("\n", "<br/>")}</code></pre>"
"<pre><code>#{encode(code).gsub("\n", "<br/>")}</code></pre>"
end
def autolink(link, link_type)
return link if link_type == :email
Formatter.instance.link_url(link)
end
private
def html_entities
@html_entities ||= HTMLEntities.new
end
def encode(html)
html_entities.encode(html)
end
end
class Formatter