add v5.0.1
[qemu-web.git] / _plugins / markdown.rb
1 =begin
2 Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid.
3 Usage:
4 {% markdown <filename> %}
5 Dependency:
6 - kramdown
7 =end
8 module Jekyll
9 class MarkdownTag < Liquid::Tag
10 def initialize(tag_name, text, tokens)
11 super
12 @text = text.strip
13 end
14 require "kramdown"
15 def render(context)
16 site = context.registers[:site]
17 if @tag_name == 'markdown' then
18 fname = File.join site.source, "_includes", @text
19 else
20 page = context.registers[:page]
21 fname = File.join site.source, File.dirname(page['path']), @text
22 end
23 tmpl = Liquid::Template.parse(File.read fname).render site.site_payload
24 html = Kramdown::Document.new(tmpl).to_html
25 end
26 end
27 end
28 Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)
29 Liquid::Template.register_tag('markdown_relative', Jekyll::MarkdownTag)