plugins - 在 Jekyll 插件中调用 "markdownify"

标签 plugins jekyll liquid

我正在尝试在 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/

相关文章:

javascript - 如何禁用所有自动步速预加载器事件

c++ - Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?

scope - 错误: Liquid syntax error: Unknown tag -- variable scope?

while-loop - 如何在液体/jekyll 中做一个while 循环?

javascript - 具有多种宽度列的同位素砌体

eclipse - 将我的插件放入 Eclipse 的 dropins 目录时出现 "no repository found at..."错误

jekyll - Liquid 中有没有办法使用 contains 运算符来检查精确匹配?

jekyll 在本地工作,但在 github 上不工作。要导入的文件未找到或无法读取 : minima

html - 如何在新的 Jekyll 中使用 Latex? (基于 gem 的主题最小值)

jekyll - 如何重置增量?