I'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:
(define (tagged? expr tag)
(if (pair? expr)
(eq? (car expr) tag)
#f))
Python code:
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.