I bet you could do the same thing with pandoc and skip serializing to HTML entirely.
Apparently yes: https://pandoc.org/MANUAL.html#options
Apparently yes: https://pandoc.org/MANUAL.html#options