By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

<pre> versus <code> white-space:pre; when pasting

P: n/a


Greetings,

Consider the XHTML document attached at the end of this post.
When viewed under Firefox 1.0.5 on Linux, highlighting
and pasting (into a text editor) the <pre> tag listing will
preserve formatting (white space and line feeds). However, this
is not true when doing the same with the <code> tag listing
(it will all be pasted on one line with multiple successive spaces
treated as a single space) despite the fact that "white-space:pre;"
was invoked via CSS.

Is this considered correct behavior?
Do other browsers generally behave in this way?

If so, it seems to me that it may prevent the use of the <code>
tag in lieu of the <pre> tag for a lot of source code - especially
in languages such as Python where spacing is an important part of
syntax (assuming we want to avoid the extra work required of the
&nbsp; and <br/> route and assuming we want users to be able to paste
short code segments from their browsers).

This should make for an interesting discussion because it deeply
involves the concept of what is content and what is presentation.
It seems that copy and paste transfers only "content" and does not
take into consideration presentation. Furthermore, within <pre>,
white space and line feeds are considered to be content. However,
this is not true within <code> regardless of what is declared with
CSS.
Thanks in advance for any comments,

Mike Shell

-----
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Copy and Paste of Code Test</title>
<meta http-equiv="Content-type"
content="text/html; charset=utf-8"></meta>
</head>

<body>

<h1>Pre tag listing</h1>
<pre>
for (some_condition)
{
do some_thing
}
</pre>

<hr></hr>
<h1>Code tag listing</h1>
<p>
<code style="white-space:pre;">
for (some_condition)
{
do some_thing
}
</code>
</p>

</body>
</html>
-----

Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Michael Shell <ne***@michaelshell.org> wrote:
Consider the XHTML document attached at the end of this post.
When viewed under Firefox 1.0.5 on Linux, highlighting
and pasting (into a text editor) the <pre> tag listing will
preserve formatting (white space and line feeds). However, this
is not true when doing the same with the <code> tag listing
(it will all be pasted on one line with multiple successive spaces
treated as a single space) despite the fact that "white-space:pre;"
was invoked via CSS.

Is this considered correct behavior?
Do other browsers generally behave in this way?
Yes x 2.
If so, it seems to me that it may prevent the use of the <code>
tag in lieu of the <pre> tag for a lot of source code
<pre><code>foobar</code></pre>
This should make for an interesting discussion


Hardly.

--
Spartanicus
Jul 21 '05 #2

P: n/a
On 20 Jul 2005 02:13:31 -0700
"ia******@gmail.com" <ia******@gmail.com> wrote:

Also, I just tried your source out, and it looks like it works fine to
me, in firefox and in IE:

This is not about how it *appears* in Firefox. It is about what
happens when the code is highlighted and *pasted* into another
application (say, when somebody wants to grab a code segment from
a web page for compilation/execution). Each of the two cases *look*
the same in Firefox. However, they do not *paste* the same - try
it with say, Word Pad.

At any rate, thank you for showing me that they still look the
same under Windows.
On Wed, 20 Jul 2005 06:50:18 GMT
Spartanicus <in*****@invalid.invalid> wrote:

: <pre><code>foobar</code></pre>

I missed that one. Interesting - one tag to indicate that it is code
and another one to indicate that whitespace and line feeds are to
be treated as content.

: Hardly.
Well, a further issue is whether the browser should take into
consideration presentation when pasting. After all, the pasting
occurs after the document has been visually rendered - and the
selection operation is working from this rendered data, not the
HTML (and CSS) that gave rise to it.


Thanks,

Mike Shell
Jul 21 '05 #3

P: n/a
Michael Shell <ne***@michaelshell.org> wrote:
Well, a further issue is whether the browser should take into
consideration presentation when pasting.


Yes when it's structural (present in the markup), no when it's
presentational (applied with CSS).

--
Spartanicus
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.