MacDownApp / macdown

Open source Markdown editor for macOS.
https://macdown.uranusjr.com/
9.43k stars 1.09k forks source link

GFM Emoji? #597

Open Sequoia opened 8 years ago

Sequoia commented 8 years ago

Is it possible to enable/achieve this?

getaaron commented 8 years ago

The names and images are publicly available on https://github.com/github/gemoji, but I'm not sure there's really demand for such a feature.

uranusjr commented 8 years ago

I think this might be more useful implemented as a JavaScript library, and then we can apply it at runtime, like what we do with math. I wonder if someone has already done this.

Sequoia commented 8 years ago

@uranusjr if it can be implemented in JS I can probably do it! Is there an example of attaching a JS plugin to macdown I could look at?

uranusjr commented 8 years ago

It’s not actually attaching JS into the MacDown parser. MacDown generates an HTML document for preview, so it should be enough to write a script that goes through the document, and replaces :emoji: occurrences with appropriate emojis. It will need to skip math and code constructs, but this shouldn’t be hard with some selectors. The one thing I’m concerned about is some edge cases that are hard to get right (spaces/punctuations around the pattern, something like :foo:bar: should not work, etc.), but I’m not very good at regex, so this might not actually be the case. And we can always play it safe in extremely rare situations anyway; nobody would expect us to be 100% compatible with GitHub. (At least I hope not.)

So the main work here would be to extract the emoji info from GitHub’s repository, and write a JavaScript lib that does the find/replace thing. After that we can just conditionally include it in the generated HTML document, which is relatively easy.

Please do give a shot if you’re interested! It would be even better if it can come as a standalone JavaScript project; I’d imagine it being very useful for online forum and chat projects.

gillesdemey commented 8 years ago

It looks like someone has already gone through the hassle and created a GFM emoji library written in JS 🙌

https://github.com/zzarcon/gh-emoji

uranusjr commented 8 years ago

Wow that is pretty cool. It seems to only handle pure text replace, so we’ll need to jump through some hoops. But it would still be very useful.

uranusjr commented 8 years ago

Note: http://james.padolsey.com/javascript/replacing-text-in-the-dom-solved/

What we want is a little less complicated (don’t need to normalise things).

connorjclark commented 7 years ago

I have some need for emoji support here. Would such a feature be welcome? If so, I'll work on it.

uranusjr commented 7 years ago

@Hoten Go ahead!