Awesome =D. I could use these stylesheets in my source code viewer: http://61924.wepwnyou.net/p-sourcebrowz0r.html

anonymous user on 6/11/08

Thank you. This helper rocks.

anonymous user on 6/23/08

He Mark, Nice helper! But you use something else? Because of the neat links ‘Show Plain text’? Or is it you own implementation?
thnx again!

anonymous user on 8/9/08

primeminister: No I’m using the helper, I’ve just done some extra work on it. I’ll post an updated file soon.

mark story on 8/13/08

Great helper but maybe using a behavior would be a better approach? You can pass all config data during behavior init (it will enable more settings for different models)

Then, if the code was found in the record you can automatically include specific stylesheet/js in the page header…

anonymous user on 8/25/08

kuba: I disagree with this being a behavior. Behaviors should be handling reusable blocks of model logic code. I don’t think that making code samples in HTML output really falls into that domain. However, I like the idea of being able to set a config array and reuse it.

mark story on 8/31/08

Thanks for the helper, its a vast improvement on my initial hack at a helper.

I have converted your mootools plain text to code toggle to JQuery, if anyone wants it the code is here, http://wiltonsoftware.com/posts/view/geshi-code-to-plain-text-jquery-javascript-toggle.

As a side one thing I noticed with your mootools version was that under IE6-7 if you click on the toggle a number of times the plain text version disappears.

anonymous user on 12/3/08

Awesome work! I used twilight in the programming section of my blog. Had to tweak a few small things but mostly was what I wanted. keep it up :)

Jono on 12/19/08

Hi, Mark.

Thanks for the helper! (I stole your JavaSript, too.) I noticed one minor bug. At line 116 of your Sept. 12 2008 version, the first $code argument should be wrapped in trim(), as it is in the call to set_source() in the following else block.

asciimo on 1/15/09

asciimo: You’re right, I’ve fixed it on github now.

Brett Wilson: This is quite possible. My IE readership is so low I don’t really waste much time testing on it. I’ll look into that when I get a chance though. Thanks for pointing it out :)

mark story on 1/16/09

This article seems to be well designed but I am having trouble trouble getting the helper to work, it’s just spitting out whatever I throw in highlight(), nothing else.

Brian H. on 8/16/09

Brian H: Do your pre blocks have language attributes? Without those the helper doesn’t know what language the code is in, and cannot tell geshi how to highlight it.

mark story on 8/17/09

Thanks! I looked through the tests and it explained that, I think I have a bad Geshi version though. now its giving me errors in the geshi helper itself:

Fatal error: Class ‘GeSHI’ not found in /foo/bar/app/views/helpers/geshi.php on line 116

Brian H, on 8/18/09

thanks a bunch for creating this! the only thing that threw me off was mistakenly downloading geshi 1.1 rather than 1.0.8 (and the methods are quite different with 1.1 of course..!).

josh on 11/23/09

Thank you so much for the Geshi Helper!!

It took a while until I figured out that you have to include the

 block within the text to be highlighted. My favourite example would be: 

echo $geshi->highlight(’

‘);

Anyway – thanks!

xemle on 2/2/10

Thank you so much for the Geshi Helper!!

It took a while until I figured out that you have to include the

block within the text to be highlighted. My favorite (corrected and escaped) example would be:

echo $geshi->highlight(’<pre lang=“php”><?php echo “Geshi Helper Rocks!”; ?></pre>’);

Anyway – thanks!

xemle on 2/2/10

Thanks for the helper Mark, it does the job nicely.

One issue I ran into however (and this is not a fault of the helper) is that the helper would return null when highlighting a long string in PHP >= 5.2.

I found that the cause of this issue is a new setting introduced in 5.2 called pcre.backtrack_limit. This limits the amount of characters PHP will check when using things like non-greedy patterns (as this helper does). The default limit is only 100000 bytes (~97KB) so anything longer than this cannot be highlighted.

I fixed this by adding a constructor to the helper and raising the limit to 1MB there (though obviously this can be done in php.ini etc too).

Obviously earlier verions of PHP are not affected, the internal limit (if there was one) must have been much higher.

Hope this helps someone.

Karl on 2/11/10

Very nice, but this guide is not as clear as it could be. Step by step guides are better so people who doesn’t know that much English can understand them as well.

ram4nd on 7/25/10

Hey Mark!
Great helper. Just one thing. It generates invalid html code.

<div class="code">
the stuff
</div class="code">

<— see?! :D

johann on 12/6/10

lol ^^

it generates <\div class="code"> instead of </div>

johann on 12/6/10