<pre> versus <code> white-space:pre; when pasting
Michael Shell <[email protected]> Wed, 20 Jul 2005 00:06:42 -0400
| Newsgroups | gmane.comp.mozilla.devel.unix |
|---|---|
| Organization | http://newsguy.com |
| Message-ID | <20050720000642.68297c40@bashir> |
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
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>
-----