Syntax highlighting now available

Posted by    |      

A much-requested feature on this website has been automatic syntax highlighting of code snippets. It is now available and I thought I'd document it here instead of sending everyone an e-mail. The reason why it took so long to implement is that I didn't know how to best integrate it with the Seam wiki text syntax. As you know, we wrap a code block in backticks - that doesn't leave any room for syntax highlighting options. Other wiki text parsers use something like <code syntax="java">...</code> but I wanted to keep the superfast backtick syntax and have it highlighted.

So the way it works now is with an optional line of parameters that follows the opening backtick:



<p class="wikiPara">
The options are enclosed in square brackets and the closing square bracket needs to be followed by a newline. See <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter:Configuration" target="" class="regularLink">this page</a> for a list of options. I've installed all brushes, though most of you will probably use 'java', 'xml', and 'sql'.
</p>

<p class="wikiPara">
The example will then render like this:
</p>

<pre class="wikiPreformatted brush: java; gutter: true;">String text = "Hello World"; // Some comment...
System.out.println(text);

If you do not specify a brush or if you do not include an option line, the code block will be rendered as a grey box, as before. Oh, and the preview when you edit a document will always show the non-highlighted version, it's only applied when you save or update the document.

(No, it will not work on the seamframework.org forums. This has to be tested here first.)


Back to top