Code highlighting with the WP-Syntax plugin for WordPress

Saturday, July 25th, 2009

I’d like to write more about ColdFusion on Wheels on this blog, so I’m playing around with a syntax highlighter for WordPress called WP-Syntax.

It supports syntax highlighting for a boat-load of languages, CFML, HTML, JavaScript, and CSS included.

It looks like all I’ll need to do is wrap some code in <pre> tags with a lang attribute like so:

<pre lang="cfm">
<cfcomponent output="false">
 
    <cffunction name="hello">
        <cfset theTime = Now()>
    </cffunction>
 
</cfcomponent>
</pre>

It will produce this output:

<cfcomponent output="false">
 
    <cffunction name="hello">
        <cfset theTime = Now()>
    </cffunction>
 
</cfcomponent>

To add line numbers to the formatting, just add the line number you want it to start at with the line attribute.

1
2
3
4
5
6
7
<cfcomponent output="false">
 
    <cffunction name="hello">
        <cfset theTime = Now()>
    </cffunction>
 
</cfcomponent>

You can view source on this entry to see what happens behind the scenes. Pretty sweet!

The Other Notes page in the documentation is the best way to get a sense of how to use the plugin, plus it lists the values you can put into the lang attribute.

Technorati Tags: , , , , , , , , , , , , , , ,

Leave a Reply