This is a plugin for the markdown-it-php Markdown parser by Kenji Yasuda. It allows you to easily embed YouTube videos into your Markdown enabled website, without allowing HTML.
Table of Contents
composer:
composer require gcdinsmore/markdown-it-youtube-php
use Kaoken\MarkdownIt\MarkdownIt;
use GCDinsmore\YoutubeIt\YoutubeIt;
$md = new MarkdownIt();
$md->plugin(new YoutubeIt());
echo $md->render("!yt[](sk2pr4XD_kw)");
$md = new MarkdownIt();
$md->plugin(new YoutubeIt([
"width" => "200px",
"height" => "200px",
"origin" => "https://example.com"
]));
echo $md->render("!yt[](sk2pr4XD_kw)");
Option | Default | Description |
---|---|---|
class | Specify a class attribute for the iframe. Use this to style iframes. | |
height | 480px | The height attribute of the YouTube iframe |
origin | This is the origin argument of the embedded URL. According to YouTube, this can help prevent malicious JavaScript from hijacking your YouTube videos. | |
width | 270px | The width attribute of the YouTube iframe |
YoutubeIt syntax is similar to the standard image Markdown syntax, except you add yt after the initial exclamation point. The text inside the square brackets is used as the alt text. The optional text after the URL is used as the title.
The URL portion can be just the video ID, or it can be the URL from the YouTube page.
!yt[Lady Washington](https://www.youtube.com/watch?v=4YBB1VXg_hk "Lady Washington from SailingNW.com")
The reference style syntax is supported as well.
!yt[S/V Audrey II][1]
Some text
- a
- b
[1]: sk2pr4XD_kw \"S/V Audrey II Adventure\"
I'm using the same MIT license that markdown-it and markdown-it-php are using.