ueberdosis / commonmark-embed-extension
league/commonmark 的嵌入扩展
0.2.1
2021-10-20 09:31 UTC
Requires
- php: ^8.0
- aviator/array-map-keys: ^0.1.0
- league/commonmark: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.8
README
我们需要您的支持来维护此包。💖 https://github.com/sponsors/ueberdosis
CommonMark Embed Extension
league/commonmark 的 URL 嵌入扩展。
示例
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>
安装
您可以通过 composer 安装此包
composer require ueberdosis/commonmark-embed-extension
支持的服务
- 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!
用法
<?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);
测试
composer test
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 以获取更多信息。