Documentation
¶
Overview ¶
Package twemoji serves the Twemoji emoji graphics (jdecked/twemoji, the community continuation of Twitter's set; graphics CC-BY 4.0 — see TWEMOJI-LICENSE-GRAPHICS) as SVG documents keyed by emoji sequence, with the :shortcode: table of markdown-it-emoji (MIT — see MARKDOWN-IT-EMOJI-LICENSE).
It is a DATA package: it embeds the SVGs, compressed, and hands one back; it draws nothing. The archive is inflated lazily, a block at a time, and the lookup tables are built on first use, so importing the package costs a few kilobytes of address space and no start-up time.
Attribution ¶
The graphics are licensed CC-BY 4.0: whoever shows them must credit "Twemoji, Copyright 2020 Twitter, Inc and other contributors (CC-BY 4.0), continued by the jdecked/twemoji project". Attribution is the one condition this package cannot meet for its users.
Names ¶
An emoji's STEM is the file name Twemoji gives its graphic: the code points in lower-case hexadecimal joined with "-", with U+FE0F (the emoji presentation selector) dropped unless the sequence has a ZWJ: 😄 is "1f604", 🇫🇷 is "1f1eb-1f1f7", 👩💻 is "1f469-200d-1f4bb", 1️⃣ is "31-20e3". Lookups here ignore U+FE0F altogether, so a sequence finds its graphic however the text qualified it.
Index ¶
- Constants
- func Cut(s string) int
- func Err() error
- func Find(s string, from int) (start, end int)
- func Len() int
- func Lookup(seq string) string
- func Replace(s string, f func(name, seq string) string) string
- func SVG(seq string) (string, bool)
- func SVGByStem(stem string) (string, bool)
- func Shortcode(name string) (string, bool)
- func Shortcodes() []string
- func Stem(seq string) string
- func Stems() []string
- func TextDefault(r rune) bool
Constants ¶
const ( Version = "17.0.3" ShortcodesVersion = "3.0.0" )
Version is the Twemoji release the embedded graphics come from, and ShortcodesVersion the markdown-it-emoji release of the :shortcode: table.
const Attribution = "Twemoji, Copyright 2020 Twitter, Inc and other contributors (CC-BY 4.0), continued by the jdecked/twemoji project"
Attribution is the credit CC-BY 4.0 asks for.
Variables ¶
This section is empty.
Functions ¶
func Cut ¶
Cut returns the byte length of the emoji at the start of s, or 0 when s does not start with one. It reads text the way Marp Core does (the emoji-regex it matches with, then Twemoji's parser):
- the match is the longest sequence the set has a graphic for, with or without U+FE0F inside it;
- a character whose default presentation is text (©, ™, ☺, ✔, ▶: see TextDefault) is an emoji only when U+FE0F follows it — except ❤ (U+2764), which is an emoji bare;
- a U+FE0F after a character that is already an emoji by default (😄) is not part of the match; after a text-default one it is (Marp Core also takes it after about thirty BMP emoji such as ⚽ ☕ ♈; the difference is an invisible U+FE0F left in the text or not);
- a match followed by U+FE0E (text presentation selector) is not one;
- a lone regional indicator is not a flag, a bare digit, # or * is not a keycap (they are with U+20E3), and nothing in the private use area is an emoji.
func Err ¶
func Err() error
Err reports why the embedded data could not be read: nil unless the package was built from a damaged archive, which its tests rule out.
func Lookup ¶
Lookup returns the stem of the embedded graphic for seq, ignoring U+FE0F, or "" when the set has none.
func Replace ¶
Replace is the :shortcode: pass of markdown-it-emoji over text: each :name: that names a shortcode becomes f(name, sequence). Matches do not overlap; ":a:smile:" yields the smile, since ":a:" names nothing. Text without a colon is returned as is.
func SVG ¶
SVG returns the SVG document of the graphic for seq (a sequence in any qualification: with or without U+FE0F), and whether the set has one.
func Shortcode ¶
Shortcode returns the sequence of the :name: shortcode (name without the colons: "smile", "+1", "100"), and whether it is defined.
func Stem ¶
Stem is the name Twemoji gives the graphic of seq, computed the way twemoji.js does: lower-case hexadecimal code points joined with "-", U+FE0F dropped unless seq contains a ZWJ. It does not look at the embedded set; see Lookup.
func TextDefault ¶
TextDefault reports whether r is an emoji whose default presentation is text: a plain glyph unless U+FE0F follows it (© ™ ↔ ☺ ✔ ▶ and about 200 more, from Unicode's emoji-sequences.txt).
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gen
command
Command gen regenerates twemoji.bin and shortcodes.txt from upstream:
|
Command gen regenerates twemoji.bin and shortcodes.txt from upstream: |
|
internal
|
|
|
gen
Package gen turns the two upstream sources into the files twemoji embeds: the Twemoji SVG assets into twemoji.bin, markdown-it-emoji's shortcode table into shortcodes.txt, and Unicode's emoji-sequences.txt into the list of text-presentation characters, textdefault.txt.
|
Package gen turns the two upstream sources into the files twemoji embeds: the Twemoji SVG assets into twemoji.bin, markdown-it-emoji's shortcode table into shortcodes.txt, and Unicode's emoji-sequences.txt into the list of text-presentation characters, textdefault.txt. |
|
pack
Package pack is the archive format of the embedded SVGs: documents sorted by key, cut into blocks of about BlockSize bytes, each block deflated on its own.
|
Package pack is the archive format of the embedded SVGs: documents sorted by key, cut into blocks of about BlockSize bytes, each block deflated on its own. |