[CSS] how can I show spaces as spaces?

Discussion in 'HTML' started by Tomasz Chmielewski, Sep 5, 2009.

  1. 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



    --
    Tomasz Chmielewski
    http://wpkg.org
     
    Tomasz Chmielewski, Sep 5, 2009
    #1
    1. Advertising

  2. Tomasz Chmielewski wrote:

    > 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;
    }



    --
    Tomasz Chmielewski
    http://wpkg.org
     
    Tomasz Chmielewski, Sep 5, 2009
    #2
    1. Advertising

  3. Tomasz Chmielewski

    dorayme Guest

    In article <h7unh7$6o6$>,
    Tomasz Chmielewski <> wrote:

    > 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>


    Diagonal writing!

    <http://dorayme.netweaver.com.au/diagonalWriting.html>

    --
    dorayme
     
    dorayme, Sep 6, 2009
    #3
  4. Tomasz Chmielewski wrote:

    > Tomasz Chmielewski wrote:
    >
    >> 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;
    > }


    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).

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Sep 6, 2009
    #4
  5. Jukka K. Korpela wrote:

    > 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.



    --
    Tomasz Chmielewski
    http://wpkg.org
     
    Tomasz Chmielewski, Sep 6, 2009
    #5
  6. dorayme wrote:
    > In article <h7unh7$6o6$>,
    > Tomasz Chmielewski <> wrote:
    >
    >> 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>

    >
    > Diagonal writing!
    >
    > <http://dorayme.netweaver.com.au/diagonalWriting.html>


    Unfortunately, I don't have much control over HTML code, so I can't do
    it this way.


    --
    Tomasz Chmielewski
    http://wpkg.org
     
    Tomasz Chmielewski, Sep 6, 2009
    #6
  7. Re: how can I show spaces as spaces?

    On Sep 6, 1:54 am, dorayme <> wrote:

    > Diagonal writing!
    >
    > <http://dorayme.netweaver.com.au/diagonalWriting.html>


    Or with '&nbsp;'


    <html>
    <head>
    <title>lazy man</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
    var space = '&nbsp;&nbsp;&nbsp;&nbsp;';
    for (var x=20;x>0;x--)
    {
    var z = space;
    for (var a=0;a<x;a++)
    {
    z = z + space;
    }
    document.writeln(z + 'hi<br>');
    }
    // -->
    </script>
    </body>
    </html>
     
    Jan C. Faerber, Sep 6, 2009
    #7
  8. Tomasz Chmielewski wrote:

    > 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.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Sep 6, 2009
    #8
  9. Re: how can I show spaces as spaces?

    On Sep 6, 1:54 pm, "Jan C. Faerber" <> wrote:

    Or with text:

    > <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;
    }
    document.writeln(z + b.charAt(x) + '<br>');
    }
    > </script>
    > </body>
    > </html>
     
    Jan C. Faerber, Sep 6, 2009
    #9
  10. Re: how can I show spaces as spaces?

    On Sep 6, 2:25 pm, "Jan C. Faerber" <> wrote:
    > On Sep 6, 1:54 pm, "Jan C. Faerber" <> wrote:


    Or with text going from the top down to the bottom:

    > > <html>
    > > <head>
    > > <title>lazy man</title>
    > > </head>
    > > <body>
    > > <script language="JavaScript">

    <!--
    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>');
    }
    // -->
    > > </script>
    > > </body>
    > > </html>


    (in the last posting I forgot the closing
    //-->)
     
    Jan C. Faerber, Sep 6, 2009
    #10
  11. Re: how can I show spaces as spaces?

    <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
     
    Jan C. Faerber, Sep 6, 2009
    #11
  12. Tomasz Chmielewski

    Doug Miller Guest

    In article <h807t2$b54$>, Tomasz Chmielewski <> wrote:

    >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.
     
    Doug Miller, Sep 6, 2009
    #12
  13. ..oO(Doug Miller)

    >In article <h807t2$b54$>, Tomasz Chmielewski <> wrote:
    >
    >>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?


    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
     
    Michael Fesser, Sep 6, 2009
    #13
  14. Michael Fesser wrote:

    >>> 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.

    [...]
    > 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.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Sep 6, 2009
    #14
  15. Jukka K. Korpela wrote:
    > Tomasz Chmielewski wrote:
    >
    >> 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.


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


    >> 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?


    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/



    --
    Tomasz Chmielewski
    http://wpkg.org
     
    Tomasz Chmielewski, Sep 6, 2009
    #15
  16. Doug Miller wrote:
    > In article <h807t2$b54$>, Tomasz Chmielewski <> wrote:
    >
    >> I have some software which "transforms" received emails into web pages.

    >
    > That is SO not a good idea.


    Most web email archives work this way.


    >> 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.


    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.


    --
    Tomasz Chmielewski
    http://wpkg.org
     
    Tomasz Chmielewski, Sep 6, 2009
    #16
  17. Tomasz Chmielewski

    Doug Miller Guest

    In article <>, Michael Fesser <> wrote:
    >..oO(Doug Miller)
    >
    >>In article <h807t2$b54$>, Tomasz Chmielewski

    > <> wrote:
    >>
    >>>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?

    >
    >Where did he mention HTML emails?


    Why do imagine that it makes a difference?
    >
    >>Hopefully, the need for better software, if not a completely different
    >>approach, is now obvious.

    >
    >It would work well for plain text emails.
    >

    What do you imagine to be the difference between "HTML emails" and "plain text
    emails"?
     
    Doug Miller, Sep 6, 2009
    #17
  18. Tomasz Chmielewski

    dorayme Guest

    In article <h807un$b54$>,
    Tomasz Chmielewski <> wrote:

    > 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.

    --
    dorayme
     
    dorayme, Sep 6, 2009
    #18
  19. dorayme wrote:
    > In article <h807un$b54$>,
    > Tomasz Chmielewski <> wrote:
    >
    >> 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.


    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.

    --
    Tomasz Chmielewski
    http://wpkg.org
     
    Tomasz Chmielewski, Sep 7, 2009
    #19
  20. Re: how can I show spaces as spaces?

    On Sep 6, 3:24 pm, "Jan C. Faerber" <> wrote:

    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?
     
    Jan C. Faerber, Sep 7, 2009
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt

    TO show or NOT to show

    Matt, May 2, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    398
  2. John B. Matthews
    Replies:
    4
    Views:
    681
    John B. Matthews
    Sep 12, 2008
  3. Roedy Green
    Replies:
    3
    Views:
    641
  4. Tomasz Chmielewski

    how can I show spaces as spaces, part 2

    Tomasz Chmielewski, Sep 9, 2009, in forum: HTML
    Replies:
    14
    Views:
    892
    Jan C. Faerber
    Sep 10, 2009
  5. johkar
    Replies:
    2
    Views:
    2,960
    Mayeul
    Dec 10, 2009
Loading...

Share This Page