我正在尝试在 Jekyll 插件中手动调用 markdownify
过滤器。这是我所拥有的:
module Jekyll
class ColumnBlock < Liquid::Block
include Jekyll::Filters
def initialize(tag_name, markup, tokens)
super
@col = markup
end
def render(context)
text = super
'<div class="col-md-' + @col + '">' + markdownify(text) + '</div>'
end
end
end
Liquid::Template.register_tag('column', Jekyll::ColumnBlock)
我收到以下错误:Liquid Exception: undefined method 'registers' for nil:NilClass
我是 Jekyll 和 Ruby 的新手。当我想使用 markdownify
过滤器时,我必须包括什么?
最佳答案
为什么不直接调用转换器呢??
参见 source code
def render(context)
text = super
site = context.registers[:site]
converter = site.getConverterImpl(Jekyll::Converters::Markdown)
'<div class="col-md-' + @col + '">' + converter.convert(text) + '</div>'
end
关于plugins - 在 Jekyll 插件中调用 "markdownify",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18768113/