New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColorizeSyntax filter removes all code with ':pygmentize => { :linenos => :table }' #71

jhelwig opened this Issue Nov 7, 2011 · 5 comments


None yet
3 participants

jhelwig commented Nov 7, 2011

The xpath expression used to clean up the multiply nested pre tags will not match anything when pygmentize is told to use a table for the line numbering (which makes it easier to copy/paste the code without also getting the line numbers).

I was able to get around this with the following diff, but I don't believe that this is actually the best way to go about doing this, nor am I sure what would be.

diff --git i/lib/nanoc/filters/colorize_syntax.rb w/lib/nanoc/filters/colorize_syntax.rb
index 33f7e6f..a1ca9c3 100644
--- i/lib/nanoc/filters/colorize_syntax.rb
+++ w/lib/nanoc/filters/colorize_syntax.rb
@@ -204,7 +204,10 @@ module Nanoc::Filters

       # Clean result
       doc = Nokogiri::HTML.fragment(highlighted_code)
-      doc.xpath('./div[@class="highlight"]/pre').inner_html
+      highlighted = doc.xpath('./div[@class="highlight"]/pre').inner_html
+      highlighted = doc.xpath('./table[@class="highlighttable"]').to_html if highlighted.empty?
+      highlighted


This comment has been minimized.


ddfreyne commented Dec 11, 2011


The problem lies a bit deeper, because nanoc currently assumes that the syntax highlighters always return something that can be wrapped in <pre><code>…</code></pre> which is not the case when Pygments returns a table with line numbers. I’ll have to look into it further.


This comment has been minimized.

jonforums commented Jan 10, 2012

@ddfreyne what do you think is the root issue?

I'm seeing something similar when using coderay and tables for line numbering. Instead of all code being removed, in my case only a portion of the code snippet removed (always at the end) but what code remains is highlighted.

I'm debugging but in my case it also appears dependent upon which flavor of markdown filter (:kramdown, :rdiscount, :redcarpet) I'm using and dependent upon the filter :colorize_syntax location in my compile filter/layout sequence


This comment has been minimized.


ddfreyne commented Jan 10, 2012

@jonforums Are you still experiencing this issue with 3.2.4? It should be fixed now.

There was a fix for this by passing nowrap=True to Pygmentize, which eliminates the need for the xpath magic, so I’ll close this issue, but if you still experience code being removed, feel free to reopen it.

@ddfreyne ddfreyne closed this Jan 10, 2012


This comment has been minimized.

jonforums commented Jan 10, 2012

C:\Users\Jon\Documents\WebDev\>nanoc --version
nanoc 3.2.4 (c) 2007-2012 Denis Defreyne.
Running ruby 1.9.3 (2011-11-08) on i386-mingw32 with RubyGems 1.8.15

I'll check by passing nowrap=true to coderay and reopen if still having problems.


This comment has been minimized.

jonforums commented Jan 10, 2012

This still causes the issue for me:

compile '/posts/*/' do
  filter :rdiscount
  filter :colorize_syntax,
         :coderay => { :line_numbers => :table, :nowrap => true }
  layout 'post'
  filter :erubis
  layout 'default'
  filter :erubis

Don't want to hijack this thread if the issues are different...should I open a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment