WordPress Plugin for Google Syntax Highlighter

I am a big fan of the source code highlighter used by the Waffle project. Michael Ward recommended it for me to use when I set my blog up a few weeks ago.

Screenshot

The highlighter itself is simple to use on its own - it’s just a javascript include but I had been using another code highlighter which had a WordPress plugin that made it’s use a snap.

I figured it wouldn’t be too hard to create a plugin for the syntax highlighter (which had larger language support including ruby which I needed) and so I did. The plugin is being hosted by WordPress and I encourage you all to take a look and use in your own blogs.

Google Syntax Highlighter for WordPress

25 Responses to “WordPress Plugin for Google Syntax Highlighter”

  1. Josh G Says:

    Thanks Peter - this is gold!

  2. Menekali Says:

    This doesn’t seem to work with 2.3. I’ve installed, activated, and input even the test syntax you have posted, and, it just doesn’t do anything… at all. :( Looked awesome too :(

  3. flu Says:

    hi,

    nice plugin and it works with 2.3,

    but: your plugin writes class=”javascript” in the script tags. this is wrong and produces an xhtml validation error.

    see: http://www.validome.org/validate/?uri=http://www.peterryan.net

    it would be better if you use the attribute type instead of class for script tags.

  4. The Definitive Guide on Wordpress Syntax Highligher Plugins - Cagintranet Web Design Says:

    […] | Author: Peter Ryan Coloring: #4 of 8 Ease of Install/Use: #7 of 8 Line Numbers: Optional PRE or CODE: PRE Other […]

  5. Kévin Dunglas Says:

    Very nice plugin !

    I’ve made some small changes to your HTML markup to get it W3C valid. You can get the modified version here : http://lapin-blanc.net/downloads/google_syntax_highlighter.phps

    With this patch, only the plugin markup will be valid, the core JS code always require to use which is invalid.

    Please include my changes in trunk :P

  6. Darko Bunic Says:

    Hi Peter,
    I use it on my site and it works very nice. I also made few changes to load only brushes that are needed and move load of JavaScript files to the top of HTML page.

    Thank you for your plugin!

  7. Rashed Says:

    Thanks a lot.

  8. Strudel Says:

    Thanks a lot for this plugin.

    One request though. Brush for bash shell script would be really cool feature.

  9. Strudel Says:

    I’ve added bash brush to the plugin. You can get the extended version of the plugin from here

    http://tech.xlab.si/wp-content/uploads/google-syntax-highlighter-with_bash-151.zip

    Thanks a lot to bboy.mr.freeze.

  10. Azrael-Sub7 Says:

    The plugin crack’s the html validation !
    In the function hooked up to the footer you should be use this

  11. A concerned citizen Says:

    FYI…
    Your example on the installation page of your plugin page has a typo.
    http://wordpress.org/extend/plugins/google-syntax-highlighter/installation/
    It is missing the equal sign between class and “ruby”

  12. Simon Says:

    Hi Peter,

    I vote for the HTML W3C bug discovered by various people earlier in your comments. Please change the class=”javascript” to type=”text/javascript” in your script declarations and republish the plugin.

    Anyway, thank you for the plugin,

    Simon

  13. Wordpress Syntax Highligher Plugins | Gareth Murran blogger Says:

    […] After looking at a few of the recent smashing magazine posts and specifically 10 killer wordpress hacks I decided it was time to look into Wordpress Syntax Highligher Plugins. A quick Tweet later and I had a fantastic round-up from Chris Cagle who runs a small web company. Amazing list ad to have all the work done and a test below to prove it works. I went with the solution from Peter Ryan of Google. […]

  14. Sam Says:

    I found, by default, the rendered code is padded by wordpress, creating gaps between the lines. I found adding the entry below to the main style.css page, it resolved the issue. There might be a way to do this from the plugin’s css, but this won’t affect anything else so it should be ok.

    html > body .entry .dp-highlighter li {
    margin:0;
    }

  15. suzanne huffman Says:

    2sdkUI Nice post. Thanks for sharing. You can watch live steraming soccer tv in my blog. Thanks,

  16. KingC Mui Says:

    Cool Info, practical.. lol,

  17. Michael P. Says:

    Doesnt work anymore =(
    Are you going to upgrade your script? Maybe i could also do this job and take over the project

  18. Nazar Says:

    thanks for useful post.

  19. robl Says:

    This plugin seems pretty bust now, wordpress by default strips the name and class attributes from pre tags meaning without overriding some defaults with a custom plugin or a hack it’s pretty useless.

  20. onykage Says:

    plugin works just fine for me, I think the “strip” part your talking about is because you are trying to use xml tags under the “visual” editer and not the “html” part. This will ofcourse automatically format and strip out the tag. Also you may need to diable the auto fix xhtml option in the general tab.

    I did however find a bug in the css on line 113, the attribute “text-align1″ should be text-align me tinks. Ive also added several custom languages to the highlighter syntax libs, you can check out http://superscriptz.com to see the script in working action.

  21. smith Says:

    hello i love to move and im looking for a good website to learn how to break dance

  22. Vic Says:

    the plugin works fine for firefox and google chorme, but it doesn’t work on IE8.
    WordPress2.9+plugin1.5.1
    Error info:
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)
    time: Sun, 27 Dec 2009 03:33:21 UTC

    Message: ‘this.regexList[…].regex’ is null or not an object
    Row: 173
    character: 1
    code: 0
    URI: ^/wp-content/plugins/google-syntax-highlighter/Scripts/shCore.js

  23. wordpress seo Says:

    Thank you for your plugin!

  24. adi imam pratomo Says:

    Love this post! Thanks for this. I’ll be sure to come back again. P.S: I’ve bookmark your site as well

  25. Wordpress Plugin: Syntax Highlighter – PHP/Javascript Code darstellen | Style, Syntax, Highlighter, Einstellungen | sohneinesschwaben.de Says:

    […] Plugins. Sucht man auf Wordpress.org nach “syntax” spuckt es WP-Syntax Colorizer, Google Syntax Highlighter for WordPress, Easy Google Syntax Highlighter und Syntax Highlighter and Code Colorizer for Wordpress […]

Leave a Reply