I think what you want is Hugo’s render-image
render-hook feature (Markdown Render Hooks in the docs).
You can see an example I have created for a (work in progress) responsive images hook on this forum
You will obviously also need to use replace or replaceRE
HTH