Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uzitech/marked-emoji
https://github.com/uzitech/marked-emoji
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/uzitech/marked-emoji
- Owner: UziTech
- License: mit
- Created: 2022-12-22T06:46:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T03:30:57.000Z (25 days ago)
- Last Synced: 2024-10-25T07:17:55.335Z (21 days ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/marked-emoji
- Size: 2.7 MB
- Stars: 14
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
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. |
| renderer | Octokit renderer: ``(token) => `` `` | 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. |