Sunday, June 11, 2006
WordPress is pretty good, but it comes with no code formatting tool, yet colouring facilities. I like the simplicity of dp.SyntaxHighlighter for displaying source code in web pages: it works with major browsers and degrades fairly well.
<textarea> tags, it will still display no matter what.
Configuring _dp.SyntaxHighlighter_to work in WordPress is pretty easy: just add the relevant code in your WordPress templates for header and footer according to the instructions found on the website and you’re done.
The issue though is making it possible to insert code when writing a post.
First of all, I doubt that there is any elegant way to make one of the rich HTML editors work well, so you’ll have to go back to basics and edit in HTML (WordPress at least hides the
<p> tags so its’ not too bad).
Then there is the issue of WP adding the
<p> to replace linefeeds, and this is where it becomes annoying: if you insert
<textarea> tags, everything in it will have the extraneous formatting code that will display verbatim on screen, sprinkling your nice source code with ugly html tags.
The solution I found was to use a small WordPress plug-in called
codeautoescape and available from:
I then modified it a bit to take care of the
<textarea> tag and the fact that we needed to take the attributes of the tag into account (dp.SyntaxHighlighter uses the class attribute to configure options for how to display the block of code).
You can download the modified version of the script: codeautoescape
To install it, just right-click and download from the link, rename it to
codeautoescapte.php then install it in your
/wp-content/plugins folder and activate it within the Plugins menu of WordPress.
Some examples of dp.SyntaxHighlighter in action:
XML / HTML
Entry Filed under : Web Design