Prettify Syntax Highlighting Plugin

Creating and modifying plugins.
Post Reply
akremedy
Regular
Posts: 56
Joined: Sat Jul 26, 2008 9:06 am
Location: Bay Area, U.S.A.
Contact:

Prettify Syntax Highlighting Plugin

Post by akremedy »

If two wasn't enough, I've put together a third option to incorporate syntax highlighting into S9Y by way of Prettify (http://code.google.com/p/google-code-prettify/). Prettify is ultra-basic, but very capable, and at just over 20kb for the core files sent client-side, it is exceptionally lightweight.

In the plugin, I'm providing the option to inject the appropriate class name into all PRE and/or CODE tags found on the page. This means that the author doesn't have to do anything special outside of wrapping their code in PRE or CODE tags, then let Prettify apply best-guess highlighting to the content.

For those who like to maintain control, simply flip the switch off and include the class name (prettyprint) for best-guess highlighting, or specify the code language as part of the class name (prettyprint lang-html) if desired. All of these options, as well as the recognized languages that extend the basic class, are spelled out in the plugin administration page.

You can find the plugin on Sourceforge here: http://php-blog.cvs.sourceforge.net/vie ... l_plugins/, and my notes at http://www.pigslipstick.com/index.php?/ ... -Form.html. As always, feedback/suggestions welcome.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Prettify Syntax Highlighting Plugin

Post by garvinhicking »

Hi!

That's interesting! Do you know the specific things it does better than Geshi and dpsyntaxhighlighter (the currently existing plugins) so that I know which one to recommend? :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
akremedy
Regular
Posts: 56
Joined: Sat Jul 26, 2008 9:06 am
Location: Bay Area, U.S.A.
Contact:

Re: Prettify Syntax Highlighting Plugin

Post by akremedy »

Hi Garvin,
I'd say that dpsyntaxhighlighter probably deserves the recommendation from a feature and completeness point of view, including auto-generated line numbers, good flexibility through native dp configuration (both globally and on a per-code-block basis), and gives that little pop-up utility to put the code block in plaintext or copy it to the clipboard. I should add that I couldn't seem to get dp to function until I upgraded it from the bundled 1.5 version to 2.0. Once I did this, it seemed to mostly work, though the results when using the WYSISYG editor aren't great. As far as dp is concerned, everything is interpreted as being one wrapped line. I'm thinking some configuration work could resolve this.

I spent a some time with Geshi. It ultimately provides most (at least many) of the features of dp, but I'm much more impressed with the concept and execution of dp. I did have the same "one wrapped line" problem as I did with dp.

Prettify is simple, but effective, and it works with no special configuration. If I was going to run a blog that was mostly about coding and showing lots of code snippets, I would try a lot harder to get dp (2.0) working just the way I wanted. As it stands, I actually think that my Prettify plugin (especially with the class injection option) is good enough for most people, most of the time...nothing special to remember or format, just wrap your code in pre tags - simple and light weight, and there is a lot to like about "simple".

I just committed version 1.5 with one small bugfix, but a nice enhancement too - I give the option in the plugin config to put a new button on the basic editor. Now you can drop a block of code between your PRE or CODE tags, select it, and click on the new button to encode all of the angle brackets automatically. Of course the wysiwyg editors are pretty good about doing this already.
Post Reply