Syntax Highlighting in a CKS:EBE blog
Today I finally got around to setting up a decent way of handling code blocks on my blog - some of my earlier code listings looked pretty awful if I didn’t put enough work into the formatting.
I’m now using SyntaxHighlighter from Google Code. It works well, but this being SharePoint there are a couple of details that make it more difficult to use.
First, SharePoint strips out a lot of html formatting as soon as you save a post. That includes the name attribute on the pre tag which is used to determine which block to format. Fortunately this is easy enough to fix by leaving the parameter off the call to HighlightAll.
Next there is getting the scripts to appear - and particularly getting the scripts to render client side and not be treated as part of the XSL. Since figuring out XSL syntax is never much fun, here’s the complete code added to Post.xsl. All the scripts are uploaded to a document library “Scripts”.
<!-- -->
<![CDATA[<br></br>
dp.SyntaxHighlighter.ClipboardSwf = '/Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll();
]]>