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.

  1. Download Dean’s Code Highlighter v1.2  and unzip it.
  2. Upload the plugin to your plugin directory (wp-content/plugins).
  3. Activate the plugin through the ‘Plugins’ menu in WordPress.
  4. 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:

function hello_world()
{
        echo "hello world";
}

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:

TAGS: , , , , ,


293 Comments »

Finally gave my blog a much needed face lift! « Joey Rivera On January 24th, 2010 at 2:38 am (#)

[...] 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 [...]

20+ WordPress Plugins I Use And Recommed On January 19th, 2010 at 12:39 pm (#)

[...] 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. [...]

29 плагинов для WordPress, которые я использую On January 7th, 2010 at 2:37 am (#)

[...] Dean's Code Highlighter. Выполняет подсветку блоков кода. К этому плагину у [...]

10 najprzydatniejszych wtyczek do Wordpressa | Vivee - wordpress, webmastering, grafika i fotografia On January 5th, 2010 at 8:26 pm (#)

[...] Strona wtyczki [...]

知识 On December 31st, 2009 at 6:01 pm (#)

雁过留痕,我过留脚印….

Wareteam fait peau neuve pour accueillir 2010 | Wareteam On December 30th, 2009 at 10:46 pm (#)

[...] Dean’s Code Highlighter, pour la coloration syntaxique des bouts de code [...]

[Wordpress] It removes pre tag attributes « Blog of a developer On December 16th, 2009 at 8:35 pm (#)

[...] will authorize plugins like Source Code syntax highlighting plugin for WordPress or WP-CodeBox to work just perfectly [...]

Inserting code in your Wordpress blog | Linux Shtuff On December 13th, 2009 at 1:23 pm (#)

[...] Dean Lee Code Highlighter WordPress Plugin [...]

Sérgio Berlotto On December 10th, 2009 at 11:55 pm (#)

Great plugins.
But not works with <pre lang='python'> only with <pre lang="python">
tks…

Matthias On November 3rd, 2009 at 1:38 am (#)

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!


Leave a comment


(will not be published)