newline dropped by HTML

X

Xiaochuan Fang

jupiter дµÀ:
I just tried sending the String like this:
tempText = (tempText + "<font color=white>\nXXX\n</font>");

It actually inserts the XXX and it changes the color, but do you
THINK it will obey \n? Not on your life.

What is the 'HTML processor'?Browser?
Are you talking about '<BR>'?
 
P

pkoerner

That's standard HTML behaviour. Any number of whitespace-Chars (\n,
\r, tab, space, ...) not marked as PCDATA is compacted to only one
whitespace. To get around this use &nbsp; for spaces and <br /> for
new-lines.

Peter
 
J

jupiter

I am stumped. I send Java String to an HTML processor method that
renders the text into pretty browser text. Fine, it works, it is
so colorful and so dashing that it takes my breath away.

But wait, what about multi-line text sent to the HTML method as a
single String? The HTML appears to be dropping the newlines that
I append to the Java String. I append "\n" after each line is
read, concatenate the lines, and send them off to the processor. I
end up with a one-liner as if I never had appended the newlines.

Of course this works when output goes to display. Of course!

I think I have to come up with a scheme to add the HTML tags before
sending it to the HTML processor method. Or something like that.
I don't even know if that makes sense since tags added on a line by
line basis may screw things up worse.

Here's a sample line from the HTML processor method where I insert
a String called answerText. You can see that sending "extra" HTML
is a bit of a weird concept, but I have no clue what else to try.

sb.append("<a href=\"#\" onMouseover=\"div" + divNum +
".innerHTML=\'" + answerText + "\'\" onMouseout=\"div" + divNum +
".innerHTML=\'\'\">\n");
 
J

jupiter

jupiter said:
I am stumped. I send Java String to an HTML processor method that
renders the text into pretty browser text. Fine, it works, it is
so colorful and so dashing that it takes my breath away.

But wait, what about multi-line text sent to the HTML method as a
single String? The HTML appears to be dropping the newlines
that I append to the Java String. I append "\n" after each line
is read, concatenate the lines, and send them off to the
processor. I end up with a one-liner as if I never had appended
the newlines.

Of course this works when output goes to display. Of course!

I think I have to come up with a scheme to add the HTML tags
before sending it to the HTML processor method. Or something
like that. I don't even know if that makes sense since tags added
on a line by line basis may screw things up worse.

Here's a sample line from the HTML processor method where I
insert a String called answerText. You can see that sending
"extra" HTML is a bit of a weird concept, but I have no clue what
else to try.

sb.append("<a href=\"#\" onMouseover=\"div" + divNum +
".innerHTML=\'" + answerText + "\'\" onMouseout=\"div" + divNum +
".innerHTML=\'\'\">\n");

I just tried sending the String like this:
tempText = (tempText + "<font color=white>\nXXX\n</font>");

It actually inserts the XXX and it changes the color, but do you
THINK it will obey \n? Not on your life.
 
J

jupiter

That's standard HTML behaviour. Any number of whitespace-Chars
(\n,
\r, tab, space, ...) not marked as PCDATA is compacted to only
one
whitespace. To get around this use &nbsp; for spaces and <br />
for
new-lines.

Peter

Big Aha!

Red faced, I limp back to insert the stupid tag that I could have
inserted instead of the gargantuanly stupid (is that a word?)
<font> tag.
 
C

Chris

jupiter said:
Big Aha!

Red faced, I limp back to insert the stupid tag that I could have
inserted instead of the gargantuanly stupid (is that a word?)
<font> tag.

Another useful tag is <pre>, for "preformatted". Wrap it around your
text with line breaks and the browser will break the lines as expected.
 
J

jupiter

Chris said:
Another useful tag is <pre>, for "preformatted". Wrap it around
your text with line breaks and the browser will break the lines
as expected.

That is sweet, Chris. I had not heard of that tag.
 
M

Martin Gregorie

jupiter said:
That is sweet, Chris. I had not heard of that tag.
"HTML for the World Wide Web" by Elizabeth Castro. Get it. Read it. Then
you'll have a working grasp of HTML.
 
O

Oliver Wong

Martin Gregorie said:
"HTML for the World Wide Web" by Elizabeth Castro. Get it. Read it. Then
you'll have a working grasp of HTML.

Alternatively, check out http://www.w3schools.com/.

Castro's book may be excellent -- I wouldn't know, as I've never read
it. On the other hand, w3school is free, and it was "good enough" for
learning HTML for me.

- Oliver
 
M

Martin Gregorie

Oliver said:
Alternatively, check out http://www.w3schools.com/.

Castro's book may be excellent -- I wouldn't know, as I've never read
it. On the other hand, w3school is free, and it was "good enough" for
learning HTML for me.
The reasons I like Castro's book are that it:

- gives a clear, well-written tutorial introduction to all the
main features of HTML.
- documents common proprietary extensions, portability issues
and work-rounds
- has examples that only need an ASCII editor and a web browser to
work through them.
- contains excellent reference sections that link back to
relevant parts of the tutorials. Its the only reference I need.
- is cheaper than most computer books.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top