4

I see some Octopress sites that have no line numbers in their codeblocks. How do you do that? Is there some attribute in {% codeblock %} tag? Or do I have to modify the codeblock plugin source?

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
delta
  • 3,778
  • 15
  • 22

4 Answers4

2

Using blockquotes through 4 space indentation should do what you're looking for, but it'll be without syntax highlighting.

If you're fine with losing line numbers everywhere, you can modify plugins/pygments_code.rb and remove the bit of code that generates line numbers.

bilalq
  • 7,279
  • 3
  • 22
  • 28
  • 1
    Shouldn't you be able to just update the CSS to not display the gutter? – Toby Feb 01 '13 at 09:58
  • 2
    You're absolutely right. You can modify the CSS to achieve the same visual effect (though you'll still have them there in the HTML). `pre.line-numbers { display: none; }` should do it. – bilalq Feb 02 '13 at 05:02
  • Can you provide an example... I'm not sure if you mean the blockquote should be first or the indent should be first. – Anthony Mastrean Jun 10 '15 at 15:10
1

A patch for pygments_code.rb as suggested by bilalq above (sorry, too big to fit in the comments of his answer)

--- a/plugins/pygments_code.rb
+++ b/plugins/pygments_code.rb
@@ -29,11 +29,11 @@ module HighlightCode
     end
     highlighted_code
   end
+
   def tableize_code (str, lang = '')
-    table = '<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers">'
+    table = '<div class="highlight"><table><tr>'
     code = ''
     str.lines.each_with_index do |line,index|
-      table += "<span class='line-number'>#{index+1}</span>\n"
       code  += "<span class='line'>#{line}</span>"
     end
     table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>"
Toby
  • 9,523
  • 8
  • 36
  • 59
1

If you use the kramdown markup engine, it comes with an option you set in your _config.yml file, coderay_line_numbers:

markdown: kramdown
kramdown:
  use_coderay: true
  coderay:
    coderay_line_numbers:
    coderay_css: class

It can be set to nil (as in this example), inline, table or list. Maybe the blogs you have been seeing without line numbers use this method.

You can see some screenshots of the different options in my blog post about kramdown in Octopress.

alestanis
  • 21,519
  • 4
  • 48
  • 67
1

Simply add:

pre.line-numbers { display: none; }

to sass/custom/_styles.scss.

This is from a comment on one of the answers by @bilalq , but I think it's the best, simplest, and most sane answer around (sane as in you want to keep your customizations under sass/custom/).

TheChymera
  • 17,004
  • 14
  • 56
  • 86