Source Code syntax highlighting plugin for WordPress (V1.2)
Introduction
This WordPress plugin using Geshi to highlight source code in a wide range of popular languages.it aims to be a simple but powerful code highlighting plugin, with the following goals:
- Easy to use.
- Support for a wide range of popular languages.
- Customizable output formats.
Installation
This plugin requires WordPress v.1.5 or later.
- Download Dean’s Code Highlighter v1.2 and unzip it.
- Upload the plugin to your plugin directory (wp-content/plugins).
- Activate the plugin through the ‘Plugins’ menu in WordPress.
- Modify the stylesheet file geshi.css to get the coloring you prefer.
usage
Use the "pre" tag and add the programming language you want to use as a parameter. Example:. < pre lang="php" >your code here … < /pre >. for example: <pre lang="php"> function hello_world(){ echo "hello world" }</pre> after highlighting:
You can see a Living demo at here.
Revision History
- version 1.2 (2007-08-28)
- version 1.1
- Add the ability to strips unwanted tags in your code snippets added by WYSWYG editors.
- version 1.0 initial version
See also
There is another plugin may interest you:Google Code Prettify for wordpress.it’s a javascript syntax highlighter based on Google Code Prettify.
Related posts:
[...] blog so much about code, I finally stopped being lazy and got a code highlighter. I’m using: Dean’s Code Highlighter by Dean Lee. It’s very easy to use and support a range of different code syntax such as PHP and [...]
[...] Dean’s Code Highlighter- nice little plugin for some of us geeks who like to show off and tell you how much better we are than rest of you by pulishing tidbits of code. [...]
[...] Dean's Code Highlighter. Выполняет подсветку блоков кода. К этому плагину у [...]
[...] Strona wtyczki [...]
雁过留痕,我过留脚印….
[...] Dean’s Code Highlighter, pour la coloration syntaxique des bouts de code [...]
[...] will authorize plugins like Source Code syntax highlighting plugin for WordPress or WP-CodeBox to work just perfectly [...]
[...] Dean Lee Code Highlighter WordPress Plugin [...]
Great plugins.
But not works with <pre lang='python'> only with <pre lang="python">
tks…
Hey Dean,
what you've done with this plugin is absolutely fantastic. I'm using WordPress for the first time and I found your plugin very useful . But I want to be a bit more flexible with the line numbers, because sometimes I want to start them at another value than "1". So I've reviewed and enhanced your code a little bit to get this running for me. Since geshi can be initiated with a different line number than "1" I changed following lines in your code:
replaced (in function ch_the_content_filter)
return preg_replace_callback("/<pre\s+.*lang\s*=\"(.*)\">(.*)<\/pre>/siU",
array(&$this, "ch_highlight_code"),
$content);
with
return preg_replace_callback("/<pre\s+.*lang\s*=\"(.*)\"(\s+.*start\s*=\"(.*)\")?>(.*)<\/pre>/siU",
array(&$this, "ch_highlight_code"),
$content);
added in function ch_highlight_code
// start line_number
$start_line_number = $matches[3];
if (!is_numeric($start_line_number)) {
$start_line_number = 1;
}
directly after the global $ch_options; line
and
$geshi->start_line_numbers_at($start_line_number);
after
$geshi = new GeSHi($plancode, strtolower($matches[1]));
and changed $plancode = $matches[2]; to $plancode = $matches[4];
Now I can write the following in the WordPress editor:
<pre lang="php" start="123"><?php
echo "Hello World!\n";
?>
and the first line number will be 123.
cheers!