GeSHi WordPress Sample with Javascript

The WP-Syntax plugin allows easy insertion of code in blog posts, using GeSHi (Generic Syntax Highlighter). It supposedly supports over one hundred programming languages, including including PHP, HTML, CSS, Java, C, Lisp, XML, Perl, Python, and assembly.

For example:

1
2
   <pre lang="html" line="1" escaped="true">
   </pre>

The line=”1″ directive tells WP-Syntax to insert line numbers. For this example, to nest xml inside xml, set escaped=”true”, and use html entities.

Here is another example, this time using “javascript” for the selected language. In this case, the code is indented. WP-Syntax converts real spaces into HTML space entities, which allows you to intend code.

1
2
3
4
5
<script type="text/javascript">// <![CDATA[
    document.write("<h1>This is a heading</h1>");
    document.write("This is a paragraph.");
    document.write("This is another paragraph.");
// ]]></script>