-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add HTML parser/replacer #2
Comments
Had twemoji concepts on my mind recently because of how poorly I noticed Slack handles their implementation. Specifically, compared to twitters on-site implementation (meaning the results on twitter.com) it's really bad on slack. For instance on twitter you can freely copy tweet text and ensure the emojis are preserved. Granted where you paste them to provides varying results based on that program/app. However any app that can take "plain text" and supports unicode/emoji will gladly take the paste and keep the emoji in place. (again with small edge-cases about device compatibility and such.) All of that in mind, I was thinking it'd be cool to make sure this package is able to "do the right thing". The fix for this is kinda simple TBH. When rendering the twemoji image tag, set an I think that the feature I'm talking about here and the idea of parsing a block of content have some important overlap. At the very least in the sense that for blog posts use case I'd want the generated HTML to include the proper |
Could be that I'm dumb but so far I see and know my code it does exactly what you want!? Lines 42 to 65 in 960bc12
https://github.com/Astrotomic/php-twemoji/blob/960bc12c1e156a21a869efdb9045ed42f54a2c6c/tests/__snapshots__/ReplacerTest__it_can_replace_emojis_in_plain_text_to_html__1.txt So the original Emoji 🚀 is the |
Regarding your offer: for sure you can start with the open part of that issue, parsing HTML. |
The original JavaScript Twemoji client allows replacing all emojis in a given text with the corresponding Twemoji image tag in one go.
We should provide a similar method like
Twemoji::parse($html)
which will search for emojis and replace them.As this requires a DOM/HTML parser to don't replace emojis in image alternate attributes for example this should be an opt-in feature. SO the DOM library shouldn't be part of the default dependencies but the
suggestions
.The method should also be flagged as experimental so everyone knows that it's possible that this method makes trouble.
To test this we should use snapshot testing on some blog posts for example. (could be faked)
They should cover emojis in plain text
.txt
, in the displayed content of HTML (outside of tags, in tag(s), with body or without) and as part of HTML attributes.content parser and emoji replacer for:
.txt
Add a batch replacer for plain text #3.html
.md
The text was updated successfully, but these errors were encountered: