The output works good except if the markdown includes a link; which makes the link to break.
Is this something that might be related with Kirby or my code?
I think the problem is caused by closing quotes in the generated HTML which break the tag. Probably not limited to links but anything that has quotes, even it is just some text that contains quotes.
What is your use case for putting HTML in a data attribute? Wouldn’t it make more sense to grab the result via AJAX?