Getting Code to Display Properly With nanoc and HAML

By Jimmy Bonney | August 12, 2011

Code

When I wrote the article about drupal and metadata, I needed to include some code snippets in order to illustrate what needed to be done. At the time, only nanoc, haml and sass were installed in my environment to generate this website. While I thought that it would be trivial to display code between pre tags, it turned out that I coudn’t get haml to display anything properly - even though I tried pretty much every combination (:preserve, whitespace preservation ~, …) in the haml-lang website.

Following an article from Chris Eppstein, I decided to look into Markdown. A quick install of RDiscount later, and it is now possible to include markdown filters in my articles. As a result, it is now much simpler to display pre tags and display code nicely.

In order to display the code properly, it is though important now to remember to use Markdown syntax. This means that each line should start with 4 spaces (or 1 tab). In my case, it looks like that:

:markdown
    <?php
        $meta = '<meta name="google-site-verification" content="ABCDEFGHWy6OxJzyJkzWGq4Um7FXYZTUVW" />';
        drupal_set_html_head($meta);
    ?>


For the time being, comments are managed by Disqus, a third-party library. I will eventually replace it with another solution, but the timeline is unclear. Considering the amount of data being loaded, if you would like to view comments or post a comment, click on the button below. For more information about why you see this button, take a look at the following article.