Highlighting code on WordPress
I must have tried every single plugin for source code highlighting, and none of them can handle templates in C++!
Well, one of them could, the google syntax highlighter could, but the image it creates is uglier than ugly.
This is really pissing me off. How hard can it be not to fuck up < and >? Or if you want to consider them tags, then not to fuck up < and >?
I’m giving up now and sticking to good old <pre>…</pre>. It isn’t pretty, but at least it shows the code I want to show, not some mangled piece of crap!
–
20-35=-15
January 20th, 2009 at 11:54 pm
Are you sure you can’t modify the css for the google syntax highlighter, to make it look a way you like?
January 21st, 2009 at 6:24 am
I might be able to. I don’t know. By the time I got to google syntax highlighter I was sufficiently pissed off that I didn’t bother trying to fiddle with it, but just moved on to the next plug in …
January 25th, 2009 at 9:08 pm
That’s simply because C++ template syntax is very complicated and non-trivial to parse. Everytime someone here is stumped by his or her inability to understand what the compiler is trying to tell him or her, I advise them to have a look at the C++ FQA, e.g.:
http://yosefk.com/c++fqa/ctors.html#fqa-10.19
That doesn’t necessarily make people better at programming in C++, but at least potentially happier and less confused programmers when it comes to reasonable expections of what C++ can do for them.
January 26th, 2009 at 6:41 am
Thomas:
I don’t think it is necessary to do any parsing of the C++ to highlight it. I agree that parsing templates is non-trivial, but not that it is needed at all for this.
I wrote my own highlighter (as a GTK+ widget) many years ago, and I never needed more than a bit of regexp matching for comments and strings and simple word recognition for keywords.
As for the FAQ item, I appreciate the link, but I am not really confused by that particular problem any more, having run into it more than once in the past :)
It is one of the more confusing errors to run into, though, similar to the typename issue I wrote about a few days ago.