Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/uzitech/marked-emoji


https://github.com/uzitech/marked-emoji

Last synced: 19 days ago
JSON representation

Awesome Lists containing this project

README

        

# marked-emoji
Parse `:emoji:` as emoji either unicode characters or images. You have to provide your own emojis. The example uses the list of emojis provided by `@octokit/rest` but you can also just create your own list from any source.

The `emojis` option is required.

# Usage

## Octokit example

```js
import {marked} from "marked";
import {markedEmoji} from "marked-emoji";

// or UMD script
//
//

import {Octokit} from "@octokit/rest";

const octokit = new Octokit();
// Get all the emojis available to use on GitHub.
const res = await octokit.rest.emojis.get();
/*
* {
* ...
* "heart": "https://...",
* ...
* "tada": "https://...",
* ...
* }
*/
const emojis = res.data;

const options = {
emojis,
renderer: (token) => `${token.name}`
};

marked.use(markedEmoji(options));

marked.parse("I :heart: marked! :tada:");
//

I heart marked! tada


// I ❤️ marked! 🎉
```

## Unicode example

```js
const options = {
emojis: {
"heart": "❤️",
"tada": "🎉"
},
renderer: (token) => token.emoji
};

marked.use(markedEmoji(options));

marked.parse("I :heart: marked! :tada:");
//

I ❤️ marked! 🎉


```

## Font Awesome example

```js
const options = {
emojis: {
"heart": "fa-heart",
"tada": "fa-tada"
},
renderer: (token) => ``
};

marked.use(markedEmoji(options));

marked.parse("I :heart: marked! :tada:");
//

I marked!


// I ❤️ marked! 🎉
```

## `options`

| option | default | description |
|--------|---------|-------------|
| emojis | required | An object with keys as emoji name and values as emoji. |
| renderer | Octokit renderer: ``(token) => `${token.name}` `` | A function that takes a token object and renders a string. |

## `token`

| property | type | description |
|----------|------|-------------|
| emoji | string | The emoji value. |
| name | string | The emoji name. |