Reprocessing Liquid tag output


#1

I’ve been trying to write a custom Liquid tag that utilizes tag components from Jekyll-Assets. However, I’m running into an issue where the output of the tag render won’t be analyzed by Jekyll again, so the asset paths are never output correctly. That is, I’d like to convert this:

{% fb 2017-07-29/stuckleft %}

into this:

<a href="{% asset_path '2017-07-29/stuckleft' %}" data-no-instant>
  {% img '2017-07-29/stuckleft' magick:1/4 %}
</a>

which is again processed, outputting the correct asset path and image tag.

I attempted to make it work by passing it back through the Markdown converter, but it just pretty-prints the text that’s passed into it instead of treating it like a Liquid tag.

module Jekyll
  class FluidboxTag < Liquid::Tag

    def initialize(tag_name, img, tokens)
      super
      @img = img
    end

    def render(context)
      site = context.registers[:site]
      converter = site.find_converter_instance(::Jekyll::Converters::Markdown)

      asset_path = converter.convert("{% asset_path '#{@img}' %}")
      img_tag = converter.convert("{% img '#{@img}' magick:resize:800 %}")

      "<a href=\"#{asset_path}\" data-no-instant>
        #{img_tag}
      </a>"
    end
  end
end

Liquid::Template.register_tag('fb', Jekyll::FluidboxTag)