bvaughn / react-highlight-words

React component to highlight words within a larger body of text
https://bvaughn.github.io/react-highlight-words/
MIT License
2.16k stars 170 forks source link

Does not parse html text #50

Closed abdelwahed-mohamed closed 6 years ago

abdelwahed-mohamed commented 6 years ago

Hello ,

I have a problem using this library with a html text string for example when my textToHightlight is a html string it does not get parsed i think the component should use the https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

thank you in advance if anyone can point me on how to figure it out.

bvaughn commented 6 years ago

This component doesn't support markup. It's built to highlight plain text.

Sorry!

jstacoder commented 6 years ago

I’ve found just wrapping any text in the html with <Highlighter/> works, although you have to keep passing around the searchWords, I think I’ll put in a PR to make a context manager for that prop for those cases.

AlexanderKozhevin commented 5 years ago

@jstacoder Looks like we can't.

 <Highlighter
          highlightClassName="YourHighlightClass"
          searchWords={["the"]}
          autoEscape={true}

        >
          <div dangerouslySetInnerHTML={{__html: note_Body}}/> 
          </Highlighter>
 Failed prop type: The prop `textToHighlight` is marked as required in `Highlighter`, but its value is `undefined`.�
jstacoder commented 5 years ago

@AlexanderKozhevin the reason you are getting that error is because you did not pass it the textToHighlight prop, which it still needs to know what its parsing through, (the error is very explicit). although im not sure it would work using dangerouslySetInnerHTML anyway, you shouldnt use that, just make your html with jsx