This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Stylesheets > August 2006 > white-space help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I want to paste a lengthly text document into a web page and have it
retain all of whitespace and line breaks.
I first tried the <pre> tag but that didn't work because it doesn't
wrap the text. I then moved to CSS and the white-space property, but I
can't seem to get it to work either. white-space: pre does the same as
<pre> and white-space: pre-wrap doesn't seem to be supported by any
browsers I've tested with. I tried word-wrap: break-word, but that is
only supported my IE and it messed up my white-space: pre anyhow.
*sigh*
Can anyone suggest to me what properties and values I should use to get
the browsers (IE and Firefox, mostly) to preserve whitespace and
newlines, as well as wrapping the text.
Thank you so much!
Brent
| |
| Jukka K. Korpela 2006-08-13, 6:32 pm |
| Brent <bkraymond@XXXXXXXXXX> scripsit:
> I want to paste a lengthly text document into a web page and have it
> retain all of whitespace and line breaks.
What could possibly constitute the need for such an operation? If it's
preformatted plain text and should be kept that way, it can be turned into a
plain text www document.
--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/
| |
| Jim Moe 2006-08-13, 6:32 pm |
| Brent wrote:
> I want to paste a lengthly text document into a web page and have it
> retain all of whitespace and line breaks.
>
> I first tried the <pre> tag but that didn't work because it doesn't
> wrap the text.
>
You want it to preserve the linebreaks and not preserve the linebreaks.
I think this is where your difficulty lies.
--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
| |
| Chris F.A. Johnson 2006-08-13, 10:31 pm |
| On 2006-08-13, Jim Moe wrote:
> Brent wrote:
> You want it to preserve the linebreaks and not preserve the linebreaks.
> I think this is where your difficulty lies.
There's nothing inconsistent in the OPP's request. He wants the
existing linebreaks to remain, and not join with the next line. HE
want long lines to wrap.
What he wants is very hard to read, and not recommended.
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
| |
| Brent 2006-08-13, 10:31 pm |
| Jim Moe wrote:
> Brent wrote:
> You want it to preserve the linebreaks and not preserve the linebreaks.
> I think this is where your difficulty lies.
>
> --
> jmm (hyphen) list (at) sohnen-moe (dot) com
> (Remove .AXSPAMGN for email)
I do want to preserve linebreaks (just like the <pre> tag does), but I
also want the text to wrap at the right edge of the browser.
Basically put, I have a text document that was written with MS Notepad,
that contains indents, tabs, paragraphs, etc... When I use
white-space: pre the paragraphs run as single lines (they don't wrap at
the right edge of the browser). The only way I found to wrap the
paragraphs causes me to loose the white-space property (indents and
tabs disappear, and paragraphs mesh together as one very long
paragraph, sort of like how text in html behaves normally.)
Is there a way preserve whitespace and have the text wrap? Or is that
simply not possible to do?
| |
| Brent 2006-08-13, 10:31 pm |
|
Chris F.A. Johnson wrote:
> On 2006-08-13, Jim Moe wrote:
>
> There's nothing inconsistent in the OPP's request. He wants the
> existing linebreaks to remain, and not join with the next line. HE
> want long lines to wrap.
>
> What he wants is very hard to read, and not recommended.
>
Why would it be hard to read? Will it not justify properly? The way I
look at it, if the existing linebreaks remain and the text wraps, it
should appear on the browser perfectly. Please let me know if I'm
missing something.
| |
| Chris F.A. Johnson 2006-08-13, 10:31 pm |
| On 2006-08-13, Brent wrote:
>
> Chris F.A. Johnson wrote:
>
> Why would it be hard to read? Will it not justify properly? The
> way I look at it,
> if the existing linebreaks remain and the text wraps, it should
> appear on
> the browser perfectly. Please let me know if I'm missing
> something.
What you are asking for will give you long lines, followed by short
lines
that should really be connected to the next line, if the text is
going
to be readable. The short lines break the flow. You would be better
off using
style="overflow: auto;".
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
| |
| Brent 2006-08-13, 10:31 pm |
|
Chris F.A. Johnson wrote:
> On 2006-08-13, Brent wrote:
>
> What you are asking for will give you long lines, followed by short
> lines
> that should really be connected to the next line, if the text is
> going
> to be readable. The short lines break the flow. You would be better
> off using
> style="overflow: auto;".
I tried style="overflow: auto" and still can't get both whitespace
preserved and wrapping at once. If I put <pre style="overflow: auto">
I get single lined paragraphs that stretch for miles of the right of
the browser. If I use <div style="overflow: auto"> I loose whitespace.
I still don't understand why you think I will get long lines, followed
by short lines. The text has no character returns, except for at the
end of each paragraph.
Is there really no way to force the text to wrap while preserving
whitespace? This is really bumming me out. :-(
| |
| Nik Coughlin 2006-08-13, 10:31 pm |
| Brent wrote:
> I want to paste a lengthly text document into a web page and have it
> retain all of whitespace and line breaks.
>
> I first tried the <pre> tag but that didn't work because it doesn't
> wrap the text. I then moved to CSS and the white-space property, but I
> can't seem to get it to work either. white-space: pre does the same
> as <pre> and white-space: pre-wrap doesn't seem to be supported by any
> browsers I've tested with. I tried word-wrap: break-word, but that is
> only supported my IE and it messed up my white-space: pre anyhow.
> *sigh*
>
> Can anyone suggest to me what properties and values I should use to
> get the browsers (IE and Firefox, mostly) to preserve whitespace and
> newlines, as well as wrapping the text.
>
> Thank you so much!
I'd just reformat the original document, I'd say it would be easier,
provided you use the right tools and judicious use of search/replace. I use
Notepad++, great for stuff like this.
You could just add <p> to the beginning of the document and </p> to the end
of the document. Then do a search/replace and replace all of the cr/lf in
the document with </p><p>. You could do the same with tabs and spaces if
you want. Use a regular expression (can't give it to you off the top of my
head sorry) to find all the runs of spaces that are 2 or more long and
replace all but the first space with
Should give you what you want.
| |
| Brent 2006-08-13, 10:31 pm |
|
Nik Coughlin wrote:
>
> I'd just reformat the original document, I'd say it would be easier,
> provided you use the right tools and judicious use of search/replace. I use
> Notepad++, great for stuff like this.
>
> You could just add <p> to the beginning of the document and </p> to the end
> of the document. Then do a search/replace and replace all of the cr/lf in
> the document with </p><p>. You could do the same with tabs and spaces if
> you want. Use a regular expression (can't give it to you off the top of my
> head sorry) to find all the runs of spaces that are 2 or more long and
> replace all but the first space with
>
> Should give you what you want.
Alright, I guess that's the best I can hope for at this point. Seems
like a lot of work for something that should be able to be handled by
stylesheets. Thanks.
| |
| Chris F.A. Johnson 2006-08-13, 10:31 pm |
| On 2006-08-13, Brent wrote:
>
> Chris F.A. Johnson wrote:
>
> I tried style="overflow: auto" and still can't get both whitespace
> preserved and wrapping at once. If I put <pre style="overflow: auto">
> I get single lined paragraphs that stretch for miles of the right of
> the browser. If I use <div style="overflow: auto"> I loose whitespace.
>
> I still don't understand why you think I will get long lines, followed
> by short lines. The text has no character returns, except for at the
> end of each paragraph.
>
> Is there really no way to force the text to wrap while preserving
> whitespace? This is really bumming me out. :-(
What whitespace are you talking about? If you want a paragraph
indent, use style="text-indent: 2em; /* adjust to taste */".
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
| |
| Brent 2006-08-13, 10:31 pm |
|
Chris F.A. Johnson wrote:
> On 2006-08-13, Brent wrote:
>
> What whitespace are you talking about? If you want a paragraph
> indent, use style="text-indent: 2em; /* adjust to taste */".
>
Paragraph indents, character returns at the end of paragraphs, and
multiple spaces in succession. I lose them all when I attempt to wrap
the text.
| |
| Chris F.A. Johnson 2006-08-13, 10:31 pm |
| On 2006-08-14, Brent wrote:
>
> Chris F.A. Johnson wrote:
>
> Paragraph indents, character returns at the end of paragraphs, and
> multiple spaces in succession. I lose them all when I attempt to wrap
> the text.
Then you probably need to preformat the file first (didn't someone
already say that?).
You could use something like:
sed 's/ / /g' FILE > NEWFILE
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
| |
| Brent 2006-08-13, 10:31 pm |
|
Chris F.A. Johnson wrote:
> On 2006-08-14, Brent wrote:
>
> Then you probably need to preformat the file first (didn't someone
> already say that?).
>
> You could use something like:
>
> sed 's/ / /g' FILE > NEWFILE
>
Yes, I guess preformatting the file on my own is my only hope at this
point. I wanted to avoid it, but there no way around it. Thank you
for your time today.
| |
| Jim Moe 2006-08-13, 10:31 pm |
| Brent wrote:
>
> Is there a way preserve whitespace and have the text wrap? Or is that
> simply not possible to do?
>
There is no HTML or CSS to do what you want without some extra work.
You must preprocess it. Replace all of the linebreaks with <br>, or
append <br> to every line. You do not want a <pre> any more, either.
--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
| |
| Jukka K. Korpela 2006-08-14, 6:33 am |
| Brent <bkraymond@XXXXXXXXXX> scripsit:
> Seems
> like a lot of work for something that should be able to be handled by
> stylesheets.
Stylesheets exist for the purpose of styling marked-up text (HTML or XML),
not plain text. If you have plain text that contains significant spaces
and/or line breaks, you should either present it as such or (preferable)
convert it to marked-up text that can then be styled.
Conversion from plain text to marked-up text is generally nontrivial and
requires human judgement when performed correctly. Adequate markup reflects
the structure and meaning of text.
--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/
| |
| Alexander Clauss 2006-08-14, 6:47 pm |
| Jim Moe <jmm-list.AXSPAMGN@sohnen-moe.com> wrote:
> There is no HTML or CSS to do what you want without some extra work.
CSS 2.1 would offer what he needs (whitespace: pre-wrap), but
unfortunately this won't work in most browsers. The only browser I know
of which supports this feature is iCab 3.
--
Alexander
| |
| Spartanicus 2006-08-14, 6:47 pm |
| aclauss@hrzpub.tu-darmstadt.de (Alexander Clauss) wrote:
>CSS 2.1 would offer what he needs (whitespace: pre-wrap), but
>unfortunately this won't work in most browsers. The only browser I know
>of which supports this feature is iCab 3.
Supported by Opera since v7.5, earlier v7 versions had a vendor specific
implementation of it (white-space:-o-pre-wrap).
--
Spartanicus
| |
| Andy Dingley 2006-08-14, 6:47 pm |
|
Brent wrote:
> I want to paste a lengthly text document into a web page and have it
> retain [some of the] whitespace and line breaks.
Pre-process it first to convert "para breaks" (probably pairs of
linebreaks) into paragraph markers. You can use the HTML <p> tag for
this. Perl, Python or even sed would be good choices for the
conversion.
Then pre-process it again to convert duplicated <p> into single <p>
(optional, but to be encouraged)
Now paste it into a HTML document inside a <div id="content" > and
style the <div> with CSS however you'd like it. You might want to
constrain the maximum width of this in wide browser windows, because as
mentioned already, extra-long text lines are hard to read.
Avoid all use of CSS white-space: pre; because that's for making a very
rigid layout and it doesn't seem like that's what you need here.
| |
|
| Brent wrote:
> I want to paste a lengthly text document into a web page and have it
> retain all of whitespace and line breaks.
>
> I first tried the <pre> tag but that didn't work because it doesn't
> wrap the text.
<xmp> tag </xmp> is better than <pre> tag </pre>
I then moved to CSS and the white-space property, but I
> can't seem to get it to work either.
CSS white-space won't get what you want.
| |
| Andy Dingley 2006-08-15, 10:35 pm |
|
RC wrote:
> <xmp> tag </xmp> is better than <pre> tag </pre>
Why?
It's not part of HTML (since 3.2), so it's not valid, and even where it
was recognised, it didn't do anything that you can't do with <pre>
http://www.w3.org/TR/html4/appendix....html#h-A.3.1.3
"The following elements are obsolete: LISTING, PLAINTEXT, and XMP. For
all of them, authors should use the PRE element instead."
| |
|
| Andy Dingley wrote:
> RC wrote:
>
>
> Why?
Inside <xmp> tag you can type
5 > 4
1 < 2
3 & 7 both are > 1
<b>Bold face</b>
</xmp>
This is convenient for mathematic and HTML examples.
But inside <pre> tag you must/need to type
5 > 4 or 5 > 4
1 < 2 or 1 < 2
3 & 7 both are $gt; 1
<b>Bold face</b>
</pre>
Do you think everybody remember those hexadecimal or symbols?
>
> It's not part of HTML (since 3.2),
Too bad, it is deprecated of HTML 2.0
| |
| Dr John Stockton 2006-08-15, 10:35 pm |
| JRS: In article <1155519612.381837.181370@74g2000cwt.googlegroups.com>,
dated Sun, 13 Aug 2006 18:40:12 remote, seen in news:comp.infosystems.ww
w.authoring.stylesheets, Brent <bkraymond@XXXXXXXXXX> posted :
[color=darkred]
>Paragraph indents, character returns at the end of paragraphs, and
>multiple spaces in succession. I lose them all when I attempt to wrap
>the text.
You can paste it into a textarea, then invoke javascript to wrap at
whitespace before a given character count and put it in a PRE.
Parts of the javascript behind <URL:http://www.merlyn.demon.co.uk/js-
quick.htm> Pack button might be useful to you; you'd have at least to
remove what changes multiple whitespace to single - or replace it by
multiple .
Read the c.l.j FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|