473,379 Members | 1,190 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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



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
3 12865
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Wladimir Borsov | last post by:
Assume I want to publish a longer article on a web page. One of the paragraphs I want to display with an indent. Read: All text lines of this paragraph should be displayed with (let's say 8) blanks...
18
by: deko | last post by:
I need to include code snippets in my html document, something like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="ConnectionString"...
18
by: John | last post by:
I'm getting ready to revamp my Magic Squares pages, which currently show the magic squares in this form: +---+---+---+---+---+---+---+---+---+---+---+ | 68| 81| 94|107|120| 1 | 14| 27| 40| 53|...
6
by: TomB | last post by:
Hello all, On the page located at http://deimos.curious.be/~dusk/lyrics.php#gotn I have put the lyrics text inside <pre> elements so that the UA renders the linebreaks in the code. Because...
9
by: Eric Lindsay | last post by:
I can't figure how to best display little snippets of shell script using <pre>. I just got around to organising to bulk validate some of my web pages, and one of the problems occurs with Bash...
14
by: Schraalhans Keukenmeester | last post by:
I am building a default sheet for my linux-related pages. Since many linux users still rely on/prefer viewing textmode and unstyled content I try to stick to the correct html tags to pertain good...
10
by: Xah Lee | last post by:
there's a HTML odditity. That is, line break will be ignored inside <preif the adjacent lines are tags. see the source code and description here: http://xahlee.org/js/linebreak_after_tag.html...
1
by: Andreas Prilop | last post by:
I've come along a strange behaviour (bug?) in the Mozilla/Firefox browsers. It does not happen in Internet Explorer. When I have *disabled* the option "Allow pages to choose their own fonts" and...
5
by: Hendrik Maryns | last post by:
Hi, A friend complained that the border around the lower code part on http://tcl.sfs.uni-tuebingen.de/~hendrik/keyboard.shtml is too small for the content. This is because his window size is so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.