3 ms·
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
by jjjbokma 7y ago
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.

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-nodes-in-perl-right-this-time.html http://johnbokma.com/blog/2019/09/16/rewriting-commonmark-no...