new post: now with code highlighting
This commit is contained in:
parent
af1753bad4
commit
ee97db037e
50
_posts/2011-09-02-kramdown-test.markdown
Normal file
50
_posts/2011-09-02-kramdown-test.markdown
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
---
|
||||||
|
layout: post
|
||||||
|
title: 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](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)_:
|
||||||
|
|
||||||
|
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](/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.
|
||||||
|
|
||||||
|
[coderay-github]: https://github.com/rubychan/coderay
|
||||||
|
[coderay]: http://coderay.rubychan.de/
|
||||||
|
[jekyll]: https://github.com/mojombo/jekyll
|
||||||
|
[kramdown]: https://github.com/gettalong/kramdown
|
Loading…
Reference in a new issue