I’ve since long wanted a place I can toss my programming related nuggets at. Every day I feel I solve something that I’ll surely hit again in a not so distant future, but by then I most certainly will have forgotten about the previous solution I came up with.
So I need to blog it down, quick and dirty, for my own documentation and memory’s sake.
- Must be easy to set up and use.
- Must handle code syntax and highlighting gracefully for a number of languages, but mainly C# and C++.
- Must be PHP-based, because that’s what my host supplies.
I know and have used WordPress (not for code, though), but is it really what I want or need?
I’ve always used WordPress for this and have had great results. If you go that route, there are two syntax highlighter plugins in particular I’d recommend looking into.
Syntax Highlighter Evolved
http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/
This one uses square brackets ([ ]) to denote your code blocks and provides line numbering, but you have to use the “copy to clipboard” or “view source” buttons it generates when copying more than one line of code, otherwise the line numbers get copied too. It’s uses the SyntaxHighlighter Javascript package for the code highlighting.
Sample syntax
[css].foo {bar:'baz';}[/css][sourcecode language="plain"]your code here[/sourcecode]
WP-Syntax
http://wordpress.org/extend/plugins/wp-syntax/
WP-Syntax – my highlighter of choice for WordPress – uses <pre> tags to signify blocks of code. Like Syntax Highlighter Evolved, it also offers line numbering options, but with the distinct difference that the line numbers don’t get selected when copying/pasting from code examples. WP-Syntax uses GeSHi for its highlighting.
Sample syntax
<pre lang="php">
$debug = print_r($foo, true);
$debug .= print_r($bar, true);
echo '<pre>' . $debug . '</pre>';
</pre>