Skip to content

Commit

Permalink
#3762: Strip some newlines
Browse files Browse the repository at this point in the history
Strip whitespace surrounding newlines between > and <, this avoids creating empty paragraphs.
  • Loading branch information
gjvoosten authored and anilsonmez-simsoft committed Oct 13, 2021
1 parent c19eca3 commit d3d8411
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion client/src/components/RichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ const withHtml = editor => {
editor.insertData = data => {
const html = data?.getData("text/html")
if (html) {
const parsed = new DOMParser().parseFromString(html, "text/html")
// Strip whitespace surrounding newlines between > and <
// This avoids creating empty paragraphs!
const htmlNoNewlines = html.replace(/>\s*(\r\n|\n|\r)\s*</gm, "><")
const parsed = new DOMParser().parseFromString(
htmlNoNewlines,
"text/html"
)
const nodes = deserialize(parsed.body)
Transforms.insertNodes(editor, nodes)
} else {
Expand Down

0 comments on commit d3d8411

Please sign in to comment.