[CSS] how can I show spaces as spaces?

  • Thread starter Tomasz Chmielewski
  • Start date
T

Tomasz Chmielewski

When I use <pre>, the spaces will be shown as spaces in a rendered page,
i.e.:

<pre>
5
4
3
2
1
0
</pre>


Will be rendered as:

5
4
3
2
1
0

Without <pre>, it would be rendered as:

5
4
3
2
1
0


Which is not what I want.

How can I tell the browser through CSS that I want to render spaces as
spaces? In other words, render this:

<div class="messageBody">
5
4
3
2
1
0
</div>

Like below:

5
4
3
2
1
0
 
T

Tomasz Chmielewski

Tomasz said:
How can I tell the browser through CSS that I want to render spaces as
spaces? In other words, render this:

Replying to myself - something like this should do:

div.messageBody {
white-space: pre;
}
 
J

Jukka K. Korpela

Tomasz said:
Replying to myself - something like this should do:

div.messageBody {
white-space: pre;
}

It cannot be regarded as the correct answer to the question you asked, which
would more correctly be formulated as "how can I make spaces
non-collapsible", since white-space: pre has essential other effects too.

The rule

div.messageBody {
white-space: pre-wrap;
}

would do what you describe in the question quoted: don't collapse a sequence
of spaces to a single space, but otherwise render the text as usual -
specifically, lines would be wrapped normally. The value pre-wrap still has
limited browser support (even on IE 8, you need to be in "standards mode"
for it to work).

But maybe your _real_ question was implicit in the introduction: "When I use
<pre>". Maybe you really wanted to ask "How can get the same effect in CSS
as I get with <pre> in HTML?"

Then your own answer would be the correct one. However, the question arises
why you would do that. Do you really want the text to be rendered as a
normal paragraph, with collapse of spaces and treating any newline in the
source as equivalent to space, when your style sheet is not applied or your
rule is overridden by other (browser, user) style sheets?

I guess this depends on why you would want to have the text displayed as
preformatted. But I cannot see any particular benefit in making it in a less
reliable way (CSS vs. HTML).
 
T

Tomasz Chmielewski

Jukka said:
I guess this depends on why you would want to have the text displayed as
preformatted. But I cannot see any particular benefit in making it in a
less reliable way (CSS vs. HTML).

I have some software which "transforms" received emails into web pages.

Basically, it reads an email and creates a HTML page with very little
modification to the email body: it will add some <br> tags and will
highlight the links, but nothing more than that.


