Markdown parsing order in custom Liquid 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