Open Bug 492147 Opened 12 years ago Updated 4 years ago

copying markup with <span style="display:block"> leads to loss of line breaks (block) when pasting as plain text

Categories

(Core :: DOM: Selection, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

UNCONFIRMED

People

(Reporter: melkor, Unassigned)

References

()

Details

(Whiteboard: DUPEME)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)

Overriding the css:display of tags that are naturally "inline" and making them "block" causes newlines in the displayed text, but if the text is copied those new lines are not expressed. If there has been a new line in the HTML document, they are expressed as a space in the copied text.

Conversely overriding the css:display of tags that are naturally "block" and making them "inline" causes no newlines in the displayed text, but if the text is copied those new lines are expressed. If there has been a new line in the HTML document, they are expressed as a space in the displayed text.

Making a BR tag display:none causes no newlines in the displayed text, but if the text is copied those new lines are expressed.

Reproducible: Always

Steps to Reproduce:
1. Create an html document with the following code in it: "~&lt;span style='display:block;'/&gt;!&lt;span style='display:block;'/&gt;~"
2. When rendered it appears equivalent to: "~&lt;br/&gt;!&lt;br/&gt;~"
3. Select and copy the rendered text.
4. Paste the copied text into any text editor.

Actual Results:  
The result will be "~!~"

Expected Results:  
The result should be three lines of text:
~
!
~

How did you come across this, why not just use a br tag?
BR tags don't collapse when you use multiple copies. On the wiki for which I write content and templates (where the line is often blurred between the two) the wiki engine has some strange formatting tenancies, some commands will only activate if they are on a new line, and in some special instances the wiki will eat newlines. There are times you need to insert an empty HTML tag to keep it from eating new lines. To complicate things we use an extension that lets us write and modify variables, so to build sections of content we append new content onto the end of variables. The end result is the need when appending text to force the engine to a new line without having the act foring the new line to display. In addition to this there are times when you need a new line to be displayed but you don't know if the previous content has supplied a new line...

Which brings us to &lt;span style="display:block"/&gt; It gives us a new line but it collapses into only a new single new-line if multiple copies are provided, which solves all the problems the wiki engine created. The reason for using span (instead of a div) is that the wiki will wrap a span tag in a p tag but it won't do the same for a div tag. Using a div tag meant having to fight off the p tag if you wanted predictable html construction.

The link provided illustrates a number of ways of potentially solving the problem the wiki engine created, all solutions exhibit the text copy problem or the p tag problem.

Interestingly enough Internet Explorer exhibits a similar bug.
Google Chrome does not exhibit this bug in any way I could see, it copies the text as it is displayed.
Sorry about the escaped characters.

Steps to Reproduce:
1. Create an html document with the following code in it: "~<span
style='display:block;'/>!<span style='display:block;'/>~"
2. When rendered it appears equivalent to: "~<br/>!<br/>~"
3. Select and copy the rendered text.
4. Paste the copied text into any text editor.
Version: unspecified → 3.0 Branch
Component: General → Selection
Product: Firefox → Core
QA Contact: general → selection
Version: 3.0 Branch → unspecified
Summary: Changing a tags css:display type causes problems with new lines when coping text. → copying markup with <span style="display:block"> leads to loss of line breaks (block) when pasting
Whiteboard: DUPEME
Summary: copying markup with <span style="display:block"> leads to loss of line breaks (block) when pasting → copying markup with <span style="display:block"> leads to loss of line breaks (block) when pasting as plain text
Yes, I've recently come across this issue within the Joomla documentation at <a href="https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_a_view_to_the_site_part">this page</a>.

In this Joomla tutorial, code which is new or changed from the previous step in the tutorial is highlighted, using a geshi extension to the wiki. Each line of highlighted code is within a span element, with a CSS class called xtra, which results in a display:block being applied.

When you copy and paste the lines into an editor there are no line feeds, and the text appears as one long line.

Chrome, Microsoft Edge and Safari (I'm told) insert the line feeds ok.
You need to log in before you can comment on or make changes to this bug.