1
Fork 0
blog/_posts/2011-09-02-kramdown-test.md

54 lines
1.5 KiB
Markdown
Raw Normal View History

2017-07-09 12:18:22 +00:00
extends: post.liquid
2011-09-02 19:36:01 +00:00
title: now with code higlighting
2017-07-09 12:18:22 +00:00
date: 02 Sep 2011 00:00:00 +0100
path: /:year/:month/:day/kramdown-test
2011-09-02 19:36:01 +00:00
---
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](http://daringfireball.net/projects/markdown/) parsing and [coderay][] for the highlighting. Then enable both in your configuration.
This is my current _[_config.yml](https://github.com/badboy/fnordig.de/blob/master/_config.yml)_:
2013-11-06 11:46:19 +00:00
~~~yaml
paginate: 5
permalink: pretty
exclude: Rakefile
markdown: kramdown
kramdown:
use_coderay: true
coderay:
coderay_line_numbers:
coderay_tab_width: 2
coderay_css: class
~~~
2011-09-02 19:36:01 +00:00
If you use `coderay_css: class` make sure to include a CSS file on your page (see my [coderay.css](/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:
2013-11-06 11:46:19 +00:00
~~~ruby
module CodeRay
def about
[self.name.downcase, 'rocks!'].join(" ")
end
module_function :about
end
~~~
2011-09-02 19:36:01 +00:00
And that's it.
[coderay-github]: https://github.com/rubychan/coderay
[coderay]: http://coderay.rubychan.de/
[jekyll]: https://github.com/mojombo/jekyll
[kramdown]: https://github.com/gettalong/kramdown