joypixels / emojione

[Archived] The world's largest independent emoji font. Maintained at https://github.com/joypixels/emoji-toolkit.
https://www.joypixels.com
Other
4.46k stars 536 forks source link

Allow to configure the HTML part of regexes #645

Open oriolbcn opened 5 years ago

oriolbcn commented 5 years ago

Why is this change needed?

Emojione does not replace emojis that are inside an <object> or <span> tag. This can be problematic in some scenarios. In our case this is problematic when processing content generated by an editor (TinyMCE), since the editor generates spans to format text.

I don't understand the reasons for avoiding the content inside these tags, but in our case removing them does not cause any problem and solve these issues.

What's the change

The change makes the part of the regexes that match HTML configurable, so that by default it keeps the same behaviour but, if wanted, a new regex can be provided. In our case, the same regex without the part.

The ugly part is that when the HTML regex is changed, the other regexes need to be recomputed, that's why I added the computeRegexes method, so you would use it like:

emojione.htmlRegexp = "<object[^>]*>.*?</object>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>";
emojione.computeRegexes();

Making this more clean would require moving all the regexes inside methods and that's a bigger change.

The change allows to fix https://github.com/emojione/emojione/issues/537