Last Updated: February 25, 2016
· keyboardcowboy

Use Markdown inside HTML blocks in Jekyll

I can't take credit for the code, but it was so helpful to me as a new Jekyll developer that I need to share it.

Jekyll can be easily extended using plugins. Simply create a directory at your site root called _plugins and add your plugins there. See the jekyll docs for more info.

I found the markdown plugin in this StackOverflow Post.

module Jekyll
  class MarkdownBlock < Liquid::Block
    def initialize(tag_name, text, tokens)
    require "kramdown"
    def render(context)
      content = super
Liquid::Template.register_tag('markdown', Jekyll::MarkdownBlock)

Then you can wrap anything, including an included .md file, in this block to have it render as markdown, even inside of HTML.

{% markdown %}
[Stack Overflow](
{% endmarkdown %}

Credit to MisterMetaphor for this.

This plugin utilizes the Ruby kramdown markdown parser.