Skip to content

Instantly share code, notes, and snippets.

@nhocki
Created April 2, 2014 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhocki/9926834 to your computer and use it in GitHub Desktop.
Save nhocki/9926834 to your computer and use it in GitHub Desktop.
Simple markdown include renderer for Jekyll.
module Jekyll
class MarkdownTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text.strip
end
def html_renderer(config)
@html_renderer ||= Jekyll::Converters::Markdown.new(config)
end
def render(context)
tmpl = File.read File.join Dir.pwd, "_includes", @text
site = context.registers[:site]
tmpl = (Liquid::Template.parse tmpl).render site.site_payload
html_renderer(site.config).convert(tmpl)
end
end
end
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)
# {% markdown foo.md %}
# renders _includes/foo.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment