1
Fork 0
blog/_posts/2011-09-02-kramdown-test.markdown
2011-09-02 21:36:36 +02:00

1.5 KiB

layout title
post now with code higlighting

I am a programmer and I like to write code and I like to talk about code. That's why this blog really needs some syntax highlighting for my favorite languages.

With jekyll as my static site generator it is easy to enable it. Just get the kramdown library for markdown parsing and coderay for the highlighting. Then enable both in your configuration.

This is my current _config.yml:

paginate: 5
permalink: pretty
exclude: Rakefile
markdown: kramdown
kramdown:
  use_coderay: true

  coderay:
    coderay_line_numbers:
    coderay_tab_width: 2
    coderay_css: class

{:lang="yaml"}

If you use coderay_css: class make sure to include a CSS file on your page (see my coderay.css).

Adding syntax-highlighted code in your post now works like this:

    indent code by 4 spaces
    even multi-line
    and define language after code block
{:lang="ruby"}

{:lang="text"}

And now some real highlighting to show it in action:

module CodeRay
  def about
    [self.name.downcase, 'rocks!'].join(" ")
  end
  module_function :about
end

{:lang="ruby"}

And that's it.