Today I learned

Markdown in Jekyll

To add Markdown to any HTML file in Jekyll, capture it into a variable and print that variable using markdownify. That is:

{% capture x %}
## This is markdown

so and so
{% endcapture %}{{ x | markdownify }}

Using Kramdown

You can also use kramdown as your Markdown processor: it supports GitHub-like code fencing and many useful Markdown extensions.

# _config.yml
markdown: kramdown
  input: GFM

Markdown in Kramdown

If you do, there's a great alternative. Name your HTML files as .md, which is fine, because Markdown will ignore HTML blocks by default. You can then opt into Markdown processing via markdown="1". More info on this on Kramdown's documentation. Hat tip to @marksteve.

  <h3>I'm HTML</h3>
  <div markdown="1">
    I am *Markdown text*. Be sure not to indent me,
    else I'll be interpreted as a code block.

You have just read Markdown in Jekyll, written on May 25, 2015. This is Today I Learned, a collection of random tidbits I've learned through my day-to-day web development work. I'm Rico Sta. Cruz, @rstacruz on GitHub (and Twitter!).

← More articles