Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

emojify-parser proof of concept #93

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

trevorah
Copy link

DO NOT MERGE THIS

This is a proof of concept that uses emojify-parser, so that the emojify function only has to worry about dom manipulation.

To use with nodejs, you would have to use jsdom like this:

jsdom.env('<span id="cat">hello :cat:</span>', function(err, window) {
  var el = window.document.getElementById('cat');
  emojify(el, { document: window.document });

  console.log(el.outerHTML)
  // '<span id="cat">hello <img class="emoji" src="/cat.png" title=":cat:" alt=":cat:" align="absmiddle"></span>'
});

Let me know what you think and whether or not I should carry on and make this fit for merging.

@adam-lynch
Copy link
Contributor

So is emoji-parser the same code that was in emojify.js previously? And what about stuff like emojify.replace?

@trevorah
Copy link
Author

Not quite, the previous code uses a regular expression to replace the :emoji: with the matching image tag. By separating out the emoji parser from the part that replaces/inserts the image tag, we can test the individual parts and have something a lot less buggy. Its kind of like separating out the parts of a compiler.

Youre right about emojify.replace, I should probably switch to constructing the html with strings rather than depending on document.createElement. We could also reuse emojify.replace internally as long as we only use it on nodes where the type is TEXT_NODE, that way we can guarantee that there will be no html in the string that we are calling emojify.replace with.

@adam-lynch
Copy link
Contributor

I just read over the jsdom README and this again.

Youre right about emojify.replace, I should probably switch to constructing the html with strings rather than depending on document.createElement

What's wrong with that if options.document is being passed?

@trevorah
Copy link
Author

I guess its just overkill to require a dom to concatenate strings if youre using emojify.replace. Especially when running in node.

@adam-lynch
Copy link
Contributor

But we'd have it anyway right? We'd require it for traversing so why not use it? So it could be safer? Maybe I'm missing something.

@trevorah
Copy link
Author

would you traverse for emojify.replace?

@adam-lynch
Copy link
Contributor

Ha sorry 😝🔨. I was thrown off by thinking of my own use case; I'm only using .replace because the other features aren't supported in Node so I wouldn't be using .replace once this is finished.

@trevorah
Copy link
Author

haha, no worries.

@hassankhan
Copy link
Contributor

Does this have any appreciable effect performance-wise? I would think not, but it would be nice to know? I'll admit, I was a bit against it to begin with but I'm slowly warming to the idea.

@trevorah
Copy link
Author

trevorah commented Nov 4, 2014

I cant see it having a massive effect. Tree traversal would cause the biggest change in performance, but thats already happened in #99.

@hassankhan
Copy link
Contributor

Alrighty then, I think it's the right thing to do, looking forward to seeing some more commits 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants