wildlyinaccurate / jekyll-responsive-image

An unopinionated Jekyll plugin for generating and using responsive images
MIT License
332 stars 48 forks source link

Cannot use markdownify in the template #86

Closed yaqwsx closed 4 years ago

yaqwsx commented 5 years ago

I would like to specify image captions using markdown (and e.g., use markdown links). Therefore I added the following to my template:

{% if caption %}
    <figcaption>
        {{ caption | markdownify }}
    </figcaption>
{% endif %}

However, then I get error Liquid Exception: undefined methodfind_converter_instance' for nil:NilClass in mymdfile.md`

The same code snippet works fine when it is used directly in the main document, so I assume there is something wrong in the plugin.

wildlyinaccurate commented 5 years ago

Thanks for reporting this! I don't have much time to look into the issue right now, but I suspect it's to do with how the plugin renders the templates. Thinking out loud: I'm guessing that Liquid doesn't know about the markdownify filter. I wonder if it's possible to ask Jekyll to render the template, rather than going to Liquid directly.

wildlyinaccurate commented 5 years ago

A possible workaround: could you markdownify the caption before you pass it into the responsive_image tag?

{% assign path = 'assets/test.png' %}
{% assign caption = 'Some MD here' | markdownify %}

{% responsive_image_block %}
  path: {{ path }}
  caption: {{ caption }}
{% endresponsive_image_block %}
yaqwsx commented 5 years ago

I think the problem could be elsewhere - the error comes from:

 def markdownify(input)
      @context.registers[:site].find_converter_instance(
        Jekyll::Converters::Markdown
      ).convert(input.to_s)
    end

It seems like @context.registers[:site] does not contain find_converter_instance - however, I have no idea why.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

yaqwsx commented 5 years ago

@stale I haven't found a solution yet.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.