Syntax Highighting

Whenever I try to put code snippets up here, I end up frustrated that they turn up deprived of any highlighting. So I’ve tried following these instructions to fix things. With luck, this post should be an example 😉

So this goes in <head>:

And for the highlighted text you have 2 options.

First is with <pre> tags:

or a slightly more longwinded version, which provides for escaping of html tags:

<script type="syntaxhighlighter" class="brush:html"><![CDATA[ <a href="">blah</a>]]</script>

This, alas, interacts badly with blogger’s pre-posting HTML validation. It’s easier to handle the escaping from the command-line beforehand:

$ xclip -o | perl -MHTML::Entities -ne 'print encode_entities($_)' | xclip

Leave a Reply

Your email address will not be published. Required fields are marked *