Cyberborean Chronicles

Sourcecode posting on WordPress

Thanks to new WordPress feature, sourcecode quotes in the blog posts now looks awesome:

[sourcecode language=’java’]
* HelloWorld
public class HelloWorld {
public static void main(String[] args) {
System.out.println(“Hello world!”);

See also this and this examples of Java code, this example of Python and this XML. Actually 12 programming/markup languages are supported by the syntax highlighter.

What’s good

  • It’s an eye-candy
  • Language-dependent syntax highlighting, of course
  • Horizontal scrolling of the code block, if it’s needed. Now I don’t have to bother how the lines are long
  • You can copy my code into your clipboard by a single click

What’s bad

There was a bug when HTML-reserved characters (“<“, “>“, “&“) were displayed as HTML entities (“&lt;” etc). It has been fixed just today. I also noticed that the single backslash chars (“\”) are not displayed and must be escaped with another backslash (“\\”) – hi, PHP geeks!

[upd] The problem with backslash has also been fixed. Thanks to Joseph Scott from WordPress for fast responding and fixing it![/upd]

Sadly enough, code posting is incompatible with WYSIWYG, if you bother about indentation of your code. TinyMCE visual editor will eat all your leading spaces and tabs.

Leave a Reply