
Image Caption in Jekyll - ronaldsvilcins
https://medium.com/@vilcins/image-caption-in-jekyll-5853b8e61b9d
======
jjjbokma
Interesting, I did something similar with my own static blog generator [0].
Instead of using an include I rewrote the CommonMark AST in such a way that an
image directly followed by text (the caption) is rewritten.

    
    
        ![Alt text](cat.jpg)
        Photo of a cat.
    

is rendered as HTML as follows:

    
    
        <figure>
        <img alt="Alt text" src="cat.jpg" />
        <figcaption>
        Photo of a cat.
        </figcaption>
        </figure>
    

An advantage is that this allows for Markdown inside the caption itself. Not
sure if your solution handles that.

[0] [https://github.com/john-bokma/tumblelog](https://github.com/john-
bokma/tumblelog)

[1] [http://johnbokma.com/blog/2019/09/16/rewriting-commonmark-
no...](http://johnbokma.com/blog/2019/09/16/rewriting-commonmark-nodes-in-
perl-right-this-time.html)

