zoon/commonmark-ext-youtube-iframe

Extension for league/commonmark to replace youtube link with iframe

Installs: 235 594

Dependents: 1

Suggesters: 0

Security: 0

Stars: 12

Watchers: 4

Forks: 5

Open Issues: 0

Type:commonmark-extension

2.0.0 2022-06-20 10:16 UTC

This package is auto-updated.

Last update: 2024-11-20 16:23:11 UTC


README

Extension for league/commonmark to replace youtube link with iframe.

Install

composer require zoon/commonmark-ext-youtube-iframe

Test

./vendor/bin/phpunit

Example

use League\CommonMark\CommonMarkConverter;
use Zoon\CommonMark\Ext\YouTubeIframe\YouTubeIframeExtension;

$converter = new CommonMarkConverter([
    'youtube_iframe' => [
        'width' => '600',
        'height' => '300',
        'allow_full_screen' => true,
    ],
]);

$converter->getEnvironment()->addExtension(new YouTubeIframeExtension());

echo $converter->convert('Check this: [](https://youtu.be/mVnSpPMgoWM?t=10)')->getContent();
echo $converter->convert('Check this: [](https://www.youtube.com/watch?v=mVnSpPMgoWM&t=10)')->getContent();
<p>Check this: <iframe width="600" height="300" src="https://www.youtube.com/embed/mVnSpPMgoWM?start=10" frameborder="0" allowfullscreen="1"></iframe></p>
<p>Check this: <iframe width="600" height="300" src="https://www.youtube.com/embed/mVnSpPMgoWM?start=10" frameborder="0" allowfullscreen="1"></iframe></p>