Call "markdownify" in Jekyll Plugin

I am trying to manually call a filter markdownifyin a Jekyll plugin. Here is what I have:

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)

I get the following error: Liquid Exception: undefined method 'registers' for nil:NilClass

I am very new to Jekyll and Ruby. What do I need to enable when I want to use a filter markdownify?

+2
source share
2 answers

Why not call the converter directly?

See 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
+4
source

Update - getConverterImpl is deprecated in Jekyll 3, use find_converter_instance instead :

def render(context)
  text = super
  site = context.registers[:site]
  converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
  '<div class="col-md-' + @col + '">' + converter.convert(text) + '</div>'
+1
source

Source: https://habr.com/ru/post/1527148/


All Articles