Codesnippet for WP and GeSHi
Published 1.29.2007 by ~mattg
Because I’ve been writing a few Powershell scripts lately, and posting at least one, I thought it would be nice to get the CodeSnippet plugin for Wordpress to highlight the Powershell syntax. So I went about creating a new language file for GeSHi, which is the underlying syntax highlighter for the plugin. When I got the basics down, I went to test it and it didn’t work like I’d hoped. On a hunch, I tried changing the colors in the GeSHi language file, but it didn’t change the colors on my site. Obviously, the plugin doesn’t work like I’d hoped. So I dug around, and here’s what I found.
As it turns out, the plugin uses the same stylesheet for all the languages, regardless of what is being defined in the GeSHi script. I was annoyed at this at first, but realize that it’s a simple solution the problem that occurs - multiple classes. If you let GeSHi generate the styles for you, it will work, but if you have two languages on the page, there is the possibility that it will generate two classes with the same name and different attributes, at which point you’d get the one that appears later in the html/css. Now, GeSHi does allow you to change the names, so I figured I’d make unique names for every code block being displayed, and all would be right with the world.
As I thought more about it, I realized that is a stupid thing to do, because then every block will have it’s own CSS style block, which may be duplicated if I have more than one code block of the same language (like, 2 C# blocks). So my new solution is to go through the content to figure out what language blocks are there and write out the appropriate styles with the language as a class suffix. Then, when I’m converting the content, each block will have class names with the appropriate suffix. Less style definition on the page, still get to use the GeSHi color definitions, it’s the best of both worlds.
Well, that’s the idea, anyway. Now I just have to find the time to implement it.
Filed under Web Development
hey I just want to say thank you for the great neuron theme you made. I love it !