定制 surface/commonmark-ext-youtube-iframe 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

surface/commonmark-ext-youtube-iframe

最新稳定版本:2.1.0

Composer 安装命令:

composer require surface/commonmark-ext-youtube-iframe

包简介

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

README 文档

README

An extension for league/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.

Installation

The project should be installed via Composer:

composer require surface/commonmark-ext-youtube-iframe

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

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

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

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

Please refer to the CHANGELOG for more information on what has changed recently.

License

This library is licensed under the MIT license. See the License File for more information.

统计信息

  • 总下载量: 5.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-13