473,897 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<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 12945
Michael Shell <ne***@michaels hell.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>foob ar</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*****@invali d.invalid> wrote:

: <pre><code>foob ar</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***@michaels hell.org> wrote:
Well, a further issue is whether the browser should take into
consideratio n 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
10970
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 from the "normal" left side. How do I do that without coding "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" ? Is there something like <TAB size=8> ..... </TAB> ?
18
49108
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" "Password=password;Persist Security Info=True;User ID=newuser;Initial Catalog=catalog;Data Source=localhost" /> </appSettings> </configuration>
18
2278
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| 66| +---+---+---+---+---+---+---+---+---+---+---+ | 80| 93|106|119| 11| 13| 26| 39| 52| 65| 67| +---+---+---+---+---+---+---+---+---+---+---+ | 92|105|118| 10| 12| 25| 38| 51| 64| 77| 79| +---+---+---+---+---+---+---+---+---+---+---+
6
2464
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 of this though some of the longer lines will be clipped by the div they're in (or cross its borders if I allow overflow) when viewed with a narrower viewport (or user-increased
9
5563
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 shell pieces like this: <pre><code> #!/bin/sh ftp -i -n ftp.server.com&lt; &lt;EOF user username password epsv4 cd /
14
3649
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 readibility on browsers w/o css-support. For important notes, warnings etc I use the <pre> tag, which shows in a neat bordered box when viewed with css, and depending on its class a clarifying background-image is shown. I would like the...
10
6610
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 if anyone know the spec for XML case, please let me know. Thanks. Xah
1
1903
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 a page does specify a font-family for TT, CODE, PRE, etc., then Mozilla/Firefox displays such text no longer in my own preferred monospaced typeface but in my preferred proportional typeface. Only when I write <code><code class=...with double...
5
6988
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 small that the size of the containing <preis smaller than the text in it. Since it is <pre>, the text is not wrapped, but the border and background color get smaller. Thus the text pops out of its box. Is there something one can do against...
0
9990
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9837
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10476
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9655
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8031
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6073
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4697
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3299
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.