boakes.org

syntax highliting in wordpress

i’ve coded on many systems over many years, starting on the ZX81 in 1981. it’s surprising how over the last 10 years or so, code highlighting has become the norm – i take it for for granted. times have changed since those days on the sinclair and acorn machines where blocky white capitals glared fuzzily out of a black television screen.

i know i must have done it, but try as i might i cannot remember ever looking at monochrome java code. last night, when i pasted some java into a short note on my site, i was shocked that i hardly recognized it. so i resolved to find a highlighter.

one quick search and install later and i’ve added Amit Gupta‘s syntax highlighting plugin (2.0 preview) to my wordpress this morning so that java and other code snippets can be presented more understandably.

the plugin is all php and seems to work very nicely, though (obviously) i’ve immediately had a few ideas for enhancements…

  1. the plugin’s not too hard to install, though there is a little tweaking which might be avoidable through judicious use of [php]$_SERVER['DOCUMENT_ROOT'];[/php].
  2. the default behaviour places the generated code in a small box with scrollbars – this is controlled by css, but that css is hard-coded into the plugin php – so when i upgrade the plugin, i have to re-edit the css. moving it out of the php would make sense since the user can then decide how they want their code framed, and maintain this across versions.
  3. i’d like the plugin to recognize if both the open and close tags are on the same line – in those cases it should not insert the list so that examples like the ‘document_root’ one above just flow with the rest of the text.
  4. In this example entry, before the code, the word “JAVA:” appears. This should be optional.
  5. I had to insert the [ java ] tag on the first and last code lines (rather than the lines above and below them) so as not to create a blank numbered line, it would be nice if the code could strip leading and trailing blanks.

These are only small ideas for enhancement based on my first impression of how I’d expect such a plugin to work, and as the plugin approaches the 2.0 release and beyone, i hope i’ll see some of them included. THanks for a nifty plugin Amit.