kelvinluck.com

a stroke of luck

Plugin to add GeSHi syntax highlighting to Textpattern – Part II

Update 2:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Update:

see the krl_geshiSyntaxHighlight project page for more information.

…continued from yesterdays post.

EDIT: Please note that the code samples in this look better than they did when I wrote it because I have since updated the engine which generates them (as you will see if you read my other entries) – so when I talk about quotes and underscores and the like being changed into wierd HTML entities it was true!

OK – thanks to some people on the textpattern forums I’ve managed to half fix the problem from yesterday. By placing <notextile> tags around the code in my example I now have the quotes not being changed into strange HTML entities. As you can see here:

  1. function GeSHi ($source, $language, $path = '')
  2. {
  3.   if ($path == '') {
  4.     $path = dirname( __FILE__ ).'/geshi/';
  5.   }

Unfortunately the FILE is still getting translated into first italic tags and then &lt;i&gt;FILE&lt;/i&gt;.

While I was wondering if there was a way to avoid this I came across Johan Nilsson’s glx_code plugin…

How comes I didn’t find it yesterday when I was looking for a way to highlight my code? Oh well – I’ve gone far enough along my path now that I need to complete it! And the way that the glx_code plugin works gave me an idea. It avoids any issues with textile by loading the file with the code sample in rather than by having it included inside the page (as my approach did). So I thought I would add the option to do this to my plugin. And here is the result marking up the above bit of code:

  1. function GeSHi ($source, $language, $path = '')
  2. {
  3.   if ($path == '') {
  4.     $path = dirname( __FILE__ ).'/geshi/';
  5. }

Sweet – that seems to work nicely :D I’m not sure it is a perfect solution because it requires creating a file on my server for each code snippet I want to highlight but it is at least functional. I’ll leave it like that for now and see if I can find a way to get the contents of the tag without textile getting it’s grubby mits on it first!

And I’ll be back soon with another installment which will hopefully contain the final plugin and instructions for it’s use…

No Comments, Comment or Ping

Reply to “Plugin to add GeSHi syntax highlighting to Textpattern – Part II”