Auto-replace emoji like ☺ with Discourse codes


#1

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.


Emoji in topic names 😛💜🍦
Unicode Emoji rendered incorrectly on Google Chrome
Inbound gutter post-links are not relative urls
Rendering of ® in post results in :registered:
Allow user to specify size of image via attributes
Convert Unicode standard emojis to selected emoji set
#2

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.


(Ani) #3

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?


(Sam Saffron) #4

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.


#5

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.


(Jeff Atwood) #6

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


(Sam Saffron) #7

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


(Michael Brown) #8

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:


#9

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.


#10

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:


(Tim Leverett) #11

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.


(Dean Taylor) #12

Pretty sure this topic is a duplicate of this one:


(Jeff Atwood) #13

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


(Sam Saffron) #14

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.


(Sam Saffron) #15

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:


(Stephen) #16

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


(Sam Saffron) #17

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:


(Stephen) #18

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


(Sam Saffron) #19

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


(Jeff Atwood) #20

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