marked-twemoji
v1.0.0
Published
Simple plugin to add twemoji support
Downloads
7
Readme
marked-twemoji
A simple plugin to add twemoji for marked
How to use
First, install plugin
npm i marked-twemoji
Then add it as an extension for marked
const { marked } = require('marked');
const { markedTwemoji } = require('marked-twemoji');
marked.use({ extensions: [markedTwemoji] });
marked(':heart:') // <p><img class="emoji" draggable="false" alt="❤️" src="https://twemoji.maxcdn.com/v/14.0.2/svg/2764.svg"/></p>
The stylesheet style.css
is a recommended style for .emoji
class, but feel free to define yourself
.emoji {
background: transparent;
height: 1em;
margin: 0 0.05em 0 0.1em !important;
vertical-align: -0.1em;
width: 1em;
}
Md-to-pdf
It is possible to use marked-twemoji
with md-to-pdf project by creating a custom config.
- Create a
config.js
file:
const { markedTwemoji } = require('marked-twemoji');
module.exports = {
css: `
.emoji {
background: transparent;
height: 1em;
margin: 0 0.05em 0 0.1em !important;
vertical-align: -0.1em;
width: 1em;
}
`,
marked_extensions: [markedTwemoji],
};
- Use md-to-pdf with config file
md-to-pdf --config-file config.js example.md
How does it work
Based on this issue and twemoji, I added a custom marked
extension to convert emojis.
Basically it looks for :abc:
pattern, and use twemoji to replace it with an <img>
Contributing
Please feel free to contribute
- To run unit tests
npm test
- Format code
npm run fmt
Credits
Special thanks to:
- simonhaenisch for helping me creating this plugin and how to include it into md-to-pdf