diff options
Diffstat (limited to 'lib/banzai/filter/syntax_highlight_filter.rb')
-rw-r--r-- | lib/banzai/filter/syntax_highlight_filter.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index 536b478979f..028edef704b 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -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 = block_code(code, language) + 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. @@ -40,8 +47,7 @@ module Banzai # Override Rouge::Plugins::Redcarpet#rouge_formatter def rouge_formatter(lexer) - Rouge::Formatters::HTMLGitlab.new( - cssclass: "code highlight js-syntax-highlight #{lexer.tag}") + Rouge::Formatters::HTML.new end end end |