Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/giberti/commonmark-emoji-extension

An extension to provide support for converting GitHub and Slack flavored emoji support to the League CommonMark package.
https://github.com/giberti/commonmark-emoji-extension

commonmark emoji php7 php8

Last synced: 2 months ago
JSON representation

An extension to provide support for converting GitHub and Slack flavored emoji support to the League CommonMark package.

Awesome Lists containing this project

README

        

# CommonMark Emoji Extension

An extension to provide GitHub and Slack style emoji for the [League CommonMark package](https://commonmark.thephpleague.com/).
By default, it will substitute official [unicode CLDR short names](http://unicode.org/emoji/charts/full-emoji-list.html) for the emoji, but can also use aliases to map common language to the official name.
The generated output wraps the emoji in a `` to permit additional styling and provides a `title` attribute for accessibility.

## Quality

[![Build and Test](https://github.com/giberti/commonmark-emoji-extension/actions/workflows/test-php.yml/badge.svg)](https://github.com/giberti/commonmark-emoji-extension/actions/workflows/test-php.yml)

### Installing

```
composer require giberti/commonmark-emoji-extension
```

## Usage

```php
use Giberti\EmojiExtension\EmojiExtension;
```

### Basic

To use, add a new instance of `EmojiExtension` to the CommonMark environment and use as you would normally.

```php
// Get a configured instance of the converter
$environment = new \League\CommonMark\Environment\Environment();
$environment->addExtension(new \League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension());
$environment->addExtension(new \Giberti\EmojiExtension\EmojiExtension());
$converter = new \League\CommonMark\MarkdownConverter($environment);

//

I can haz ?


echo $converter->convert('I can haz :hot_beverage:?')->getContent();
```

### Providing Aliases

GitHub and Slack both shortcuts that do not map directly to the official Unicode CLDR Short Name. Mappings can be injected at the time the instance of `EmojiExtension` is created.

The Aliases should be passed as an associative array with the key being the new alias and the value being the CLDR Short Name equivalent.

```php
$aliases = [
':coffee:' => ':hot_beverage:',
':smile:' => ':grinning_face_with_smiling_eyes:',
// ... any other aliases you wish to support
];

// Get a configured instance of the converter
$environment = new \League\CommonMark\Environment\Environment();
$environment->addExtension(new \League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension());
$environment->addExtension(new \Giberti\EmojiExtension\EmojiExtension($aliases));
$converter = new \League\CommonMark\MarkdownConverter($environment);

//

I can haz ?


echo $converter->convert('I can haz :coffee:?')->getContent();
```