Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax highlighting markdown code blocks in Jekyll (without using liquid tags)

It seems like syntax highlighting in Jekyll is limited to using liquid tags and pygments like so:

{% highlight bash %} cd ~ {% endhighlight %} 

But I've imported my existing blog from wordpress and it was written in markdown (using markdown code blocks) and I don't want to have to go through each post and fix the code blocks. Also, I want to keep my posts in pure markdown format in case I ever need to switch blogging platforms again.

I switched my Jekyll parser to redcarpet with the hope that I could use this markdown syntax:

```bash cd ~ ``` 

But it doesn't seem to work. It just wraps it in a normal code block. Any ideas?

like image 884
markquezada Avatar asked Dec 27 '11 19:12

markquezada


People also ask

How do you get syntax highlighting in Markdown?

Many Markdown processors support syntax highlighting for fenced code blocks. This feature allows you to add color highlighting for whatever language your code was written in. To add syntax highlighting, specify a language next to the backticks before the fenced code block.

How do you mark a code block in Markdown?

To format a code block in Markdown, indent every line of the block by at least four spaces. An indented code block cannot interrupt a paragraph, so you must insert at least one blank line between a paragraph the indented code block that follows.

Does Jekyll support Markdown?

By default, Jekyll uses the kramdown Markdown processor with stock settings, but you can enable other kramdown options or even switch Jekyll to another Markdown processor. See the Jekyll Markdown configuration options documentation for more information.

Can you embed code snippets in Markdown?

Embedding Code in Markdown. If you're writing your code in markdown, the easiest way to embed snippets is to use "fenced code blocks", which also allows syntax highlighting. For examples in practice, see this assemble boilerplate for markdown projects, in particular take a look at the code in these templates.


1 Answers

Fenced blocks were introduced with Redcarpet 2. Jekyll now supports Redcarpet 2.

As an aside I am using Redcarpet with Rouge until Kramdown support is available.

In addition some people prefer Nanoc to Jekyll.

like image 165
Zombo Avatar answered Sep 20 '22 01:09

Zombo