Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

PHP numbered code listings

Michael V has written a couple of functions to apply my CSS numbered code listing technique to PHP’s built in syntax highlighting.

This is PHP numbered code listings by Simon Willison, posted on 15th August 2002.

View blog reactions

Next: Today's required reading

Previous: Patented IMBots

4 comments

  1. Yeah I did this a while back but gave up on it because it does weird things in IE. The font tags dont get closed at the end of each list item and while this doesnt cause any problems in Mozilla, in IE it applies the colours to the numbers of the list items.

    R.Livsey - 16th August 2002 12:08 - #

  2. Urgh nasty :( You could probably fix it with some vicious regular expressions but (be good to get rid of the font tags completely and change them in to spans anyway) - could be quite a big job though.

    Simon - 16th August 2002 12:28 - #

  3. :) yeah thats why I left it for the time being. One 'fix' is to syntax highlight line by line. You dont get carry over of font colours onto the numbers, but it also doesn colour multiline comments etc.. I've been milling it over in my head and may do something about it soon, but will probable be a while as I'm soooo busy at the moment! Lets see if someone else comes up with a fix, until then I'm going to leave the line numbers and drob the syntax highlighting.

    R.Livsey - 16th August 2002 23:57 - #

  4. This is a very late reply, but oh well. What could be done: Some regex sorcery to detect which font tags have been opened and left opened at the end of the line, put them on top of a stack to schedule them for re-opening on the next line, close them, and do what's scheduled for each font tag that's still on top of the stack until there's none left. Repeat with each line. I'll leave that as an exercise for the bored reader :P And once you know how to detect the font tags, you might aswell replace them with CSS coloring ;)

    michel v - 10th September 2002 20:04 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2002/08/15/phpNumberedCode

A django site