PHP code example of ueberdosis / commonmark-embed-extension
1. Go to this page and download the library: Download ueberdosis/commonmark-embed-extension library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ueberdosis / commonmark-embed-extension example snippets
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);