Auto-replace emoji like ☺ with Discourse codes

Over on TDWTF, I’ve been using a bot to automatically replace Unicode emoji like :slight_smile: with Discourse emoji codes like :smile:; it’s useful when posting from mobile. @codinghorror suggests it could be made a Discourse feature; it never occurred to me before, but it does sound like it’d be useful. That way it could also work in PMs, which is something I haven’t got working in my bot yet.

10 Likes

This is what happened with my first post on the Nexus @codinghorror sent me! I was thinking about that concept too. Glad I’m not the only one.

Would we not be able to do something like this already by using…

Discourse.Dialect.registerEmoji('☺', '/plugins/trout_emoji/images/trout-square.jpg');

Or something along those lines?

Not that trivial to do efficiently, see:

In particular you need to map the unicode → code points → emoji image. This means that we need to scan through every char and check it to see if its an emoji.

We can not afford to cripple the editor here so whatever we do needs to be using lots of fancy tricks.

1 Like

Does it need to be done in the editor though? On desktop, people will normally use the Discourse emoji code auto-complete instead of Unicode emoji; it’s only really those on mobile (which has no preview pane IIRC) that will be using Unicode emoji.

No, this should only be done server side on post bake. No need to clutter the client with this.

4 Likes

Server side this is much more practical, we already do a bunch of nokogiri passes.

Any particular benefit for this? Using Discourse™ and other programs under Linux© I usually :heart: typing emoji at least ¾ of the time inline using Compose - can make most of the really common ones even ← arrows →.

That’s right - I’m the ♔ of edge user cases. :stuck_out_tongue_winking_eye:

5 Likes

Isn’t Emoji One designed to do exactly this?

http://emojione.com/

Although I guess that would only replace with Emoji One emojis rather than the forum’s customised emoji choices.

Mostly for those on Windows 7 and other older OS’s that don’t have extensive Unicode emoji support, so they don’t see loads of little squares :wink:

3 Likes

Just commenting to add that there is a similar thread in the markdown community considering adding emoji directly to markdown.

I’m of the opinion that it should be kept separate as a postprocessor, and that discourse could lead by example by creating/implementing a post-processor for emoji support. It wouldn’t be that difficult to scan through the DOM and replace patterns in text nodes with their emoji equivalents.

Pretty sure this topic is a duplicate of this one:

https://meta.discourse.org/t/unicode-emoji-rendered-incorrectly-on-google-chrome/20458?u=deanmarktaylor

I disagree; the title of that topic alone rules it out from being a duplicate. Sorry. :frowning:

It is exactly the same issue as here, we should close one of them and if we prefer the title here then just keep this and close the old one as dupe.

1 Like

When I was at Red Dot Ruby conf, Juanito said he may look at implementing this.

Will invite him here in case he is still up to it, Juanito loves Emoji :yum:

3 Likes

What’s the impact going to be for those of us who embed Discourse content elsewhere, such as back into WordPress?

It means when I post on iPhone and enter Emojis direct we would replace them with images, when cooking. It improves the embedding story AND ensures posts look consistent across all browsers. (and no one has ugly square blocks or monochrome emojis) :scream:

2 Likes

That sounds so awesome I’m surprised it’s not already a thing.

This is planned, we want to do it just have not had time, PR totally welcome (but we will eventually get to it)

Is this something you want to take on when you’re back @eviltrout? Maybe you could scope the work.