Pen & Paper


undefined method "getConverterImpl" (Jekyll)

14 Dec 2015

I use a “markdown” tag to render my “about” page {% markdown about.md %} in this jekyll blog. The ‘about’ page is written in markdown but is seldom changed. It is unnecessary to run it through the jekyll engine to process it every time when a new posting is made. The ‘markdown’ tag is created using the following gem plugin (named with a .rb extension and to be put into a _plugins sub-directory under the jekyll root).

=begin
  Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid.
  Usage:
    {% markdown <filename> %}
=end
module Jekyll
  class MarkdownTag < Liquid::Tag
    def initialize(tag_name, text, tokens)
      super
      @text = text.strip
    end
 
    def render(context)
      tmpl = File.read File.join Dir.pwd, "_includes", @text
      site = context.registers[:site]
      converter = site.getConverterImpl(Jekyll::Converters::Markdown)
      tmpl = (Liquid::Template.parse tmpl).render site.site_payload
      html = converter.convert(tmpl)
    end
  end
end
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)

Upgrading from jekyll 2.5.3 to jekyll 3.0.1 will produce an error pointing to an undefined method getConverterImpl. After some googling, I have found that the method getConverterImpl has been changed to find_converter_instance in jekyll 3. Changing the following line in the above script will remove the error.

##  converter = site.getConverterImpl(Jekyll::Converters::Markdown)
    converter = site.find_converter_instance(Jekyll::Converters::Markdown)