A new day (yesterday)* a new release of the syntax highlighter plugin.
This one adds support for line numbers; whether line numbers are displayed and the starting line number is controlled through attributes to the pre tag.
<pre lang=[cpp|cppcli|csharp|php|html|css|xml|xsl|text] useLineNumbers=[true|false] startingLineNumber=[1|...]> // Your code here </pre>
Case doesn’t matter for the useLineNumbers
or startingLineNumber
attribute names but the values are case sensitive.
Download Syntax Highlighter v1.2 (23.9Kb). Installation is simple, extract the zip file to your WordPress installation directory and modify syntax_highlighter2.php the 'default' => 'csharp',
line to tell the highlighter how it should colorize pre tags that don’t have the lang attribute set, or set to a valid value.
Once that is done you need to add some CSS classes to your sites stylesheet:
pre span.linenumber { color: gray; border-right: 1px solid gray; } pre span.comment { color: green; } pre span.keyword { color: blue; } pre span.number { color: red; } pre span.string { color: #990000; }
Once that is done upload the files to your webserver and you should be ready to go.
*A New Day Yesterday, Stand Up – Jethro Tull
FYI:
The link in your blog pointing to syntax_highlight_v1_2.zip does not work…
Thanks for the heads up, I’ve fixed the link.
James
Ok I tested it and it works beautifully 🙂 (except for a minor detail)
I use:
pre lang=”csharp” useLineNumbers=”true”
If I use:
pre lang=”csharp” useLineNumbers=”true” startingLineNumber=”0″ then it looks really weird…
Look here for an example, the second code snippet uses startingLineNumber and sets it to 0:
http://java.thn.htu.se/~toor/blog-ng/index.php?p=316
Notice the shift on the first line? Or is it my Mozilla?
Hmm same thing happens when linenumbers go from 9 to 10:
http://java.thn.htu.se/~toor/blog-ng/index.php?p=317