https://github.com/uzitech/marked-emoji
https://github.com/uzitech/marked-emoji
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/uzitech/marked-emoji
- Owner: UziTech
- License: mit
- Created: 2022-12-22T06:46:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T03:27:34.000Z (4 months ago)
- Last Synced: 2025-03-13T01:35:27.732Z (4 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/marked-emoji
- Size: 2.28 MB
- Stars: 16
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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) => ``
};marked.use(markedEmoji(options));
marked.parse("I :heart: marked! :tada:");
//I
marked!
// 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. The value will be passed directly to the renderer as the `token.emoji` property |
| renderer | Octokit renderer: ``(token) => `` `` | A function that takes a token object and renders a string. |
## `token`
| property | type | description |
|----------|------|-------------|
| emoji | any | The emoji value. |
| name | string | The emoji name. |