react-highlight-words icon indicating copy to clipboard operation
react-highlight-words copied to clipboard

textToHighlight Prop doesn't maintain the spacing or newlines

Open julianaubrey opened this issue 5 years ago • 2 comments

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.

julianaubrey avatar Apr 25 '19 13:04 julianaubrey

+1 for spaces and newlines.

rrfeng avatar Apr 26 '19 10:04 rrfeng

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

MarkosKon avatar May 29 '19 16:05 MarkosKon