One thing that I have really enjoyed since becoming a professional web developer is writing more and with this kind of job I find myself doing mostly technical writing and this involves generally writing blocks of code to show examples of my work.

This is a Jekyll site which uses Liquid. I found when I first started writing blocks of code that sometimes what I wrote in the code block ended up being ran which is less than ideal and here is where the raw method comes in to it’s own.

First of all to construct a code block using Jekyll you have to use the highlight method. You can use this for a variety of different languages (according to Jekyll they support over 60). You just have to place your language of choice after highlight.

{% highlight ruby %}
def cat
  puts 'I love cats'
end
{% endhighlight %}

This is all fine and dandy but remember I mentioned that sometimes the code will be ran. This can happen even within the highlight, so you need to use raw to escape it. Like this:

{% highlight ruby %}
{% raw %}
def cat
  puts 'I love cats'
end
{% endraw %}
{% endhighlight %}

Please take a look at the source code to see how I actually put this out if you’re interested in how to escape {% endraw %} tags. It gets very meta!

Why not read some more of our Development Help posts?