helior / react-highlighter

:high_brightness: Highlight text using React
MIT License
157 stars 42 forks source link

Add support for ignoring diacritics; Use <mark> tags for highlighting #43

Closed Dentosal closed 6 years ago

Dentosal commented 7 years ago

Sorry to introduce two changes in the same PR. I also fixed some deprecation warnings with React by moving to React.createElement style. If this is a real problem, feel free to either modify it yourself or ask me to do it in comments.

This PR adds two props: ignoreDiacritics and diacriticsBlacklist. The code uses unicode normalization to separate and combine diacritical marks from characters.

ignoreDiacritics

ignoreDiacritics allows ignoring diacritical marks when matching. For instance cafe will match café and á will match a. Currently both search and subject are simplified, so it is not possible to make á not match a, except when using diacriticsBlacklist.

diacriticsBlacklist

diacriticsBlacklist contains a list of characters excluded from diacritics removal. For example:

<Highlight
  search='Café Ääkkönen'
  ignoreDiacritics=true
  diacriticsBlacklist='ÄäÖö'
>

Will match Cafe Ääkkönen and café ääkkönen but not cafe aakkonen.

coveralls commented 7 years ago

Coverage Status

Changes Unknown when pulling b1e281fcd9a7aac976b4c8f48c5da61045141df3 on Dentosal:master into on helior:master.

coveralls commented 7 years ago

Coverage Status

Changes Unknown when pulling ba937abb2b5922d1cc88dee82be4121a1217d747 on Dentosal:master into on helior:master.

helior commented 7 years ago

This is a rad feature @Dentosal, thanks for your contribution! I'll give this a review sometime during the long-weekend.

Dentosal commented 7 years ago

@helior Any problems with this? Feel free to ask if there are any issues.

helior commented 7 years ago

@Dentosal no issue with these changes, other than the current merge conflicts; also, I haven't tested this locally. If you want to make the updates I'll merge when they're ready, otherwise I'll have to put some time aside to button this up and get it merged. A lot of people will appreciate this contribution, thanks again!

pasieronen commented 6 years ago

@helior I've rebased @Dentosal's changes on top of the current master (with some commit squashing/splitting), and tested the result with our app. I left normalize as is - if you need IE11 support, you can use a polyfill for that.

pasieronen commented 6 years ago

@helior Is there something you'd like to see changed before merging this?