Ultraviolet gives new life to Syntax highlighting

Posted by Michael on February 5, 2009 in General, Programming

I am tired of Google’s Syntax highlighter.  If I accidentally switch to Visual mode in the editor and do some edits and switch back to HTML mode, then I lose the class=”code” moniker and I have to go through the entire post and fix.

Another drawback I have with Google Syntax highlighter is that the page renders without highlighting and then all the code listings change to syntax highlighted text a few moments later.

Introducing Ultraviolet, a syntax highlighter supporting over 50 syntaxes and any TextMate theme.  Ultraviolet is based on Oniguruma, a regular expression library that comes standard with Ruby 1.9. Ultraviolet requires a little more effort for me to cut and paste, but I am definitely much happier with the end results and Wordpress no longer mungs my posts. Only real complaint I have is that I can’t read the posted code inline in HTML format (but I can read it in Visual mode!).

Ruby Script

   1  require 'rubygems'
   2  require 'ramaze'
   3  require 'maruku'
   4  require 'sequel'
   5 
   6  $LOAD_PATH.unshift(__DIR__)
   7 
   8  require 'env'
   9 
  10  require 'vendor/flickr'
  11  require 'vendor/haml_maruku_filter'
  12  require 'vendor/image_science_cropped_resize'
  13 
  14  require 'model/init'
  15  require 'controller/init'
  16 
  17  require 'db/init' if SOCIAR.mode == :dev
  18 
  19  r = SOCIAR.ramaze
  20 
  21  =begin
  22  if r.gzip
  23    require 'ramaze/contrib/gzip_filter'
  24    gzip = Ramaze::Filter::Gzip
  25    gzip.trait :threshold => 1
  26    Ramaze::Dispatcher::Action::FILTER << gzip
  27  =end
  28 
  29  Ramaze.start :adapter => r.adapter,
  30               :host => r.host,
  31               :port => r.port,
  32               :boring => r.boring

Shell Script

   1  #!/bin/sh
   2 
   3  ### BEGIN INIT INFO
   4  # Provides:          lm-sensors
   5  # Required-Start:    $local_fs
   6  # Required-Stop:
   7  # Default-Start:     S
   8  # Default-Stop:
   9  # Short-Description: lm-sensors
  10  # Description:       hardware health monitoring
  11  ### END INIT INFO
  12 
  13  . /lib/lsb/init-functions
  14 
  15  [ -f /etc/default/rcS ] && . /etc/default/rcS
  16  PATH=/bin:/usr/bin:/sbin:/usr/sbin
  17  PROGRAM=/usr/bin/sensors
  18 
  19  test -x $PROGRAM || exit 0
  20 
  21  case "$1" in
  22    start)
  23  	log_begin_msg "Setting sensors limits"
  24  	if [ "$VERBOSE" = "no" ]; then
  25  		/usr/bin/sensors -s 1> /dev/null 2> /dev/null
  26  		/usr/bin/sensors 1> /dev/null 2> /dev/null
  27  	else
  28  		/usr/bin/sensors -s
  29  		/usr/bin/sensors > /dev/null
  30  	fi
  31  	log_end_msg $?
  32  	;;
  33    stop)
  34  	;;
  35    force-reload|restart)
  36  	$0 start
  37  	;;
  38    *)
  39  	log_success_msg "Usage: /etc/init.d/sensors {start|stop|restart|force-reload}"
  40  	exit 1
  41  esac
  42 
  43  exit 0

Apache Config

   1  <VirtualHost *:80>
   2  	ServerName www.stinger.local
   3  	ServerAdmin webmaster@localhost
   4 
   5  	DocumentRoot /var/www/
   6  	<Directory />
   7  		Options FollowSymLinks
   8  		AllowOverride None
   9  	</Directory>
  10  	<Directory /var/www/>
  11  		Options Indexes FollowSymLinks MultiViews
  12  		AllowOverride None
  13  		Order allow,deny
  14  		allow from all
  15  	</Directory>
  16 
  17  	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  18  	<Directory "/usr/lib/cgi-bin">
  19  		AllowOverride None
  20  		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  21  		Order allow,deny
  22  		Allow from all
  23  	</Directory>
  24 
  25  	ErrorLog /var/log/apache2/error.log
  26 
  27  	# Possible values include: debug, info, notice, warn, error, crit,
  28  	# alert, emerg.
  29  	LogLevel warn
  30 
  31  	CustomLog /var/log/apache2/access.log combined
  32 
  33      Alias /doc/ "/usr/share/doc/"
  34      <Directory "/usr/share/doc/">
  35          Options Indexes MultiViews FollowSymLinks
  36          AllowOverride None
  37          Order deny,allow
  38          Deny from all
  39          Allow from 127.0.0.0/255.0.0.0 ::1/128
  40      </Directory>
  41 
  42  </VirtualHost>
blog comments powered by Disqus

More

Read more posts by Michael

About the Author

A software developer and network engineer for over 25 years. Currently developing Microsoft Windows desktop applications with Delphi and web services with Ruby, Ruby on Rails, Ramaze and Javascript. Web services are hosted on CentOS and Ubuntu servers under either Xen or VMWare powered via Apache, passenger, mysql and postgresql.