It may be worthwhile to take a deeper look at Pandoc if other replies don’t respond with something easier.
In a recent Talk Python to Me podcast [0], the Quarto [1] developers talked about how they are using Pandoc’s Lua interpreter [2] to perform transformations that aren’t part of vanilla pandoc in.md -o out.pdf.