The WP-syntax plugin works ok with the WYSIWYG editor, as long as you put your code in using the html tab.

To display code using the plugin, place the following tags around your code:

<pre lang="language" line="1"> Your code goes here</pre>

Where language is the language of your code. The line attribute enables line numbering, starting with the number you assign or disables line numbering if left out. For example

<pre lang="language">Code goes here</pre>

Does not show line numbers.

And how did I show the </pre> tag in my code without it being interpreted as an actual end of my demonstration code block? Encode the html entities and use the escaped=”true” attribute like this:

<pre lang="html4strict">
&lt;pre lang="language" escaped="true"&gt;
Code goes here
&lt;/pre&gt;
</pre>

Note that if you hit preview or publish from the visual editor tab, it will entity encode your code so you better have that escaped=”true” attribute set! Of course if you just stay in HTML mode you’re pretty safe 😉
EDIT: The wp-syntax plugin is based on GeSHi which is also available on a number of other platforms (just this week I used a Mediawiki plugin). As it turns out, the Mediawiki documentation has a nicely formatted version of the elusive list of GeSHi supported languages and what to call them in your pre tag

Leave a Reply

Your email address will not be published. Required fields are marked *