Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emoji suggestion #1108

Closed
lijiarui opened this issue Feb 24, 2018 · 1 comment
Closed

emoji suggestion #1108

lijiarui opened this issue Feb 24, 2018 · 1 comment

Comments

@lijiarui
Copy link
Member

lijiarui commented Feb 24, 2018

I found src/misc is trying to strip emoji, HTML and any misc things in a text message.

I have 2 suggestions:

  1. I feel a bit confused about all emoji rules and this file rules, so I suggest to add some comment here, then if any other one gets some new emoji rules, we can add it here.

  2. I suggest to add two functions:

  • message.stripEmoji(): void: to strip emoji from the text message, then we can get a pure one.
  • message.emoji(): []: return a list containing all emojis meaning in the text.

I found the following code in src/misc seems trying to get emoji meaning but it cannot always succeed, also if there is some emotion, like gif in wechat, it doesn't work too.

  public static digestEmoji(html?: string): string {
    if (!html) {
      return ''
    }
    return html
          .replace(/<img class="(\w*?emoji) (\w*?emoji[^"]+?)" text="(.*?)_web" src=[^>]+>/g,
                   '$3',
                 ) // <img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />
          .replace(/<span class="(\w*?emoji) (\w*?emoji[^"]+?)"><\/span>/g,
                   '[$2]',
                 ) // '<span class="emoji emoji1f334"></span>'
  }

Well, thinks more, even it should be a seperate npm module....

@suntong
Copy link
Contributor

suntong commented Feb 25, 2018

Oh, thanks for spotting that, I was just about to write my own code to get rid of them.

When you say "some emotion ... doesn't work", can you give several sample of those not working emotions please?

Also, talking about cleaning up emoji, wouldn't clean = Misc.digestEmoji(messy) (or Misc.stripEmoji) be good enough? why proposing a different API? IMHO, I think we should have even fewer APIs, e.g., those people who prefer Misc.stripEmoji would most probably use stripHtml too, as it is hard to image someone want to get rid of only emoji while keeping other messy html stuff.

Personally, I'd use Misc.digestEmoji to keep the emojis, but I wouldn't use stripHtml blindly, as there are several useful HTML tags, like <br>, and a few others.

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

No branches or pull requests

2 participants