Skip to content

Instantly share code, notes, and snippets.

@salgadobreno
Forked from tmtk75/markdown-tag.rb
Last active December 10, 2015 21:48
Show Gist options
  • Save salgadobreno/4497316 to your computer and use it in GitHub Desktop.
Save salgadobreno/4497316 to your computer and use it in GitHub Desktop.
Markdown Tag for Jekyll
=begin
Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid.
Usage:
{% markdown <filename> %}
Dependency:
- kramdown
=end
module Jekyll
class MarkdownTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text.strip
end
require "kramdown"
def render(context)
"#{Kramdown::Document.new(File.read(File.join(Dir.pwd, '_includes', @text))).to_html}"
end
end
end
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment