Created
April 2, 2014 02:10
-
-
Save nhocki/9926834 to your computer and use it in GitHub Desktop.
Simple markdown include renderer for Jekyll.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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