diff options
author | http://jneen.net/ <jneen@jneen.net> | 2016-06-17 02:05:53 +0300 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2016-07-14 20:08:15 +0300 |
commit | 362d7fde084d0e9eeeeea0c78c2f455c6e86a35b (patch) | |
tree | af8a2b6c6f1e35045eec3ae0e8d930d26ab7c903 /lib/banzai | |
parent | e9f191907cb9c9d03b5ad0b67bd3e114f2111a18 (diff) |
bugfix: don't error in css_classes
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/syntax_highlight_filter.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index 144d8c175dc..17f9164bcb7 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 = %<<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) |