0

When writing markdown with code to be read by Jekyll, you can enable syntax highlighting with

{% highlight python %}
x = ('a', 1, False)
{% endhighlight %}

However, this becomes a bit verbose if you constantly switch between code and text. Is it possible to introduce a YAML variable in the header, like

---
layout: page
title: "Syntax highlighting"
tags : [python, jekyll]
language: python
---

so that every code block on this page will be highlighted like python, but only needs to be indented, and not fenced off?

Psirus
  • 1,225
  • 1
  • 11
  • 21

1 Answers1

3

Fenced blocks were introduced with Redcarpet 2. Jekyll now appears to support Redcarpet 2.

~~~ python
x = ('a', 1, False)
~~~

If you want it a little simpler you can make it a two-liner, but that’s the best deal you’re going to get.

    x = ('a', 1, False)
{:.language-python}
Steven Penny
  • 82,115
  • 47
  • 308
  • 348
  • I don't object to the `Liquid` syntax, I'm bothered by the fact that every one-liner of code turns into three lines. It clutters up the markdown sources. – Psirus May 13 '13 at 06:26
  • Didn't even know about fenced blocks, I'm still using triple backticks. Cool. – Ain Tohvri Dec 13 '17 at 22:21