ueberdosis/commonmark-embed-extension

An embed extension for league/commonmark

Package info

github.com/ueberdosis/commonmark-embed-extension

pkg:composer/ueberdosis/commonmark-embed-extension

Fund package maintenance!

ueberdosis/

Statistics

Installs: 1 848

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

0.2.1 2021-10-20 09:31 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 027af76755b41b0ecbfd68b8c260d7af45795aba

  • Hans Pagel <hans.pagel.woop@ueber.io>

markdowncommonmarkcommonmark-embed-extension

This package is auto-updated.

Last update: 2026-06-20 19:27:50 UTC


README

We need your support to maintain this package. πŸ’– https://github.com/sponsors/ueberdosis

CommonMark Embed Extension

πŸ‘ Image
πŸ‘ Tests
πŸ‘ Image
πŸ‘ Sponsor

An extension to transform URLs to embeds with league/commonmark.

Example

Markdown

OMG, you should see this video:

https://www.youtube.com/watch?v=eX2qFMC8cFo

Itβ€˜s amazing, isn’t it?

HTML

<p>OMG, you should see this video:</p>

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/eX2qFMC8cFo" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

<p>Itβ€˜s amazing, isn’t it?</p>

Installation

You can install the package via composer:

composer require ueberdosis/commonmark-embed-extension

Supported services

  • YouTube
  • Vimeo

Have a look at the provided services to learn how you can add your own integrations. Don’t forget to send a PR with your additions!

Usage

<?php

use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use Ueberdosis\CommonMark\EmbedExtension;
use Ueberdosis\CommonMark\Tests\Services\YouTube;
use Ueberdosis\CommonMark\Tests\Services\Vimeo;

// Configure the Environment with all the CommonMark parsers/renderers
$environment = new Environment([
 'embeds' => [
 new YouTube(),
 new Vimeo(),
 ],
]);
$environment->addExtension(new CommonMarkCoreExtension());

// Add this extension
$environment->addExtension(new EmbedExtension());

// Instantiate the converter engine and start converting some Markdown!
$converter = new MarkdownConverter($environment);
$markdown = <<<MARKDOWN
https://www.youtube.com/watch?v=eX2qFMC8cFo
MARKDOWN;

echo $converter->convertToHtml($markdown);

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.