PHPackages                             surface/commonmark-ext-youtube-iframe - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. surface/commonmark-ext-youtube-iframe

ActiveCommonmark-extension[Parsing &amp; Serialization](/categories/parsing)

surface/commonmark-ext-youtube-iframe
=====================================

Extension for league/commonmark to replace YouTube link with an iframe.

2.1.0(3y ago)15.6k↑12.5%MITPHPPHP ^8.0

Since Apr 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/trovster/commonmark-ext-youtube-iframe)[ Packagist](https://packagist.org/packages/surface/commonmark-ext-youtube-iframe)[ Docs](https://github.com/trovster/commonmark-ext-youtube-iframe)[ RSS](/packages/surface-commonmark-ext-youtube-iframe/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (7)Used By (0)

YouTube iframe extension
========================

[](#youtube-iframe-extension)

An extension for [league/commonmark](https://github.com/thephpleague/commonmark)version 2 built using PHP 8.0. This replaces YouTube links with the embed iframe.

The extension supports for the primary YouTube URL, with and without prefixed with the `www`. It also supports the short shareable URL using the `youtu.be` domain.

Initially based on the [YouTube extension](https://github.com/zoonru/commonmark-ext-youtube-iframe).

Installation
------------

[](#installation)

The project should be installed via Composer:

```
composer require surface/commonmark-ext-youtube-iframe
```

Usage
-----

[](#usage)

Configure your CommonMark `Environment` and add the extension.

```
use League\CommonMark\Environment\Environment;
use League\CommonMark\MarkdownConverter as Converter;
use Surface\CommonMark\Ext\YouTubeIframe\Extension as YouTubeExtension;

$options = [
    'youtube_iframe' => [
        'width' => 800,
        'height' => 600,
    ]
];

$environment = new Environment($options);
$environment->addExtension(new YouTubeExtension());

$converter = new Converter($environment);

echo $converter->convert('[](https://youtu.be/xxx)');
echo $converter->convert('[](https://www.youtube.com/watch?v=xxx)');
echo $converter->convert('[](https://youtu.be/xxx?height=480)');
echo $converter->convert('[](https://www.youtube.com/watch?v=xxx&width=640)');
```

### Dimensions

[](#dimensions)

You can control the dimensions of the videos by using the `width` and `height` configuration options.

You can also configure the dimensions using query parameters on the embed URL. You can provide the `height` or `width` or *both*.

```
?width=640
?height=480
?width=640&height=480
```

### Full URL

[](#full-url)

You can disable the parsing of full YouTube URLs (with or without the www) by using the following option. If this option is disabled, only URLs under the ‘short’ domain will be used (`youtu.be`).

```
$options = [
    'youtube_iframe' => [
        'full_url' => false,
    ]
];
```

Testing
-------

[](#testing)

There are Unit and Integration tests for the project. These can be run using the following commands:

```
composer test
composer run test
composer run test-unit
composer run test-integration
```

There are also scripts to run code sniffer, mess detector and static analysis:

```
composer run sniff
composer run mess
composer run stan
```

Changelog
---------

[](#changelog)

Please refer to the [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

This library is licensed under the MIT license. See the [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~59 days

Total

5

Last Release

1260d ago

Major Versions

v1.x-dev → 2.0.02022-04-13

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0fcbd1351650ca328e0ee494a7704fcbc393512d57234c694d02c37d1c86093?d=identicon)[trovster](/maintainers/trovster)

---

Top Contributors

[![trovster](https://avatars.githubusercontent.com/u/48729?v=4)](https://github.com/trovster "trovster (6 commits)")

---

Tags

commonmarkextensioniframemarkdownphpyoutubemarkdownyoutubecommonmarkextensionembedmusiciframe

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/surface-commonmark-ext-youtube-iframe/health.svg)

```
[![Health](https://phpackages.com/badges/surface-commonmark-ext-youtube-iframe/health.svg)](https://phpackages.com/packages/surface-commonmark-ext-youtube-iframe)
```

###  Alternatives

[zoon/commonmark-ext-youtube-iframe

Extension for league/commonmark to replace youtube link with iframe

12275.9k1](/packages/zoon-commonmark-ext-youtube-iframe)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
