| 1 |
--- |
| 2 |
icon: lucide/smile |
| 3 |
--- |
| 4 |
[:octicons-file-code-24:][_emoji]{: .source-link } |
| 5 |
|
| 6 |
# Emoji |
| 7 |
|
| 8 |
## Overview |
| 9 |
|
| 10 |
The Emoji extension adds support for inserting emoji via simple short names enclosed within colons: `:short_name:`. |
| 11 |
This is accomplished by using a short name index to map easy to remember names to associated Unicode data. The Unicode |
| 12 |
data is then converted into actual Unicode emoji characters and/or special HTML elements (usually images) that represent |
| 13 |
the emoji. |
| 14 |
|
| 15 |
``` |
| 16 |
:smile: :heart: :thumbsup: |
| 17 |
``` |
| 18 |
|
| 19 |
/// html | div.result |
| 20 |
:smile: :heart: :thumbsup: |
| 21 |
/// |
| 22 |
|
| 23 |
The Emoji extension can be included in Python Markdown by using the following: |
| 24 |
|
| 25 |
```py3 |
| 26 |
import markdown |
| 27 |
md = markdown.Markdown(extensions=['pymdownx.emoji']) |
| 28 |
``` |
| 29 |
|
| 30 |
## Supported Emoji Providers |
| 31 |
|
| 32 |
There are a number of emoji short name conventions that people may be aware of. These conventions are always tied to a |
| 33 |
specific emoji set. These conventions differ because there is no official Unicode short name convention. At the present, |
| 34 |
Emoji chooses to focus on three specific emoji sets: |
| 35 |
|
| 36 |
|
| 37 |
/// tab | EmojiOne |
| 38 |
[EmojiOne][emojione] (<img align="absmiddle" alt=":smile:" class="emojione" src="https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/assets/png/1f604.png" title=":smile:" /> <img align="absmiddle" alt=":heart:" class="emojione" src="https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/assets/png/2764.png" title=":heart:" /> <img align="absmiddle" alt=":thumbsup:" class="emojione" src="https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/assets/png/1f44d.png" title=":thumbsup:" />): |
| 39 |
EmojiOne is a high quality emoji set with support for gender and skin tone modifiers. Their free emoji set includes |
| 40 |
PNGs in sizes of 32x32, 64x64, and 128x128 which are all available via a CDN. |
| 41 |
|
| 42 |
The older EmojiOne (version 2.2.7), is what is used by default. It is the last truly free version. EmojiOne has |
| 43 |
rebranded with the name JoyPixels and now has an even more restrictive license for their graphical assets. Their |
| 44 |
latest short name list is still used for Twemoji as that portion is available under the MIT license via their |
| 45 |
toolkit repo @JoyPixels/emoji-toolkit. |
| 46 |
/// |
| 47 |
|
| 48 |
/// tab | Twemoji |
| 49 |
[Twemoji][twemoji] (<img align="absmiddle" alt=":smile:" class="twemoji" src="https://cdn.jsdelivr.net/gh/jdecked/[email protected]/assets/72x72/1f604.png" title=":smile:" /> <img align="absmiddle" alt=":heart:" class="twemoji" src="https://cdn.jsdelivr.net/gh/jdecked/[email protected]/assets/72x72/2764.png" title=":heart:" /> <img align="absmiddle" alt=":thumbsup:" class="twemoji" src="https://cdn.jsdelivr.net/gh/jdecked/[email protected]/assets/72x72/1f44d.png" title=":thumbsup:" />): |
| 50 |
Twemoji is Twitter's open source emoji set which also covers a great many emoji with skin tones and gender modifiers. |
| 51 |
The hosted CDN provides 72x72 PNG emoji or SVG emoji. |
| 52 |
|
| 53 |
While Gemoji and EmojiOne have a short name convention, Twemoji does not, and there are very few 3rd party projects |
| 54 |
that provide short names anywhere close to all the provided emoji that Twemoji supports. Since JoyPixels has an MIT |
| 55 |
licensed index of short names closest to what Twemoji supports, we use their short name list for Twemoji. There will |
| 56 |
be a reasonable attempt to patch in emoji not found in JoyPixels' index, but if JoyPixels is ever significantly |
| 57 |
behind, we may wait for JoyPixels to catch up. |
| 58 |
/// |
| 59 |
|
| 60 |
/// tab | Gemoji |
| 61 |
[Gemoji][gemoji] (<img align="absmiddle" alt=":smile:" class="gemoji" src="https://github.githubassets.com/images/icons/emoji/unicode/1f604.png" title=":smile:"/> <img align="absmiddle" alt=":heart:" class="gemoji"src="https://github.githubassets.com/images/icons/emoji/unicode/2764.png" title=":heart:"/> <img align="absmiddle" alt=":+1:" class="gemoji" src="https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png" title=":+1:" />): |
| 62 |
Gemoji is GitHub's open source emoji solution. It contains a lot of common emoji and a couple special, non Unicode |
| 63 |
emoji (like Gemoji's `:octocat:` <img align="absmiddle" alt=":octocat:" class="gemoji" src="https://github.githubassets.com/images/icons/emoji/octocat.png" title=":octocat:" />). |
| 64 |
If you are a GitHub user, you are probably familiar with some of the short names associated with it. Their |
| 65 |
associated CDN contains the emoji in 75x75 PNG format. |
| 66 |
/// |
| 67 |
|
| 68 |
/// warning | Emoji Image Licensing |
| 69 |
PyMdown Extensions has no affiliation with EmojiOne, Gemoji, or Twemoji. The indexes generated from their sources |
| 70 |
are covered under their respective licensing. When using their images or CSS, please see their licensing terms to |
| 71 |
ensure proper usage and attributions. |
| 72 |
|
| 73 |
//// tab | EmojiOne |
| 74 |
- https://github.com/joypixels/emoji-toolkit#joypixels-version-2 |
| 75 |
- http://creativecommons.org/licenses/by/4.0/ |
| 76 |
//// |
| 77 |
|
| 78 |
//// tab | Twemoji |
| 79 |
- https://github.com/jdecked/twemoji/blob/main/LICENSE-GRAPHICS |
| 80 |
//// |
| 81 |
|
| 82 |
//// tab | Gemoji |
| 83 |
- https://github.com/github/gemoji/blob/master/LICENSE |
| 84 |
//// |
| 85 |
/// |
| 86 |
|
| 87 |
All short name indexes that Emoji uses are generated from EmojiOne's or Gemoji's latest official source tag -- Twemoji |
| 88 |
uses JoyPixels' index as the Twemoji repository does not ship with a short name index. The indexes contain the emoji |
| 89 |
names, short names, values, etc.; everything needed to insert Unicode emoji characters or specially crafted HTML |
| 90 |
elements. |
| 91 |
|
| 92 |
## Emoji Output Formats |
| 93 |
|
| 94 |
Depending on your needs, you may have different requirements for how emoji get displayed in your documents. You may want |
| 95 |
to use PNG images, or maybe you really like SVG images. Maybe you just want to convert short names to the actual Unicode |
| 96 |
code points. There are a variety of ways you may want to output emoji, and the Emoji extension has you covered. |
| 97 |
|
| 98 |
Emoji provides various output formats that take the Unicode data associated with a short name (or the short name itself |
| 99 |
in the case of a custom emoji) and generates an HTML output. Not all of the provided output formats will work for each |
| 100 |
emoji index, but there are a few that should work for all three. Check out |
| 101 |
[Default Emoji Generators](#default-emoji-generators) or [Custom Emoji Generators](#custom-emoji-generators) to learn |
| 102 |
more. |
| 103 |
|
| 104 |
## Default Emoji Indexes |
| 105 |
|
| 106 |
By default, Emoji provides three indexes: `emojione`, `gemoji`, and `twemoji`. All indexes are generated from the most |
| 107 |
recent official release tag source (in the case of Twemoji, short names are acquired from the generated index in |
| 108 |
@JoyPixels/emoji-toolkit). They can be used by passing in one of the three functions below via the `emoji_index` |
| 109 |
parameter. Pass the actual function reference, not a string. If you need to create your own, just check out |
| 110 |
[Custom Emoji Indexes](#custom-emoji-generators). |
| 111 |
|
| 112 |
/// tip |
| 113 |
If you are attempting to configure these options in a YAML based configuration (like in [MkDocs][mkdocs]), please |
| 114 |
see the [FAQ](../faq.md#function-references-in-yaml) to see how to specify function references in YAML. |
| 115 |
/// |
| 116 |
|
| 117 |
/// tab | EmojiOne |
| 118 |
``` |
| 119 |
pymdownx.emoji.emojione |
| 120 |
``` |
| 121 |
|
| 122 |
This is the default function that is used. EmojiOne was rebranded as JoyPixels and is no longer permissible |
| 123 |
enough to be used. The release used here is for 2.2.7 which is the last usable, truly free version of EmojiOne. |
| 124 |
Users are still required to comply with acknowledgments. JoyPixels 3.0+ graphical assets will not be supported |
| 125 |
moving forward as the license is too restrictive, tough the latest index of their friendly names is supported |
| 126 |
under the MIT license and is used to generate friendly, short names for Twemoji. |
| 127 |
|
| 128 |
You can always find out what tag it was built with by doing the following: |
| 129 |
|
| 130 |
```pycon3 |
| 131 |
>>> import pymdownx.emoji1_db as e1db |
| 132 |
>>> e1db.version |
| 133 |
'v2.2.7' |
| 134 |
``` |
| 135 |
|
| 136 |
To see the full list of short names for this index, see the index [source][emojione-index]. |
| 137 |
/// |
| 138 |
|
| 139 |
/// tab | Twemoji |
| 140 |
``` |
| 141 |
pymdownx.emoji.twemoji |
| 142 |
``` |
| 143 |
|
| 144 |
This function provides an index of the latest Twemoji supported emoji (at the time of release). The associated |
| 145 |
short names are currently borrowed from JoyPixels' index found in their @JoyPixels/emoji-toolkit repo. JoyPixels |
| 146 |
short name index is available under the MIT license and is used as Twemoji does not provide its own list of |
| 147 |
short names. |
| 148 |
|
| 149 |
There are a few emoji that are currently Twemoji specific, two of which are likely to always be as they are not |
| 150 |
part of the official emoji spec. The short names are listed below. |
| 151 |
|
| 152 |
//// details-info | Twemoji Specific Emoji |
| 153 |
Twemoji provides some non-standard emoji. We've made them available following the naming patterns that |
| 154 |
EmojiOne follows as we are using their short name index. |
| 155 |
|
| 156 |
The emoji are either some that only Twemoji supports, rarely supported by others, or emoji that have tone |
| 157 |
and/or gender modifiers that aren't supported in the Unicode specifications. We've also provided appropriate |
| 158 |
aliases for consistency with other like emoji. |
| 159 |
|
| 160 |
``` |
| 161 |
:pirate_flag: |
| 162 |
:shibuya: |
| 163 |
|
| 164 |
:skier_tone1: |
| 165 |
:skier_tone2: |
| 166 |
:skier_tone3: |
| 167 |
:skier_tone4: |
| 168 |
:skier_tone5: |
| 169 |
|
| 170 |
:woman_levitate: |
| 171 |
:woman_levitate_tone1: |
| 172 |
:woman_levitate_tone2: |
| 173 |
:woman_levitate_tone3: |
| 174 |
:woman_levitate_tone4: |
| 175 |
:woman_levitate_tone5: |
| 176 |
|
| 177 |
:woman_in_business_suit_levitating_tone1: |
| 178 |
:woman_in_business_suit_levitating_tone2: |
| 179 |
:woman_in_business_suit_levitating_tone3: |
| 180 |
:woman_in_business_suit_levitating_tone4: |
| 181 |
:woman_in_business_suit_levitating_tone5: |
| 182 |
|
| 183 |
:woman_in_tuxedo: |
| 184 |
:woman_in_tuxedo_tone1: |
| 185 |
:woman_in_tuxedo_tone2: |
| 186 |
:woman_in_tuxedo_tone3: |
| 187 |
:woman_in_tuxedo_tone4: |
| 188 |
:woman_in_tuxedo_tone5: |
| 189 |
|
| 190 |
:transgender_sign: |
| 191 |
:transgender_flag: |
| 192 |
``` |
| 193 |
//// |
| 194 |
|
| 195 |
You can always find out what tag it was built with by doing the following: |
| 196 |
|
| 197 |
```pycon3 |
| 198 |
>>> import pymdownx.twemoji_db as twdb |
| 199 |
>>> twdb.version |
| 200 |
'v12.1.3' |
| 201 |
>>> twdb.index_version |
| 202 |
'5.0.5' |
| 203 |
``` |
| 204 |
|
| 205 |
To see the full list of short names for this index, see the index [source][twemoji-index]. |
| 206 |
/// |
| 207 |
|
| 208 |
/// tab | Gemoji |
| 209 |
``` |
| 210 |
pymdownx.emoji.gemoji |
| 211 |
``` |
| 212 |
|
| 213 |
This function provides an index of the latest Gemoji supported emoji (at the time of release). |
| 214 |
|
| 215 |
You can always find out what tag it was built with by doing the following: |
| 216 |
|
| 217 |
```pycon3 |
| 218 |
>>> import pymdownx.gemoji_db as gmdb |
| 219 |
>>> gmdb.version |
| 220 |
'v3.0.1' |
| 221 |
``` |
| 222 |
|
| 223 |
To see the full list of short names for this index, see the index [source][gemoji-index]. |
| 224 |
/// |
| 225 |
|
| 226 |
## Default Emoji Generators |
| 227 |
|
| 228 |
Emoji provides six default emoji generators. PNG output and Unicode code point output are supported for all three |
| 229 |
indexes. SVG output is only supported for Twemoji and the older 2.2.7 EmojiOne set. PNG sprites and the "Font Awesome" |
| 230 |
like format are only supported by EmojiOne. SVG sprites is only supported by the 2.2.7 EmojiOne. |
| 231 |
|
| 232 |
You can select a generator to use by passing in one of the functions below via the `emoji_generator` parameter. Pass |
| 233 |
the actual function reference, not a string. If you need to create your own, just check out |
| 234 |
[Custom Emoji Generators](#custom-emoji-generators). |
| 235 |
|
| 236 |
/// tip |
| 237 |
If you are attempting to configure these options in a YAML based configuration (like in [MkDocs][mkdocs]), please |
| 238 |
see the [FAQ](../faq.md#function-references-in-yaml) to see how to specify function references in YAML. |
| 239 |
/// |
| 240 |
|
| 241 |
/// tab | PNG |
| 242 |
``` |
| 243 |
pymdownx.emoji.to_png |
| 244 |
``` |
| 245 |
|
| 246 |
This is a general purpose generator which provides EmojiOne, GitHub, and Twemoji CDN path(s) out of the box. |
| 247 |
Depending on the index you've chosen, the appropriate CDN will be provided. If this ever gets out of date, |
| 248 |
a new CDN can be passed in via `image_path` and/or `non_standard_image_path`. EmojiOne actually has multiple |
| 249 |
PNGs sizes of 32, 64, and 128, but the default CDN path is the one for size 64: |
| 250 |
`https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/assets/png/64/`. You can change it for a larger or |
| 251 |
smaller PNG size by updating the size in the URL and passing the new URL in through `image_path`. The PNG output |
| 252 |
form is as follows: |
| 253 |
|
| 254 |
```html |
| 255 |
<img alt="😄" class="emojione" src="https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/assets/png/64/1f604.png" title=":smile:" /> |
| 256 |
``` |
| 257 |
|
| 258 |
**Generator Specific Options** |
| 259 |
|
| 260 |
Option | Type | Default | Description |
| 261 |
------------------------- | ---------- | ------------------------------ | ----------- |
| 262 |
`classes` | string | Name of the index used | Specifies the class(es) to be used in the image element. |
| 263 |
`image_path` | string | CDN for the default index used | This can be either a local path or a CDN containing the assets. By default, an appropriate CDN is provided for EmojiOne, Gemoji, and Twemoji depending on which index is being used. |
| 264 |
`non_standard_image_path` | string | CDN for the default index used | This can be either a local path, or a CDN containing the assets. This is often used for non-standard emoji that do not have an actual Unicode number, and cannot be found in this way. Gemoji used to use this for non-standard emoji like `:octocat:`, but none of those are available by default anymore. |
| 265 |
`attributes` | dictionary | `#!py3 {}` | A dictionary containing tag attributes as key value string pairs. The dictionary keys are the attribute names and dictionary values are the attribute values. |
| 266 |
/// |
| 267 |
|
| 268 |
/// tab | SVG |
| 269 |
``` |
| 270 |
pymdownx.emoji.to_svg |
| 271 |
``` |
| 272 |
|
| 273 |
This generator was written to output SVG images and supports EmojiOne and Twemoji. EmojiOne's SVG support is only |
| 274 |
for the free 2.2.7 release, so the default CDN still references the 2.2.7 release. EmojiOne short names added after |
| 275 |
2.2.7 will not find images. You can of course reference local SVG images as well by pointing `image_path` to them |
| 276 |
as well. The SVG image outputs as: |
| 277 |
|
| 278 |
```html |
| 279 |
<img alt="😄" class="emojione" src="https://cdn.jsdelivr.net/emojione/assets/svg/1f604.svg" title=":smile:" /> |
| 280 |
``` |
| 281 |
|
| 282 |
**Generator Specific Options** |
| 283 |
|
| 284 |
Option | Type | Default | Description |
| 285 |
------------ | ---------- | ------------------------- | ----------- |
| 286 |
`classes` | string | Name of the index used | Specifies the class(es) to be used in the image element. The default will match the name of the index used. |
| 287 |
`image_path` | string | A CDN for EmojiOne images | This can be either a local path or a CDN containing the assets. By default, an appropriate CDN is provided for EmojiOne. |
| 288 |
`attributes` | dictionary | `#!py3 {}` | A dictionary containing tag attributes as key value string pairs. The dictionary keys are the attribute names and dictionary values are the attribute values. |
| 289 |
/// |
| 290 |
|
| 291 |
/// tab | PNG Sprite |
| 292 |
``` |
| 293 |
pymdownx.emoji.to_png_sprite |
| 294 |
``` |
| 295 |
|
| 296 |
This generator was written to support PNG sprite output for EmojiOne. It is expected that this will be used in |
| 297 |
conjunction with the official EmojiOne CSS. You can include the CSS from the CDN in your document. The CSS comes in |
| 298 |
three sizes: 32, 64, 128. Make sure to set the correct size in the options to generate the appropriate classes. |
| 299 |
|
| 300 |
Example CDN for the 2.2.7 version with 64px PNGs: |
| 301 |
`https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/assets/sprites/emojione.sprites.css`. |
| 302 |
|
| 303 |
`to_png_sprite` outputs the emoji as a span in the form below. The CSS will apply the appropriate mapping in the |
| 304 |
sprite PNG to the background image of the span. |
| 305 |
|
| 306 |
```html |
| 307 |
<span class="emojione-64-people _1f604" title=":smile:">😄</span> |
| 308 |
``` |
| 309 |
|
| 310 |
**Generator Specific Options** |
| 311 |
|
| 312 |
Option | Type | Default | Description |
| 313 |
------------ | ---------- | ---------------------- | ----------- |
| 314 |
`classes` | string | Name of the index used | Class(es) used for the span where the classes are inserted as "class" in the following template: `#!py3 '%(class)s-%(size)s-%(category)s _%(unicode)s'`. |
| 315 |
`size` | int | `#!py3 64` | Integer specifying the size for the class above. |
| 316 |
`attributes` | dictionary | `#!py3 {}` | A dictionary containing tag attributes as key value string pairs. The dictionary keys are the attribute names and dictionary values are the attribute values. |
| 317 |
/// |
| 318 |
|
| 319 |
/// tab | SVG Sprite |
| 320 |
``` |
| 321 |
pymdownx.emoji.to_svg_sprite |
| 322 |
``` |
| 323 |
|
| 324 |
This was written to support EmojiOne SVG sprite output. The output form was taken directly from an example in the |
| 325 |
EmojiOne source. It is expected that the user will provide a local version of the official SVG sprite and the path to |
| 326 |
it. Unfortunately there is no free 3.0 SVG sprite, so you will need to [download][emojione-sprites-svg] the old 2.27 |
| 327 |
one. The output is: |
| 328 |
|
| 329 |
```html |
| 330 |
<svg class="emojione"><description>😄</description><use xlink:href="./../assets/sprites/emojione.sprites.svg#emoji-1f604"></use></svg> |
| 331 |
``` |
| 332 |
|
| 333 |
**Generator Specific Options** |
| 334 |
|
| 335 |
Option | Type | Default | Description |
| 336 |
------------ | ------ | ---------------------- | ----------- |
| 337 |
`classes` | string | Name of the index used | Class(es) to apply to the `svg` element where the classes are inserted as "class" in the following template: `#!py3 '%(class)s-%(unicode)s'`. |
| 338 |
`image_path` | string | `#!py3 ''` | Path to the SVG sprites. |
| 339 |
/// |
| 340 |
|
| 341 |
/// tab | Alt |
| 342 |
``` |
| 343 |
pymdownx.emoji.to_alt |
| 344 |
``` |
| 345 |
|
| 346 |
This generator supports all emoji indexes. The generator outputs the alt value directly to the document. The |
| 347 |
output can be Unicode characters, HTML entities, or even just the short name depending on what the global setting of |
| 348 |
`alt` is set to. |
| 349 |
|
| 350 |
```html |
| 351 |
😃 |
| 352 |
``` |
| 353 |
|
| 354 |
There are no generator specific options. |
| 355 |
/// |
| 356 |
|
| 357 |
## Custom Emoji Indexes |
| 358 |
|
| 359 |
```py3 |
| 360 |
def emoji_index(options, md) |
| 361 |
``` |
| 362 |
|
| 363 |
In order to provide a custom index, the Emoji extension must be given a function that returns a suitable emoji index. |
| 364 |
The function should simply return the custom index. It accepts both an options dictionary and the markdown object. The |
| 365 |
options dictionary is the same object that is specified in the extensions [settings](#options). |
| 366 |
|
| 367 |
The index should be returned in the following format: |
| 368 |
|
| 369 |
/// collapse-code |
| 370 |
```py |
| 371 |
emoji_index = { |
| 372 |
# Name is the name of the index. This is passed into the emoji |
| 373 |
# generator functions and can be used to differentiate logic |
| 374 |
# for different indexes if required. |
| 375 |
"name": "myindex", |
| 376 |
|
| 377 |
# The actual index. A dictionary of all the emoji. |
| 378 |
# Different emoji short names with the same Unicode data |
| 379 |
# can be mentioned under aliases. |
| 380 |
"emoji": { |
| 381 |
# Key is the short name. |
| 382 |
":zero:": { |
| 383 |
|
| 384 |
# Name is the long name. |
| 385 |
"name": "keycap digit zero", |
| 386 |
|
| 387 |
# Category of emoji. |
| 388 |
# Not needed if this is a non-Unicode, custom |
| 389 |
# emoji with no category |
| 390 |
"category": "symbol", |
| 391 |
|
| 392 |
# Unicode is the representation of the Unicode |
| 393 |
# code points, but it is not necessarily valid Unicode |
| 394 |
# code points. Essentially it is what represents the Unicode |
| 395 |
# and is used as the image name for pngs and svgs. Depending |
| 396 |
# on the index, it may not be code points alt all. It is also |
| 397 |
# sometimes used as part of special class names in the HTML |
| 398 |
# output (depending on the generator). |
| 399 |
# |
| 400 |
# In the case of Gemoji and EmojiOne this is the Unicode code |
| 401 |
# points with variations and joiners striped out. In the case of |
| 402 |
# Twemoji, it is usually full valid code points though leading |
| 403 |
# zeros are stripped from the beginning. |
| 404 |
# |
| 405 |
# Do not include this if the emoji is a custom, non-Unicode emoji. |
| 406 |
"unicode": "0030-20e3", |
| 407 |
|
| 408 |
# This is the full Unicode code points and is |
| 409 |
# used for the "alt" attributes in the HTML output of images. |
| 410 |
# It is redundant to include this if it is the |
| 411 |
# same as 'unicode', but it won't hurt anything if it is. |
| 412 |
# |
| 413 |
# Do not include this if the emoji is a custom, |
| 414 |
# non-Unicode emoji. This shows a fully qualified emoji code, |
| 415 |
# but it could just as easily be "0030-2033" which is also valid. |
| 416 |
# Some indexes will provide fully qualified, some may not. |
| 417 |
"unicode_alt": "0030-fe0f-20e3" |
| 418 |
}, |
| 419 |
# No need to specify 'unicode_alt' as it is the same |
| 420 |
# as 'unicode'. |
| 421 |
":thumbsup:": { |
| 422 |
"name": "thumbs up sign", |
| 423 |
"unicode": "1f44d", |
| 424 |
"category": "people" |
| 425 |
}, |
| 426 |
# Should not specify any unicode fields |
| 427 |
# as this is not a real unicode emoji. |
| 428 |
":octocat:": { |
| 429 |
"name": "octocat" |
| 430 |
}, |
| 431 |
}, |
| 432 |
# Short names that share previously defined Unicode data |
| 433 |
# like '+1' and 'thumbsup' etc. |
| 434 |
"aliases": { |
| 435 |
# Key is the alias. |
| 436 |
# Value is the short name it maps to in the |
| 437 |
# previously defined 'emoji' key. |
| 438 |
":+1:": ":thumbsup:" |
| 439 |
} |
| 440 |
} |
| 441 |
``` |
| 442 |
/// |
| 443 |
|
| 444 |
/// new | New 7.1 |
| 445 |
Emoji indexes now accept `options` and `md`. The old sans argument format will still be accepted, but in the future |
| 446 |
the arguments will be expected. |
| 447 |
/// |
| 448 |
|
| 449 |
## Custom Emoji Generators |
| 450 |
|
| 451 |
```py3 |
| 452 |
def emoji_generator(index, shortname, alias, uc, alt, title, category, options, md) |
| 453 |
``` |
| 454 |
|
| 455 |
Each different kind of output is controlled by a different emoji generator function, but all generator functions have |
| 456 |
the same input format. The options object is the same object that is specified in the extensions [settings](#options) |
| 457 |
and is shared with the index as well. |
| 458 |
|
| 459 |
Parameter | Type |Description |
| 460 |
----------- | ---------- | ---------- |
| 461 |
`index` | string | The name of the selected emoji index. |
| 462 |
`shortname` | string | The current short name. This may differ from the actual name used in a document as aliases get translated to the main short name. |
| 463 |
`alias` | string | If the specified short name is an alias, that alias will be set here, and the main short name will be found under `shortname`. This will be `None` if the name used was not an alias. |
| 464 |
`uc` | string | This is a string representation of the Unicode, it could technically be anything as this is normally used to reference image files. So while some indexes will have this be code points, it may not contain code points at all or it may strip out code points for simpler image names. So the value here will not always be practical for calculating the actual Unicode points of an emoji. This will be `None` for non-standard emoji that are not Unicode. |
| 465 |
`alt` | string | This is the alternative emoji value (or fallback value). Its format will differ depending on the extension setting `alt` and also the index being used. This will be returned as either the full valid Unicode characters or HTML entities, or it will be the short name used. See the `alt` setting for more info. |
| 466 |
`title` | string | This is the title that can be used in image elements. Depending on the global extension setting `title`, this will either return the full long description, the short name, or `None`. See the `title` setting for more info. |
| 467 |
`category` | string | Category of the emoji, or `None` if there is no category for the emoji. |
| 468 |
`options` | dictionary | This is a dictionary to specify generator and index function specific options. This can be anything, and it is up to the generator function and the index function to parse relevant options and provide defaults. |
| 469 |
`md` | class | This is the Markdown class object. This is mainly used to access specific things needed from the Markdown class when formatting your output. If you needed to stash your output, you would do something like: `#!py3 md.htmlStash.store(alt, safe=True)`. |
| 470 |
|
| 471 |
/// warning | Non-Unicode emoji |
| 472 |
Keep in mind that Gemoji ships with some non-standard emoji like `:octocat:` that do not have Unicode code |
| 473 |
points. `uc` and `alt` are affected by this and will return `None` and the short name respectively instead of |
| 474 |
strings describing the Unicode points. For example `:octocat:` will just return `None` for `uc` and `:octocat:` |
| 475 |
for `alt`. If you are parsing an index with custom emoji, like Gemoji has, then you need to be aware of this. |
| 476 |
/// |
| 477 |
|
| 478 |
## Using with MkDocs |
| 479 |
|
| 480 |
This project uses these extensions with [MkDocs][mkdocs] to generate the documentation. It might not be obvious how to |
| 481 |
set the index or generator functions in MkDocs' YAML settings file, but it is actually pretty easy. The functions are |
| 482 |
referenced like you would import them in Python except you also append them with a special prefix to let the YAML module |
| 483 |
know that the setting value is a Python object. For instance, to specify the `to_svg` generator, you would simply |
| 484 |
reference it like this: `#!yaml !!python/name:pymdownx.emoji.to_svg` (or you could use your own custom module :wink:). |
| 485 |
|
| 486 |
```yaml |
| 487 |
markdown_extensions: |
| 488 |
- pymdownx.emoji: |
| 489 |
emoji_generator: !!python/name:pymdownx.emoji.to_svg |
| 490 |
``` |
| 491 |
|
| 492 |
## Emoji Index Updates |
| 493 |
|
| 494 |
The Emoji extension might at times be behind on having indexes built from the latest repositories. We try to keep the |
| 495 |
indexes updated with new releases, but if they fall out of date, you can open an issue on the this project's issue page |
| 496 |
to alert the maintainer(s) and they will update them when someone gets a chance. Pull requests are also welcome. The |
| 497 |
process for updating the indexes is automated, so it is fairly easy to do a pull request. See |
| 498 |
[Generating Emoji Indexes](../about/development.md#generating-emoji-indexes) for more info. |
| 499 |
|
| 500 |
## Options |
| 501 |
|
| 502 |
Option | Type | Default | Description |
| 503 |
--------------------------- | ---------- | -------------------- | ----------- |
| 504 |
`emoji_index` | function | `emojione` index | A function that returns the index to use when parsing `:short_name:` syntax. See [Default Emoji Indexes](#default-emoji-indexes) to see the provided indexes. |
| 505 |
`emoji_generator` | function | `to_png` generator | A function that takes the emoji info and constructs the desired emoji output. See [Default Emoji Generators](#default-emoji-generators) to see the provided generators. |
| 506 |
`title` | string | `#!python 'short'` | Specifies the title format that is fed into the emoji generator function. Can either be `long` which is the long description of the emoji, `short` which is the short name (`:short:`), or `none` which will simply pass `None`. |
| 507 |
`alt` | string | `#!python 'unicode'` | Specifies the format for the alt value that is passed to the emoji generator function. If `alt` is set to `short`, the short name will be passed to the generator. If `alt` is set to `unicode` the Unicode characters are passed to the generator. Lastly, if `alt` is set to `html_entity`, the Unicode characters are passed encoded as HTML entities. |
| 508 |
`remove_variation_selector` | bool | `#!python False` | Specifies whether variation selectors should be removed from Unicode alt. Currently, only `fe0f` is removed as it is the only one presently found in the current emoji sets. |
| 509 |
`options` | dictionary | `#!python {}` | Options that are specific to emoji generator functions. Supported parameters can vary from function to function. |
| 510 |
`strict` | bool | `#!python False` | Raise an exception if an emoji is used whose name is not found in the database. |
| 511 |
|
| 512 |
/// new | New 7.1 |
| 513 |
`options` is now shared between index and generator functions opposed to being passed to the generator function |
| 514 |
only. The generator and/or index function should decide which of the arguments are relevant for its usage and parse |
| 515 |
accordingly. |
| 516 |
/// |
| 517 |
|
| 518 |
/// new | New 10.12 |
| 519 |
Added `strict` mode. |
| 520 |
/// |
| 521 |
|
| 522 |
/// tip | Legacy GitHubEmoji Emulation |
| 523 |
The Emoji extension was actually created to replace the now retired GitHubEmoji extension. Emoji was written to be |
| 524 |
much more flexible. If you have a desire to configure the output to be like the legacy GitHubEmoji extension, you |
| 525 |
can use the settings below. This shows the full setup. To learn more about the settings used, continue reading the |
| 526 |
documentation. |
| 527 |
|
| 528 |
```py3 |
| 529 |
import pymdownx.emoji |
| 530 |
|
| 531 |
extension_configs = { |
| 532 |
"pymdownx.emoji": { |
| 533 |
"emoji_index": pymdownx.emoji.gemoji, |
| 534 |
"emoji_generator": pymdownx.emoji.to_png, |
| 535 |
"alt": "short", |
| 536 |
"options": { |
| 537 |
"attributes": { |
| 538 |
"align": "absmiddle", |
| 539 |
"height": "20px", |
| 540 |
"width": "20px" |
| 541 |
}, |
| 542 |
"image_path": "https://assets-cdn.github.com/images/icons/emoji/unicode/", |
| 543 |
"non_standard_image_path": "https://assets-cdn.github.com/images/icons/emoji/" |
| 544 |
} |
| 545 |
} |
| 546 |
} |
| 547 |
``` |
| 548 |
/// |