testing WP-Syntax
May 17th, 2008 at 8:50 amI’ve installed the WP-Syntax plugin to add syntax highlighting and line numbers to code snippets I post, and this post is a test.
Here’s some C code without line numbers:
for (i = 0; i < 20; ++i) { printf("i is %d\n", i); /* print i */ }
Scheme code with line numbers:
1 2 3 4 | (define (tagged? expr tag) (if (pair? expr) (eq? (car expr) tag) #f)) |
Python code:
1 2 3 4 5 6 7 8 9 | def fib( ): """Unbounded generator for Fibonacci numbers""" x, y = 0, 1 while True: yield x x, y = y, x + y import itertools print(list(itertools.islice(fib( ), 20))) |
Perl code:
my %dict = ( SENTENCE => ["NP VP"], NP => ["ART NOUN"], VP => ["VERB NP"], ART => [qw/ the a /], NOUN => [qw/ man ball woman table /], VERB => [qw/ hit took saw liked /] ); sub rand_production { my $items = $dict{+shift}; return $items->[rand @$items]; }
Vanilla ‘pre’ tags, without WP-Syntax:
Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. D:\Documents and Settings\User>
The same, but with ‘lang=text’ using WP-Syntax:
Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. D:\\Documents and Settings\\User>
I wasn’t very happy with the default styles and colors used by the plugin, so I modified them to my taste, following the directions form GeSHi’s documentation (GeSHi is the syntax-highlighting package used by WP-Syntax).
The customization done by inserting the following code after the creation of the $geshi object in function wp_syntax_highlight of wp-syntax.php:
$geshi->set_keyword_group_style(1, 'color: blue; font-weight: bold;', false); $geshi->set_keyword_group_style(2, 'color: blue;', false); $geshi->set_keyword_group_style(3, 'color: black;', false); $geshi->set_keyword_group_style(4, 'color: black;', false); $geshi->set_strings_style('color: maroon;', false); $geshi->set_escape_characters_style('color: maroon;', false); $geshi->set_symbols_style('color: black;', false); $geshi->set_numbers_style('color: black;', false); $geshi->set_methods_style('color: black;', false); $geshi->set_regexps_style('color: maroon;', false); $geshi->set_comments_style(1, 'color: darkgreen;'); $geshi->set_comments_style('MULTI', 'color: darkgreen;');
I have also followed the WP-Syntax instructions to place wp-syntax.css in my theme directory to override my default styles for the ‘pre’ tag.

May 17th, 2008 at 2:16 pm
I’ve noticed the WP-Syntax Colorizer plugin ( http://wordpress.org/extend/plugins/wp-syntax-colorizer/ ) which was written to address this. It’s installed along side WP-Syntax.
However, I’m just passing on the link; I use the Highlight Source Pro plugin ( http://wordpress.org/extend/plugins/highlight-source-pro/ ), so I can’t say anything about the quality of the WP-Syntax stuff.