Adding Youtube video just like adding an Image.
![isyoutube](youtube link here)// it's that simple
For example, markdown-youtube will convert the following line virtually:
![isyoutube](https://www.youtube.com/watch?v=Wwp9eaVVW_8)
to:
<iframe src="https://www.youtube.com/embed/Wwp9eaVVW_8"></iframe>
Manage iframe
height, width, border, margin
, etc. using CSS. Something like:
iframe {
width: 80%;
height:350px;
border: 0;
margin: 0 auto;
display:block;
}
You can't let your user to use IFrame for adding video in Markdown for Security reason.
I've modified Pagedown's Markdown.Converter.js
and Markdown.Sanitizer.js
to Support Youtube video.
I've also modified michelf's php-markdown Markdown Extra
in markdown.php
to Support Youtube video.
In JavaScript,
- Check for
isyoutube
, Given url
characters are escaped,- Match
Given url host
towww.youtube.com
, - Slice
v
's value from the URL, - Now place it inside
'<iframe src="https://www.youtube.com/embed/'+value of v+'"></iframe>'
, - This
iframe
is sanitized inMarkdown.Sanitizer.js
. Just similar toimg
tag sanitization.
In Markdown.php
you need to use Markdown Extra
. The working process is almost same as in JavaScript except sanitization.
For Sanitization process I used HTMLPurifier.
$config->set('HTML.Trusted', true);
$config->set('Filter.YouTube', true);