-
-
Save salgadobreno/4497316 to your computer and use it in GitHub Desktop.
Markdown Tag 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
=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