Posting code examples

When bloging about PostgreSQL and programming I often want to post code examples. The platform I'm using doesn't support automatic syntax highlightning (and sometimes I want to create a stand alone HTML page with syntax highlightning too).

Since I use Vim as my editor I make use of the command :TOhtml.

I find it convinient to make use of the CSS type of conversion insted of the default one and then just copy the contents of the body from the converted text to my blog entry. I already have my own settings for the code highlight in my own style.css.

I also finds it very useful to use TOhtml on conjunction with visual mode to convert only a part of a source to HTML.

Working from the command line is also an option. Example:

$ vim -c 'TOhtml' -c 'wqa' myscript.sql

The above exampel generates a file myscript.sql.html.

Finally an example of a highlighted file:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Say hello to the world.
"""

if __name__ == '__main__':
    print "Hello World!"

# vi: set fileencoding=utf-8 :

Kommentarer

Kommentera inlägget här:

Namn:
Kom ihåg mig?

E-postadress: (publiceras ej)

URL/Bloggadress:

Kommentar:

Trackback
RSS 2.0