Syntax Highlighting II

The first time I looked up for a method to include code snippets into my blog entries, I came up with a solution based upon using the service provided by the site tohtml.com. I blogged about it.

This approach had a couple of drawbacks:

  1. Highlighting is based upon HTML tags. Hence code edition is a cumbersome task since the easiest way to do it is to take te code snippet back to tohtml.com, edit it, generate the HTML code again and replace it in the post.
  2. The generated HTML code doesn't use CSS. So customizing it is hard and changing its style requires to generate the code again.
  3. The code snippet is part of the articles text so its width is limited. This affects readability and requires some custom line breaking.
So after I read the post How to embed snippets in your blog, I gave it a try and switch to use GitHub's gists.

Using this approach overcomes the first and third drawbacks. And the second is not a serious problem since now code snippets appear enclosed into a text box, so even if I would change the background to a dark color, snippets will still look good.

The only disadvantage is that I lose the possibility of highlighting parts of the code snippet (e.g. using a bold font or yellow marker style for just one line), but I certainly like it much more the way code snippets look in the blog now.

No comments:

Post a Comment