2010
07.24

I wanted to have syntax highlighting for a big SQL file I was working on. Finding a solution didn’t take my too long. Source-highlight given a source file, produces a document with syntax highlighting. Output formats that are supported:

  • HTML
  • XHTML
  • LATEX
  • TEXINFO
  • ANSI
  • DocBook

Input formats that are supported:

  • Ada
  • Asm
  • Applescript
  • Awk
  • Autoconf files
  • Bat
  • Bib
  • Bison
  • C/C++
  • C#
  • CakePhp templates
  • Clipper
  • Cobol
  • Configuration files (generic)
  • Caml
  • Changelog
  • Css
  • D
  • Diff
  • Erlang
  • errors (compiler output)
  • Flex
  • Fortran
  • GLSL
  • Haskell
  • Haskell literate programming
  • Haxe
  • Html
  • ini files
  • Java
  • Javascript
  • KDE desktop files
  • Latex
  • Ldap files
  • Lisp
  • Logtalk
  • Log files
  • lsm files (Linux Software Map)
  • Lua
  • Makefile
  • Manifest
  • M4
  • ML
  • Oz
  • Pascal
  • Perl
  • pkg-config files
  • PHP
  • Postscript
  • Prolog
  • Properties files
  • Protobuf (Google’s Protocol Buffers)
  • Python
  • RPM Spec files
  • Ruby
  • Scala
  • Shell
  • S-Lang
  • Sql
  • Tcl
  • Texinfo
  • Vala
  • VBscript
  • XML
  • XOrg conf files

Exactly what I needed!

For Debian/Ubuntu get source-highlight to work is just as simple as:

apt-get install source-highlight

And adding these two environment variables (to .bashrc):

export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s"
export LESS=' -R '

The result looks like this:

source-highlight SQL file

source-highlight SQL file

Be sure this line isn’t present in your .bashrc because it will interfere with source-highlight:

[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"

For CentOS/Red Hat the procedure will be comparable, but I don’t now for sure if a RPM package of source-highlight is available.

References:

3 comments so far

Add Your Comment
  1. The package name is the same in Fedora 15.

  2. Thanks for pointing that out.

  3. Any way to make this work with “<"?

    I never type "less" if I can type "<".

    I got it working otherwise.