react-quill
react-quill copied to clipboard
Trimming of newlines or linebreaks
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>
You could simply use a regular expression for that
let noNewLines = html.replace(/<p><br><\/p>/g, '')
To remove duplicates but leave one instance.
const noNewLines = html.replace(/(<p><br><\/p>)+/g, "$1")