Copy & paste of <h1>1</h1>\n<p>2</p> behaves differently to <h1>1</h1><p>2</p>

Xon

Well-known member
Affected version
2.3.7
If you copy & paste from a HTML document with this sort of structure:
HTML:
<html><head></head>
<body>
<h1>1</h1>
<p>2</p>
</body></html>
It results in:
with newline said:
But if you copy & paste the following structure (no newline between <h1 & ><p> tags:
HTML:
<html><head></head>
<body>
<h1>header</h1><p>Lorem ipsum</p>
</body></html>
It results in:
with new line said:

The linebreaks typically show up when copying HTML from firefox, while chrome will strip newlines between tags.
 
This also affects unordered and ordered lists when there are spaces inside the tags.

Adding this code into paste.beforeCleanup event is probably the most targeted version
JavaScript:
fragWrapper.querySelectorAll('p,h1,h2,h3,h4,h5,h6,li').forEach(function (element) {
    const node = element.nextSibling;
    if (node && node.nodeType === Node.TEXT_NODE && node.nodeValue.match(/^\s+/$)) {
        node.remove();
    }
});
fragWrapper.querySelectorAll('ul,ol').forEach(function (element) {
    const node = element.firstChild;
    if (node && node.nodeType === Node.TEXT_NODE && node.nodeValue.match(/^\s+/$)) {
        node.remove();
    }
});

Might need todo table tags?

I'm positive I've seen a bug report where @Chris D failed to reproduce pasting a list of thing adding new-lines & additional bullet points. The secret ingredient is firefox not outputting the expected HTML and something in XF's editor stack is then converting the whitespace into newlines
 
Last edited:
Back
Top Bottom