Code Yarns β€πŸ‘¨β€πŸ’»
Tech Blog ❖ Personal Blog

Pandoc not converting image to figure

πŸ“… 2020-May-18 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ ⬩ πŸ“š Archive

Problem

I had written a blog post using Markdown, that had an image in it like this:

![](foobar.png)

I used Pandoc in Ubuntu 18.04 to convert the Markdown file to HTML. It rendered the image to the figure tag in HTML like this:

<figure>
<img src="foobar.png" />
</figure>

When I used Pandoc in Ubuntu 20.04 it rendered the HTML like this:

<p><img src="foobar.png" /></p>

This was not what I wanted.

Investigation

It turns out that Ubuntu 18.04 has Pandoc 1.x, while Ubuntu 20.04 has Pandoc 2.5.

Pandoc 2.0.0.1, which was released on 2017-10-30, seems to have this breaking change in its changelog:

Require nonempty alt text for implicit_figures (#2844). A figure with an empty caption doesn’t make sense.

So, to get back to older behavior in Pandoc 2.x, I need to always provide a caption for images, like this:

![Figure of a foobar](foobar.png)