Posting source code on WordPress.com blog

While WordPress.com doesn’t allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing. WordPress.com has created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:

  1. #button {  
  2.   
  3. font-weightbold;  
  4.   
  5. border2px solid #fff;  
  6.   
  7. }  

Wrap your code in these tags:

[sourcecode language=’css’]

your code here

[/sourcecode]

Any of the following can be used for the language parameter (using one is required):

  • cpp
  • csharp
  • css
  • delphi
  • html
  • java
  • jscript
  • php
  • python
  • ruby
  • sql
  • vb
  • xml

Code in between the [sourcecode] tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

Alex Gorbatchev’s syntaxhighligher Google Code project was used to implement this feature.

Advertisements
%d bloggers like this: