如何在Jekyll标签插件中获取Markdown处理的内容 [英] How to get Markdown processed content in Jekyll tag plugin
问题描述
我正在为Octopress网站开发一个Jekyll标签插件,以帮助我制作一个"note"元素.我只希望能够在我的博客上突出显示一条信息,就像这样.
I'm working on a Jekyll tag plugin for my Octopress site to help me make a 'note' element. I just want to be able to highlight a piece of information on my blog as a side note, like this.
问题是,我不知道如何获取此标签的内容(即Markdown或Textile).上面的图像只有在我实际上使用html代码进行链接时才能实现.当我在内容中使用markdown时,结果就是这样.
The problem is, I can't figure out how to get the contents of this tag to be processed (i.e. Markdown or Textile). The above image is only achieved is I actually make my links with html code. Here is how it ends up turning out when I use markdown in the contents.
在我的帖子中,我正在这样写内容.
In my post, I'm writing the contents of this like so.
{% note %}
This is the third post in my Start to Finish series. Last time I talked about [Git](/blog/2013/09/25/getting-started-with-git/).
{% endnote %}
这是我的插件代码.它基于图像标签代码,实际上没有太多内容.
Here is my plugin code. It's based off of the image tag code, and there's really not a lot to it.
module Jekyll
class NoteTag < Liquid::Block
@title = nil
def initialize(tag_name, markup, tokens)
@title = markup
super
end
def render(context)
output = super(context)
title = "Note"
if !@title.empty?
title += ": #{@title}"
end
"</section>\n<div class=\"note\"><span class=\"title\">#{title}</span>#{output}</div>\n<section>"
end
end
end
Liquid::Template.register_tag('note', Jekyll::NoteTag)
您是否知道如何在此标签的内容上使用转换器?我通常在帖子中使用Markdown,但我想为其他人发布此插件,因此我希望它像Jekyll的其余部分一样具有动态性.
Do you have any idea how I can use a converter on the contents of this tag? I generally use Markdown for my posts, but I'd like to release this plugin for others so I'd like it to be dynamic just like the rest of Jekyll.
推荐答案
Jekyll 3.x:现在已弃用 getConverterImpl
Jekyll 3.x : getConverterImpl is now deprecated
使用 find_converter_instance 获取转换器:
def render(context)
text = super
site = context.registers[:site]
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
_output += "<figcaption>#{converter.convert(_caption)}</figcaption>"
这篇关于如何在Jekyll标签插件中获取Markdown处理的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!