46

我有一个 Markdown 格式的侧边栏,我想显示在我的 Jekyll 博客中。我之前曾尝试将它包含在内,{% include sidebar.markdown %}但它实际上不会呈现 Markdown。我可以像这样成功地包含它:

{% capture sidebar %}{% include sidebar.markdown %}{% endcapture %}
{{ sidebar | markdownify }}

虽然这是一个易于管理的解决方案,但我更喜欢一种更优雅的方式来实现这一点。有任何想法吗?提前致谢!

4

2 回答 2

21

我也在寻找这个,它是一个 PITA 发现如何做到这一点,没有多少谷歌内容,最准确的发现是一个在这里不起作用的要点......死简单的解决方案:

./_plugins/markdown_tag.rb

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
      Jekyll::Converters::Markdown::KramdownParser.new(Jekyll.configuration()).convert(tmpl)
    end
  end
end
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)

更新:博客使用示例:https ://web.archive.org/web/20161207125751/http://wolfslittlestore.be/2013/10/rendering-markdown-in-jekyll/

于 2013-01-09T22:05:18.103 回答
5

Jekyll 现在支持编写简单的插件来添加标签、转换器或生成器。查看http://jekyllrb.com/docs/plugins/了解详细信息。

于 2011-09-17T15:34:26.150 回答