On 11/17/06, Karl Guertin <[EMAIL PROTECTED]> wrote:
>
> On 11/17/06, chiangf <[EMAIL PROTECTED]> wrote:
> > Does anyone know how to do this?
>
> Do it server side and send the text with the <br> already in place. I
> haven't tried it in JS, but I'd imagine you'd have to at least
> innerHTML the result into the DOM node to get it to process.

The problem with innerHTML is that you have to ensure that it's
escaped correctly... otherwise you might unintentionally cause the
browser to attempt to parse a tag or character entity. If you're
working with text that has newlines in it and not br tags then you
probably aren't dealing with HTML and you shouldn't trivially treat it
as such.

Doing it with DOM is easy enough, though. This function returns an
Array of alternating strings and br tags that you could use with
appendChildNodes or whatnot.

var dom_nl2br = function (str) {
    var res = str.split(/\n/);
    for (var i = res.length - 1; i > 0; i--) {
        res.splice(i, 0, BR());
    }
    return res;
};

-bob

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to