Jekyll Raw Code Block Syntax

A guide to formatting code blocks using the Jekyll raw syntax

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. Sometimes I found that code blocks I had written as examples would end up being ran rather than being outputted as text code blocks. This is where the raw method becomes useful.

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 %}

Recent posts View all

Web DevProductivity

Keeping on top of website updates

Learn what website updates are, what they entail, why they are important, and how we can help

Freelancing

Getting the most out of your agency

Here are some tips based on years of working with, for, and as an agency on how to get the most out of any work you do.