Another attempt at PHP syntax highlighting

So this is an illustration of Posterous’ markdown tag. Lets see how we go:

Well, starters, if I include a link to the markdown help page on the text of the word markdown above, then that’s it. End of post. Bit shit really.Here’s the link pasted in plain text. Will it break again?

No. Was the parser getting confused by the word markdown being in the href attribute of the A tag? or by the word markdown being in the middle of the A and /A tags? That is possible – an overly greedy Regex could confuse {a}markdown{/a} with {markdown}, or something along those lines.Anyway, on with the syntax highlighting.See here for my first attempt: here’s the code with syntax highlighting:

strip_html_tags() Function

Well, this is still being mangled badly.

The trick to getting Syntax highlighting is to precede all code lines with two tab characters. My booboo – failed to spot that.

This causes problems in itself though – if you send post with a plain text email, line breaks will be introduced, which will break code and be missing the tabs for formatting on the new lines.

There should be 36 lines of code above, but due to the Posterous parser introducing html comment tags all over the shop, you can’t see most of it. Well, for now, some code simply can not be posted it would seem.

Get the original code courtesy of:

The code is covered by the OSI BSD license so you can use, modify,redistribute, and sell as you see fit.

5 thoughts on “Another attempt at PHP syntax highlighting”

  1. Is the syntax highlighting completely broke today? I can’t get one single post with simple java code to highlight correctly. It’ll highlight only one line of the entire code. Ugh! Been trying for an hour to get it to work.

  2. No worries, glad it help. I notice Outlook’s stupid HTML is causing isues with comment replies by email. Another one to pass the team…

  3. Seems OK to me – you can see some HTML and PHP highlighting in action on this post:
    Make sure you indent your code declaration with two tabs, and every line of the code.
    I have found actually that you can indent just the first line of the code with two tabs, and the rest with one. With two tabs it tends to indent the following lines one extra tab. Bit odd.
    Drop a line to – I found them to be very helpful, and keen to get things working just right.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *