I have a bunch of markdown documents with a mix of relative and absolute image destinations. e.g.
This is some text

And more text

I want to prepend a URL to each of the relative images, e.g. to change the above to
This is some text

And more text

but preferably without hard-coding /sub/folder/
into the replace script (which is how I currently do it).
Is there a clever way to do this with awk
or sed
or is that a bad idea due to markdown having more edge cases than one expects?
I made some progress with https://pypi.org/project/marko/, e.g.
import marko
with open("myfile.md") as f: s = f.read()
doc = marko.inline.parser.parse_inline(s)
for i, e in eumerate(doc):
if type(e) == marko.inline.Image:
if not e.dest.startswith("http"):
doc[i].dest = "https://some-image-host/image-host-subpath/" + doc[i].dest
which finds all the images and updates the destination of each relative image with the URL, but I'm not quite sure how to render this list of inline elements back into a markdown string again, and I figured I would post here first before re-inventing the wheel in case there is a much simpler way of doing this.
TIA for any help.