Permalink
Browse files

Added line number capabilities to highlight blocks

  • Loading branch information...
1 parent 94c06d0 commit d63f1f92a2f859b631d1d26ef87840fb56c60f33 @jcon jcon committed Jan 22, 2009
Showing with 31 additions and 4 deletions.
  1. +16 −1 README.textile
  2. +15 −3 lib/jekyll/tags/highlight.rb
View
@@ -331,11 +331,26 @@ The argument to <code>highlight</code> is the language identifier. To find the
appropriate identifier to use for your favorite language, look for the "short
name" on the "Lexers":http://pygments.org/docs/lexers/ page.
+There is a second argument to <code>highlight</code> called
+<code>linenos</code> that is optional. Including the <code>linenos</code>
+argument will force the highlighted code to include line numbers. For instance,
+the following code block would include line numbers next to each line:
+
+<pre>
+{% highlight ruby linenos %}
+def foo
+ puts 'foo'
+end
+{% endhighlight %}
+</pre>
+
In order for the highlighting to show up, you'll need to include a
highlighting stylesheet. For an example stylesheet you can look at
"syntax.css":http://github.com/mojombo/tpw/tree/master/css/syntax.css. These
are the same styles as used by GitHub and you are free to use them for your
-own site.
+own site. If you use linenos, you might want to include an additional CSS class
+definition for <code>lineno</code> in syntax.css to distinguish the line numbers
+from the highlighted code.
h2. Categories
@@ -2,10 +2,22 @@ module Jekyll
class HighlightBlock < Liquid::Block
include Liquid::StandardFilters
+ # we need a language, but the linenos argument is optional.
+ Syntax = /(\w+)\s?(:?linenos)?\s?/
- def initialize(tag_name, lang, tokens)
+ def initialize(tag_name, markup, tokens)
super
- @lang = lang.strip
+ if markup =~ Syntax
+ @lang = $1
+ if defined? $2
+ # additional options to pass to Albino.
+ @options = { 'O' => 'linenos=inline' }
+ else
+ @options = {}
+ end
+ else
+ raise SyntaxError.new("Syntax Error in 'highlight' - Valid syntax: highlight <lang> [lineno]")
+ end
end
def render(context)
@@ -17,7 +29,7 @@ def render(context)
end
def render_pygments(context, code)
- "<notextile>" + Albino.new(code, @lang).to_s + "</notextile>"
+ "<notextile>" + Albino.new(code, @lang).to_s(@options) + "</notextile>"
end
def render_codehighlighter(context, code)

0 comments on commit d63f1f9

Please sign in to comment.