markdown-tag.rb 681 B

12345678910111213141516171819202122
  1. =begin
  2. Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid.
  3. Usage:
  4. {% markdown <filename> %}
  5. =end
  6. module Jekyll
  7. class MarkdownTag < Liquid::Tag
  8. def initialize(tag_name, text, tokens)
  9. super
  10. @text = text.strip
  11. end
  12. def render(context)
  13. tmpl = File.read File.join context.registers[:site].source, "_includes", @text
  14. site = context.registers[:site]
  15. converter = site.getConverterImpl(Jekyll::Converters::Markdown)
  16. tmpl = (Liquid::Template.parse tmpl).render site.site_payload
  17. html = converter.convert(tmpl)
  18. end
  19. end
  20. end
  21. Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)