react-quill icon indicating copy to clipboard operation
react-quill copied to clipboard

Trimming of newlines or linebreaks

Open DvzH opened this issue 5 years ago • 2 comments

Hi, I am new to react quill. I want to trim new lines or line breaks at the beginning and end of the editor's contents. Trimming of spaces and tabs is working fine. but I want to trim newlines/linebreaks as well.which are caused by clicking on "Enter" Button.

I am saving the HTML content from Editor in my component state. So I need to remove one or multiple of these
<p><br></p>

DvzH avatar Jul 03 '20 09:07 DvzH

You could simply use a regular expression for that

let noNewLines = html.replace(/<p><br><\/p>/g, '')

alejo4373 avatar Mar 09 '21 06:03 alejo4373

To remove duplicates but leave one instance.

const noNewLines = html.replace(/(<p><br><\/p>)+/g, "$1")

lainfox avatar Mar 27 '22 06:03 lainfox