Skip to content

Instantly share code, notes, and snippets.

@daveaseeman
Forked from mignev/markdown-tag.rb
Last active August 29, 2015 14:14
Show Gist options
  • Save daveaseeman/ad1e46cbecc95d60546f to your computer and use it in GitHub Desktop.
Save daveaseeman/ad1e46cbecc95d60546f to your computer and use it in GitHub Desktop.
=begin
Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid.
Usage:
{% markdown <filename> %}
=end
module Jekyll
class MarkdownTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text.strip
end
def render(context)
tmpl = File.read File.join Dir.pwd, "_includes", @text
site = context.registers[:site]
converter = site.getConverterImpl(Jekyll::Converters::Markdown)
tmpl = (Liquid::Template.parse tmpl).render site.site_payload
html = converter.convert(tmpl)
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