A Bit of a Bodge To Make MASSIVE Emoji
I’ve been fiddling with an instance of Known over on social.omgmog.net. As part of my fiddling I’ve been trying out some of the plugins for Known. I came across the “Render Emoji Unicode” plugin but it was using an old library, and referencing an old version of Twemoji, so I updated it to use the latest Twemoji library.
Twe-who-ji?
Twitter’s open source emoji has you covered for all your project’s emoji needs. With support for the latest Unicode emoji specification, featuring 3,245 emojis, and all for free.
The nice thing about Twemoji is that you can parse a chunk of text and convert any matched emojis to their Twemoji-based img counterparts. Why would you want to do this? Well for me it’s for consistency. I don’t like the per-platform variation with emoji.
To get started, you first load the library from a CDN and then tell it what to parse:
twemoji.parse(document.body);
By default it will use .png images, but you can tell it to use .svg. it will replace any emoji it finds with an img tag referencing the appropriate image:
💩
becomes
<img draggable="false" class="emoji" alt="💩" src="https://twemoji.maxcdn.com/v/14.0.2/svg/1f4a9.svg">
Let me take you on a journey
I’ve always enjoyed how Slack makes the emoji in messages containing just emoji massive – JUMBOMOJI – and so I thought it’d be cool to bring that feature to my site too.

My first thought was that I could use the :only-child pseudo-selector to select a solo <img class="emoji" />. It worked, sort of, except it also detected any single img.emoji amongst text nodes as being an :only-child.
What’t the deal with that? Well CSS doesn’t recognise the Text node as being a distinct element like JavaScript does. It would cause all sorts of headaches if it did – imagine having to consider how to handle chunks of whitespace in/around elements! (For now let’s skip over the historical horrors of handling floated elements, inline elements, and the perils of space around them.)
We’re already leveraging JavaScript to convert emoji to Twemoji, it probably wouldn’t hurt too much to also process the surrounding DOM a little, would it?
DOM traversial to keep you awake at night
So I arrived at wrapping any non-whitespace Text nodes in <span> tags to make it easier for CSS to explicitly recognise them as a first-class citizen node.
document.querySelectorAll('.e-content').forEach(block => {
twemoji.parse(block, {folder:'svg', ext:'.svg'});
block.childNodes.forEach(child => {
if (child.nodeType === 3 && child.textContent.trim().length) {
const nodeWrapper = document.createElement('span');
child.parentNode.insertBefore(nodeWrapper, child);
nodeWrapper.appendChild(child);
}
});
});
It feels a bit dirty to be manipulating the DOM of all blocks containing non-whitespace text, even if there are no img.emoji present, but I don’t imagine it will give to much of a performance hit.
Here’s how it looks with my extremely thorough test suite:

On an unrelated note, TIL that Jekyll (probably just Jekyll on Windows?) doesn’t like emojis for filenames of images. At first I thought it was the way I was referencing the image in my post, so I tried the following forms:
💩,xn--ls8h,%F0%9F%92%A9– but none of those resolved the issue until I used a regular filename for the image. 🤷
Related posts
- Adding support for Webmentions
I’ve added Webmention support to the posts on this blog. Webmentions are a method for websites to know that they’ve been linked to (or mentioned) from elsewhere on the web.
- Enriching webmentions from third-party platforms
I keep finding new gaps in my webmention implementation. Mentions coming in from Bluesky, Lemmy and Lobsters were showing up with no author at all, just a blank avatar and an empty name. Reddit and Hacker News bookmarks fared a bit better, with a username attached, but got flattened into a generic “bookmarked” icon with no indication of where the post had actually been shared. Lobsters mentions also carried the wrong published date. None of these felt like they were pulling their weight compared to a proper webmention from a blog or Mastodon.
- Sending webmentions on deploy
I’ve spent a fair bit of time on the receiving end of webmentions, from adding support for them in the first place through to fetching them at build time and rendering them server-side so the discussion section doesn’t flicker in over JS. What I’d never actually done was send the other half. Every link I’ve ever made out to another IndieWeb site has just sat there, silently not telling anyone I’d linked to them.
Discussion
No interactions yet
Join the conversation
Reply from your own site with a Webmention (how?).
