Friday, May 8, 2009

HTML Syntax Highlighting of Code Snippets

If you're after a utility for generating colorful syntax-highlighted HTML from code snippets, then I've got just the tool you need: GNU source-highlight by Lorenzo Bettini.

It supports more than 60 source languages, and several output formats. It's highlighting is quite well done, if not as accurate as that of Vim or emacs.

The feature which makes it very useful for this blog, is the fact that, by default, it generates plain HTML fragments, with no CSS. These HTML fragments can be pasted as is into a post that's being edited, while in HTML mode.

source-highlight can also be used as a syntax highlighted pager for the console like this:
source-highlight -o STDOUT -f esc /path/to/file 2>/dev/null | less -R

(you may want to take a look at my previous posts about syntax highlighting for paging and listing of source code at the console).

No comments:

Post a Comment