I've always kinda viewed Markdown's image embed more as a media embed than strictly an image embed, so I decided to transform the image rendering in Marked into a generic media render. Right now it supports three types of embeds; the standard image embeds, YouTube/Vimeo embeds, and HTML5 video embeds with .webm and .mp4 file extensions.
- Image usage is standard Markdown
- YouTube/Vimeo usage: Use a YouTube/Vimeo video's URL and it'll generate a YouTube/Vimeo
<iframe>embed - HTML5 Video: Use either a relative or absolute URL that ends with
.webmor.mp4and it will create a<video>tag for you. The text inside brackets will be used if HTML5 Video is unavailable. If an image URL in quotes is provided after the video URL, it will be used for the video's poster. Videos have controls on. If the video is relative and it's a.webmfile, it will attempt to find a corisponding.mp4file and include that as a secondary source. A base path to prepend to the the relative path it is checking for can be set using thelocalVideoPathoption.
Code - YouTube
Output - YouTube
<p><iframe width="560" height="315" src="//www.youtube.com/embed/_wYtG7aQTHA" frameborder="0" allowfullscreen></iframe></p>Code - Vimeo
Output - Vimeo
<p><iframe src="//player.vimeo.com/video/90602247" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></p>Code
Output
<p><video controls poster="images/shake-it-off.png"><source src="videos/shake-it-off.webm" type="video/webm"><source src="videos/shake-it-off.mp4" type="video/mp4">Shake it Off</video></p>
There is a XSS vulnerability here, everywhere you post user-data into the generated HTML.
Instead, you should html encode them properly first. I'm not sure what libraries are included with marked (definitely check there first), but as a fallback: