-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
index.js
36 lines (32 loc) · 901 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import extend from "just-extend"
import emojiRegex from "regex-emoji"
import kebab from "just-kebab-case"
const id = "emoji"
// You need emoji.css to run with this plugin. Else you need to pass the
// template suitable to your needs.
export default function emoji(opts) {
const defaultOptions = {
id,
regex: emojiRegex(),
template(emojiName) {
return `<span class="ec ec-${kebab(emojiName)}"></span>`
}
}
const pluginOptions = extend({}, defaultOptions, opts)
return {
transform(options) {
return Promise.resolve(
extend({}, options, {
result: options.result.replace(
pluginOptions.regex,
(match, emojiName) => {
options._services.push({ id, match })
return pluginOptions.template(emojiName, options, pluginOptions)
}
)
})
)
}
}
}
emoji.id = id