How to insert youtube videos(and embeds from twitter, instagram and etc.) in text rendered with markdown

I making a blog and want to allow users to insert videos from youtube(and embeds from twitter, instagram) in their posts. I have a simple preview, basically it’s a reactive var that have changing with keyup event and rendered in view by {{#markdown}}{{text}}{{/markdown}}. I’ve tried after sanitizing html tags to parse in raw markdown text custom tag like that “[https://www.youtube.com/?v=…]” and replace it with iframe, but after replacing markdown compilation is stop working(instead of compilating markdown it’s showing a raw markdown). How can i make it work?