Created
November 30, 2011 08:10
-
-
Save tmtk75/1408402 to your computer and use it in GitHub Desktop.
Jekyll Markdown Tag
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
=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) | |
tmpl = File.read File.join Dir.pwd, "_includes", @text | |
site = context.registers[:site] | |
tmpl = (Liquid::Template.parse tmpl).render site.site_payload | |
html = Kramdown::Document.new(tmpl).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
How would variables be passed into the included markdown ?