我正在为我的 Octopress 网站开发 Jekyll 标签插件,以帮助我制作“注释”元素。我只是希望能够在我的博客上突出显示一条信息作为旁注,就像这样。
问题是,我不知道如何处理此标签的内容(即 Markdown 或 Textile)。上面的图片是我实际使用 html 代码制作链接时才实现的。这是当我在内容中使用 markdown 时最终的结果。
在我的帖子中,我是这样写的内容。
{% 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 %}
这是我的插件代码。它基于图像标签代码,并且实际上没有太多内容。
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 [email protected]?
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 的其他部分一样是动态的。
杰基尔 3.x:获取ConverterImpl现已弃用
Use 查找转换器实例获取转换器:
def render(context)
text = super
site = context.registers[:site]
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
_output += "<figcaption>#{converter.convert(_caption)}</figcaption>"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)