lib/devcenter-parser/github_parser.rb in devcenter-parser-2.2.1 vs lib/devcenter-parser/github_parser.rb in devcenter-parser-2.2.2rc1
- old
+ new
@@ -1,9 +1,31 @@
module GitHubParser
extend self
class HTMLWithPantsRenderer < Redcarpet::Render::HTML
include Redcarpet::Render::SmartyPants
+
+ def block_code(code, language)
+ %{\n<pre><code class="lang-#{language}">#{html_escape(code)}</code></pre>\n}
+ end
+
+ private
+
+ # This is a method copy/pasted from redcarpet/lib/redcarpet.rb
+ # It's a private instance method on the Render::Safe class which inherits
+ # from the HTML renderer.
+ # I'm not sure why our tests expect escaped code while we inherit from the
+ # HTML renderer and not the Safe renderer though.
+ def html_escape(string)
+ string.gsub(/['&\"<>\/]/, {
+ '&' => '&',
+ '<' => '<',
+ '>' => '>',
+ '"' => '"',
+ "'" => ''',
+ "/" => '/',
+ })
+ end
end
def self.parse(markdown)
html = github_parser.render(markdown.to_s)
doc = Nokogiri::HTML::DocumentFragment.parse(html)