question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How replace emoji codes in html to Emoji Component?

See original GitHub issue

Hello,

I want to display the Emoji Component like bellow but I don’t know how can I replace the html result with component like:

Can you help me with this please?

Thank you.

I get html like this

Hello, how are you? :thumbsup:

I would like to get something like this:

Hello, how are you? <Emoji emoji=':thumbsup:'  size={64} />

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

20reactions
EtienneLemcommented, May 16, 2017

👋

You will need a regex to detect the colons-syntax emojis, then you will be able to reconstruct your children with a mix of strings and Emoji components (given you already are in a React app)

Here’s a quick snippet of how we parse them in Missive:

let string = 'Hello, how are you? :thumbsup:'
let regex = new RegExp('(^|\\s)(\:[a-zA-Z0-9-_+]+\:(\:skin-tone-[2-6]\:)?)', 'g')

let match
while (match = colonsRegex.exec(string)) {
  let colons = match[2]
  let offset = match.index + match[1].length
  let length = colons.length

  console.log(colons, offset, length)
}

The colons variable can be used as-is w/ the Emoji component: <Emoji emoji={colons}>, it supports skin color too.

The rest (instead of the console.log) can vary depending on many factors, so I’ll let you figure out how that can be implemented in your app 😄

7reactions
Pong420commented, Oct 6, 2020

Just tested on latest chrome and safari.

const colons = `:[a-zA-Z0-9-_+]+:`;
const skin = `:skin-tone-[2-6]:`;
const colonsRegex = new RegExp(`(${colons}${skin}|${colons})`, 'g');

interface Props {
  content: string;
}

 function Component({content}: Props) {
    return (
      <div>
        {content
          .split(colonsRegex)
          .map(
            (emoji, idx) =>
              !!emoji && (
                <Emoji
                  size={24}
                  key={idx}
                  emoji={emoji}
                  fallback={() => emoji as any}
                />
              )
          )}
      </div>
    );
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Emojis in HTML - W3Schools
Emojis look like images, or icons, but they are not. They are letters (characters) from the UTF-8 (Unicode) character set. UTF-8 covers almost...
Read more >
Using Emojis in HTML, CSS, and JavaScript - KIRUPA
Specifying the Emoji Codepoint​​ To specify this emoji in HTML using the codepoint, we have to modify the value a bit. Add the...
Read more >
How to add Emoji's in your website, using HTML, CSS or ...
Emoji's in the Web · Insert in HTML by copy pasting · Insert in HTML with its codepoint (replace U+ with &#x) ·...
Read more >
How to add emoji in HTML document ? - GeeksforGeeks
Emojis can be added in HTML document by specifying their hexadecimal code within the required tags. These codes start with &#x and end...
Read more >
How can I use a diffrent style for emojis? - Stack Overflow
You cannot modify the rendering of emoji directly. Regardless of font-face, the user's browser and OS determine how emoji characters are ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found