Skip to content

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

License

Notifications You must be signed in to change notification settings

trovster/commonmark-ext-spotify-iframe

Repository files navigation

Spotify iframe extension

An extension for league/commonmark version 2 built using PHP 8.0. This replaces Spotify links with the embed iframe.

The extension supports for tracks, artists, albums and playlists using the embed URL format.

Initially based on the YouTube extension.

Installation

The project should be installed via Composer:

composer require surface/commonmark-ext-spotify-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\SpotifyIframe\Extension as SpotifyExtension;

$options = [
    'spotify_iframe' => [
        'size' => 'large',
    ],
];

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

$converter = new Converter($environment);

echo $converter->convert('[](https://open.spotify.com/embed/artist/xxx)');
echo $converter->convert('[](https://open.spotify.com/embed/track/xxx?theme=0)');
echo $converter->convert('[](https://open.spotify.com/embed/album/xxx?theme=1&size=small)');
echo $converter->convert('[](https://open.spotify.com/embed/playlist/xxx?theme=1&size=lg)');

Sizes

Spotify provides two different sizes, large and small. By default the extension provides the large version. You can configure the option globally using the size option.

You can also configure the size option using a query parameter on the embed URL. The supported sizes are large, lg, small and sm.

?size=large
?size=small
?size=lg
?size=sm

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.