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

textToHighlight Prop doesn't maintain the spacing or newlines #80

Open julianaubrey opened 5 years ago

julianaubrey commented 5 years ago

The text I'm passing to the textToHighlight prop contains newlines because it is formatted in paragraphs. Unfortunately, the spacing or newlines are not maintained so my text doesn't look formatted anymore.

rrfeng commented 5 years ago

+1 for spaces and newlines.

MarkosKon commented 5 years ago

You can use the white-space css property with the pre-wrap value.

For example, white-space: pre-wrap;.

You can pass it as a style prop in the Highlighter component.

Codesandbox example