This means that with "normal" HTML rendering, all spaces will not be
shown (if they are not replaced into &nbsp; - and the software I have
doesn't do it), which will "break" emails if someone "centered" anything
carefully with spaces.



I have little control over the software, that's why I want to "show
spaces" with CSS.
 
J

Jukka K. Korpela

Tomasz said:
I have some software which "transforms" received emails into web
pages.

I guess the main problems (which you might still be unaware of) are not
technical but more fundamental. Publishing an arbitrary e-mail message
without permissions easily takes you on the wrong side of the law, or at
least into trouble.
Basically, it reads an email and creates a HTML page with very little
modification to the email body: it will add some <br> tags and will
highlight the links, but nothing more than that.

Then it's horrendously wrong. Test it with a message containing
<blink><font size=7 color=red>Goofed!</font></blink>

And how does it handle MIME, for example?
This means that with "normal" HTML rendering, all spaces will not be
shown (if they are not replaced into &nbsp; - and the software I have
doesn't do it), which will "break" emails if someone "centered"
anything carefully with spaces.

If you wish to consider such issues, then you should probably consider
division into lines as well. Little does it help to preserve spaces
otherwise.
I have little control over the software, that's why I want to "show
spaces" with CSS.

No, you need more control over the software, or really some different
software, for the part of the activity that makes sense.
 
J

Jan C. Faerber

<html>
<head>
<title>lazy man</title>
</head>
<body>
<script language="JavaScript">
<!--
var b = 'text with 20 letters';
var space = '&nbsp;&nbsp;&nbsp;&nbsp;';
for (var x=19;x>=0;x--)
{
var z = space;
for (var a=0;a<x;a++)
{
z = z + space;
}
 
J

Jan C. Faerber

<!--
var b = 'text with 20 letters';
var turn = b.charAt(19);
for (var l=1;l<=19;l++)
{
var turn = turn + b.charAt(19-l);
}
var space = '&nbsp;&nbsp;&nbsp;&nbsp;';
for (var x=19;x>=0;x--)
{
var z = space;
for (var a=0;a<x;a++)
{
z = z + space;
}
document.writeln(z + turn.charAt(x) + '<br>');
}
// -->
(in the last posting I forgot the closing
//-->)
 
J

Jan C. Faerber

<html>
<head>
<title>lazy man</title>
</head>
<body>
<script language="JavaScript">
<!--
function passon()
{
start(document.gimme.textfield.value);
}
// -->
</script>

<form name="gimme">
<input type=text size=20 name="textfield" value="max. 20 letters
here">
<input type=button value="click" onClick="passon()">
</form>



<script language="JavaScript">
<!--
function start(b) {
var turn = b.charAt(19);
for (var l=1;l<=19;l++)
{
var turn = turn + b.charAt(19-l);
}
var space = '&nbsp;&nbsp;&nbsp;&nbsp;';
for (var x=19;x>=0;x--)
{
var z = space;
for (var a=0;a<x;a++)
{
z = z + space;
}
document.writeln(z + turn.charAt(x) + '<br>');
}
document.writeln('use the back button of your browser to enter a new
text');
}
// -->
</script>
</body>
</html>


I don't know yet why the textfield disappears after clicking the
button.
And how to avoid the loading of the page...
can be continued in a js group.

roger & over
 
D

Doug Miller

I have some software which "transforms" received emails into web pages.

That is SO not a good idea.
Basically, it reads an email and creates a HTML page with very little
modification to the email body: it will add some <br> tags and will
highlight the links, but nothing more than that.

So if the email contains something like
<img src="www.porn.com/NakedPeopleDoingDisgustingThingsWithVegetables.jpg">
or
<a href="www.evil.com/DownloadVirus">See nude pics of Jennifer Anniston</a>
your software will display that on the web page, too?

Hopefully, the need for better software, if not a completely different
approach, is now obvious.
 
M

Michael Fesser

..oO(Doug Miller)
That is SO not a good idea.

So if the email contains something like
<img src="www.porn.com/NakedPeopleDoingDisgustingThingsWithVegetables.jpg">
or
<a href="www.evil.com/DownloadVirus">See nude pics of Jennifer Anniston</a>
your software will display that on the web page, too?

Where did he mention HTML emails?
Hopefully, the need for better software, if not a completely different
approach, is now obvious.

It would work well for plain text emails.

Micha
 
J

Jukka K. Korpela

Michael said:
[...]
Where did he mention HTML emails?

He didn't, but he wrote "nothing more than that".

So if a plain text e-mail message contains <blink>, it will appear as
<blink> on an HTML page, and if an HTML e-mail message contains <blink>, it
will also appear as <blink>.

If you wanted to convert plain text to HTML, it would not suffice to "add
some <br> tags and [...] hightlight the links". You would need to do more
than that.
 
T

Tomasz Chmielewski

Jukka said:
I guess the main problems (which you might still be unaware of) are not
technical but more fundamental. Publishing an arbitrary e-mail message
without permissions easily takes you on the wrong side of the law, or at
least into trouble.

It's a mailing list and everyone posting there knows it.

Then it's horrendously wrong. Test it with a message containing
<blink><font size=7 color=red>Goofed!</font></blink>

And how does it handle MIME, for example?

Yes, I didn't mention that.
It does handle HTML mail and does some more processing in that case.

BTW, the software is Lurker: http://lurker.sourceforge.net/
 
T

Tomasz Chmielewski

Doug said:
That is SO not a good idea.

Most web email archives work this way.

So if the email contains something like
<img src="www.porn.com/NakedPeopleDoingDisgustingThingsWithVegetables.jpg">
or
<a href="www.evil.com/DownloadVirus">See nude pics of Jennifer Anniston</a>
your software will display that on the web page, too?

Hopefully, the need for better software, if not a completely different
approach, is now obvious.

It will display these as links (if the spam filter doesn't stop it); the
software processes HTML of course.

Dealing with spam and malicious mail is not the main topic for alt.html.
 
D

Doug Miller

..oO(Doug Miller)


Where did he mention HTML emails?

Why do imagine that it makes a difference?
It would work well for plain text emails.
What do you imagine to be the difference between "HTML emails" and "plain text
emails"?
 
D

dorayme

Tomasz Chmielewski said:
dorayme wrote: ....
Unfortunately, I don't have much control over HTML code, so I can't do
it this way.

I did not really know what you are doing. Still don't. Are you in some
group that email each other, some sort of email list and you want to
make a web record of it all?

I subscribe to a list that about a year or two ago suddenly went all
google, and you can choose how to read and write to it. You can simply
go to Google and sign in and do the business there.

Or you can get every email direct to your email program.

Or you can get a digest of the emails once a day (menu of posts at the
top - each menu item also being a link to go to G and see it there if
you want - and all the messages at the bottom).

Or you can get just the menu of posts (a sort of cut down of the digest
sans the actual messages) in an email.

(I liked it the way it used to be better, just email - but this has the
advantage of all the threads being there to be searched easily.)

I am just saying there are different ways to manage a bunch of people
emailing things to each other and the idea of making a webpage of email
messages sounds like quite a task for someone to sit and do. There are
probably automated alternatives you might explore (as in the case I
outline above). Please ignore all this if it is not relevant.
 
T

Tomasz Chmielewski

dorayme said:
I did not really know what you are doing. Still don't. Are you in some
group that email each other, some sort of email list and you want to
make a web record of it all?

I subscribe to a list that about a year or two ago suddenly went all
google, and you can choose how to read and write to it. You can simply
go to Google and sign in and do the business there.

Or you can get every email direct to your email program.

Note that not all lists are open public lists; note that subscribers may
wish that their emails show up in the archive with proper formatting.

Anyway, the problem is solved, thanks all for the input.
 
J

Jan C. Faerber

Now I ask myself (respecting that JavaScript might not be object
orientated) if you could not use such a script to fill in always
different text in different <td>s. That would be 'reusability'.

Of course I know now that HTML is not a programming language and some
people turn off JavaScript in their browsers.

So one question is left for me at this point:

How manage big online news portals whith rapidly changing content the
actualisation of their pages?
Do they open the source code?
Or do they have an interface?
I think 'contribute' in CS4 Webstandard is something for blogs.
But I never heard about something for magazines.

A person who writes the stories for an online magazine - does he
automatically have to know about HTML?
Or is it another person who takes the article and places it into the
right places of the huge portal?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top