Commit 362d7fde authored by http://jneen.net/'s avatar http://jneen.net/

bugfix: don't error in css_classes

parent e9f19190
......@@ -19,8 +19,15 @@ module Banzai
language = node.attr('class')
code = node.text
lexer = Rouge::Lexer.find_fancy(language)
formatter = Rouge::Formatters::HTML.new
css_classes = "code highlight js-syntax-highlight #{lexer.tag}"
begin
highlighted = %<<pre class="#{css_classes}"><code>#{block_code(code, language)}</code></pre>>
highlighted = ''
highlighted << %<<pre class="#{css_classes}"><code>>
highlighted << formatter.format(lexer.lex(code))
highlighted << %<</code></pre>>
rescue
# Gracefully handle syntax highlighter bugs/errors to ensure
# users can still access an issue/comment/etc.
......@@ -31,10 +38,6 @@ module Banzai
replace_parent_pre_element(node, highlighted)
end
def css_classes
"code highlight js-syntax-highlight #{lexer.tag}"
end
private
def replace_parent_pre_element(node, highlighted)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment