West Wind Hero Image

Rick Strahl's Weblog

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows
On this page:

Embedding YouTube videos into Markdown can be surprisingly unintuitive depending on what the Markdown rendering platform supports. If the platform you're publishing your Markdown to - your own blog engine, a commercial CMS site, Wordpress, or something less mainstream - there may or may not be support for certain features, or there may be custom implementations provided by the platform.

Native support in Markdown itself is pretty limited, although there are a number of ways you can embed YouTube videos and in this post I'll discuss the following three ways:

  • YouTube Player embedding
  • YouTube Image Preview plus Link
  • Capture YouTube Preview plus link

I'm coming at this from the perspective of blogging and using my own Blog engine, so the above points address first what's natively available and then also a custom approach as part of some tooling in Markdown Monster that works by automatically generating a You Tube preview.

The YouTube Embeddable Player

YouTube has an official way to embed the YouTube player into HTML. You can access this from YouTube's Share button and use the Embed link. This produces a bit of HTML that you can directly paste into your Website and... your Markdown text.

The HTML that YouTube provides looks like this:

<iframe></iframe>

This is meant for pasting into HTML content, but it also works in Markdown since Markdown by default supports embedded HTML content.

This is great... as long as you can use it!

The problem with this is that many Markdown hosting platforms don't allow for extensive HTML embedding and even those that do often don't allow for <iframe> embedding since it poses a big cross-site scripting security issue.

GitHub which arguably is the most widely used Markdown platform does not support <iframe> embedding (or most HTML embedding for that matter) and so you can't embed the YouTube player directly.



System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Html.HtmlString]