Markdown parsing order in custom Liquid tags

I created and maintain a Jekyll theme that has several custom Liquid tags to streamline the post-writing process. This repo.

A few of the image related tags have parameters that require both an image file path and a caption. I have not been able to figure out a way to allow the writers to use Markdown syntax inside the caption parameters. So right now, if someone wants to italicize a title in a main-column image for instance, they must write something like ‘Blah blah, <em>The Best Blah of the Blahs</em>, 2020’ instead of ‘Blah blah, *The Best Blah of the Blahs*, 2020’. in order to render 'Blah blah, The Best Blah of the Blahs, 2020. Ideally, it would be best to not require any HTML tags at all.

I suspect it has to do with the parsing order of the files. I’m guessing the Liquid tags get parsed first, and then the remaining text gets parsed as Markdown. For some reason, Markdown syntax embedded in a Liquid tag parameter is not parsed.

Is there a way to perhaps change the parsing order when the site is built? Or perhaps my Liquid tag code is insufficient: I am not any sort of real Ruby programmer.

Ideas?

Use the markdownify filter.

Then you can have a frontmatter which is valid markdown (maybe quote it so YAML doesn’t evaluate characters).

title: **Title**

Then when its rendered you can convert from markdown to html

{{ page.title | markdownify }}

Renders with the bold or em tags.

The problem is in a custom tag, not the front matter. Just for the benefit of anyone having a similar issue as I did, I solved it by running the markdown converter inside the custom liquid tag code. The problem stems from the fact that the Kramdown converter does not play well with HTML5 <figure> and <figcaption> tags. By running the converter on the string in question inside the Liquid code, it converted it to HTML, but had the unfortunate side effect of wrapping everything in a <p> tag pair. So I had to strip the <p> tags.

The relevant code solution was this:

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

      baseurl = context.registers[:site].config['baseurl']
      label = Kramdown::Document.new(@text[1],{remove_span_html_tags:true}).to_html # render markdown in caption
      label = converter.convert(label).gsub(/<\/?p[^>]*>/, "").chomp # remove <p> tags from render output