I have seen some very well written blogs out on the interwebs which include clean and well highlighted example code inline with the rest of the document. Turns out it is really easy to implement in WordPress. I browsed around and found a nice comparison of different syntax highlighting tools and settled on the Google Syntax Highlighter. Here is the comparison review.
Getting the Code
You can get the latest version as a WordPress plugin either by searching for “Syntax Highlighter” in the plugins admin page for WordPress, or you can download from the WordPress site.
Usage
Just surround your code like this:
<pre class="brush:[code-alias]"> …Your Code Here </pre>
replace the "[code-alias]" segment with the type of code you have. See all the available brush aliases at the plugin author's website. For Example, PHP would be like this:
<pre class="brush:php"> …Your PHP Code Here </pre>
Examples
SQL
SELECT count(1) FROM some_table WHERE some_field = 'some value';
C
#include
main()
{
printf("hello, world\n");
}
Python
#!/usr/bin/python print 'Hello World!'
Post a Comment