[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
Hi T.J., I finally got around trying your recommendation and it worked flawlessly. Thanks a ton. -- Kash On Jun 13, 3:32 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi, String#escapeHTML doesn't do anything with embedded newlines; it Converts HTML special characters to their entity equivalents. Newlines aren't special HTML characters, they're just whitespace. You can easily do what you want with a String#replace[1]: after = before.replace(/\n/g, br/); Be sure you do the replace *after* you escape the HTML, otherwise you'll end up with the br/ displayed literally. So: after = before.escapeHTML().replace(/\n/g, br/); I don't think browsers ever put a \r before the \n in textareas, but I couldn't swear to it, so if it were me I'd probably hedge my bets and optionally include it: after = before.escapeHTML().replace(/\r?\n/g, br/); [1]https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global... HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Jun 12, 8:36 pm, Kash kaushikagra...@gmail.com wrote: Hey Guys, I am using the escapeHTML() string function in the following manner. $('divElement').update( stringInput.escapeHTML() ); Now my stringInput is something like This is a test\nThis should be a new line!!! The \n does not show up as a new line on my HTML page. Was hoping someone could guide me what a work around could be so that a new line shows up on my HTML page. I did try putting lt;br#47;gt; instead of \n. But it just shows up as something weird on the HTML page. Please help. P.s: I would still like to keep using escapeHTML, so a solution which doesn't involve removing escapeHTML from the code would help... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
@kangax Rob: I didn't mean to step into someone's holy war here. By seems to be recommended I meant what I said earlier, used in the unit tests and such. Let's just change them to something reasonable and move on. -- T.J. On Jun 17, 7:10 am, RobG robg...@gmail.com wrote: On Jun 15, 5:48 pm, T.J. Crowder t...@crowdersoftware.com wrote: Heya, I thought it wouldn't come as a surprise that using XHTML makes no sense... Hey, HTML and CSS make no sense, let alone XHTML. But that's OT. :-) I'm just saying, the doctype that seems to be recommended is XHTML transitional, By who? Certainly not by those who understand the issues involved - search the archives at: news:comp.infosystems.www.authoring.html URL:http://groups.google.com/group/comp.infosystems.www.authoring.html?lnk= XHTML is pretty much dead, it is essentially replaced by HTML 5. The vast majority of documents with an XHTML DOCTYPE are served as text/ html, so they are treated by browsers as invalid HTML. It was something of a fad to pretend to use XHTML, it serves no useful purpose. I always chuckle when I see an IIS server using the default XHTML DOCTYPE, then serve it as text/html. If it was served as XML, IE would not know what to do with it since IE is one of the few modern browsers that don't know what XML is. A clear case of style over substance. so that's what I use as I don't have a strong reason for doing anything else, and in the XHTML transitional doctype, br/ is correct and I'm guessing requires less work from the browser. But of course, you're right that if you don't specify any doctype or if you specify an HTML doctype, you want br. I don't know if that's going to be 99% of the time, but it's going to be a big number. Probably 99.999% The take away for the OP is: Use a doctype (just about any doctype), and then use br or br/ depending on what doctype you're using. The DOCTYPE is pretty much irrelevant except for switching to or from standards mode (or almost standards mode). Whether the document is treated as XML or HTML depends on the response header content type. -- Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
Sorry, holy war reads a lot stronger than I meant it to. I'm just frustrated by the utter bollocks that comes out of the W3C more often than not. -- T.J. On Jun 17, 9:44 am, T.J. Crowder t...@crowdersoftware.com wrote: @kangax Rob: I didn't mean to step into someone's holy war here. By seems to be recommended I meant what I said earlier, used in the unit tests and such. Let's just change them to something reasonable and move on. -- T.J. On Jun 17, 7:10 am, RobG robg...@gmail.com wrote: On Jun 15, 5:48 pm, T.J. Crowder t...@crowdersoftware.com wrote: Heya, I thought it wouldn't come as a surprise that using XHTML makes no sense... Hey, HTML and CSS make no sense, let alone XHTML. But that's OT. :-) I'm just saying, the doctype that seems to be recommended is XHTML transitional, By who? Certainly not by those who understand the issues involved - search the archives at: news:comp.infosystems.www.authoring.html URL:http://groups.google.com/group/comp.infosystems.www.authoring.html?lnk= XHTML is pretty much dead, it is essentially replaced by HTML 5. The vast majority of documents with an XHTML DOCTYPE are served as text/ html, so they are treated by browsers as invalid HTML. It was something of a fad to pretend to use XHTML, it serves no useful purpose. I always chuckle when I see an IIS server using the default XHTML DOCTYPE, then serve it as text/html. If it was served as XML, IE would not know what to do with it since IE is one of the few modern browsers that don't know what XML is. A clear case of style over substance. so that's what I use as I don't have a strong reason for doing anything else, and in the XHTML transitional doctype, br/ is correct and I'm guessing requires less work from the browser. But of course, you're right that if you don't specify any doctype or if you specify an HTML doctype, you want br. I don't know if that's going to be 99% of the time, but it's going to be a big number. Probably 99.999% The take away for the OP is: Use a doctype (just about any doctype), and then use br or br/ depending on what doctype you're using. The DOCTYPE is pretty much irrelevant except for switching to or from standards mode (or almost standards mode). Whether the document is treated as XML or HTML depends on the response header content type. -- Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
On Jun 16, 4:57 am, T.J. Crowder t...@crowdersoftware.com wrote: Heya, If XHTML isn't necessary for Prototype, I'd suggest we change the doctype of the examples and unit tests. Good idea. Exclusively using XHTML doctype either shows our ignorance on the subject or the fact that we prefer to serve browsers with broken tag soup with no apparent benefits. What doctype do you use? You've been using and contributing to Prototype for a long time, I'll totally jump ship to whatever you're using. I'm using HTML 4.01 strict, but I really don't want you to jump this ship just because I'm on it :) I'd rather you realize why this is the only viable option at the moment (seriously, look at that article link to which I pasted earlier). [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
Heya, I thought it wouldn't come as a surprise that using XHTML makes no sense... Hey, HTML and CSS make no sense, let alone XHTML. But that's OT. :-) I'm just saying, the doctype that seems to be recommended is XHTML transitional, so that's what I use as I don't have a strong reason for doing anything else, and in the XHTML transitional doctype, br/ is correct and I'm guessing requires less work from the browser. But of course, you're right that if you don't specify any doctype or if you specify an HTML doctype, you want br. I don't know if that's going to be 99% of the time, but it's going to be a big number. The take away for the OP is: Use a doctype (just about any doctype), and then use br or br/ depending on what doctype you're using. -- T.J. :-) On Jun 14, 6:08 pm, kangax kan...@gmail.com wrote: On Jun 14, 4:15 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi, Isn't the recommended doctype when using Prototype xhtml transitional? br doesn't validate in xhtml transitional, it has no closing tag. I thought it wouldn't come as a surprise that using XHTML makes no sense http://hixie.ch/advocacy/xhtml. I know that Rails blindly uses XHTML. I remember Mislav mentioned that the issue was brought up on Rails mailing list but that noone seemed to care http:// mislav.uniqpath.com/rails/cargo-culting-xhtml-considered-harmful/ I'm not sure about recommended doctype, but I know that Prototype most likely doesn't work when served and parsed as application/xhtml+xml. Object model of documents parsed as XML is different: from what I remember, `document.write` doesn't work, `innerHTML` parser works differently, etc. All of the Prototype's unit tests use XHTML doctype, but fail to set proper content-type response header. This means that browsers are told to *parse and render page as HTML*, but are actually being served a so- called xhtml tag soup http://en.wikipedia.org/wiki/Tag_soup, which they simply correct into proper HTML (this correction also takes time, of course, but I'm not sure if it's significant). I personally have never seen Prototype tests run as real XHTML, so I can't be sure that it works. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
On Jun 15, 3:48 am, T.J. Crowder t...@crowdersoftware.com wrote: Heya, I thought it wouldn't come as a surprise that using XHTML makes no sense... Hey, HTML and CSS make no sense, let alone XHTML. But that's OT. :-) I'm just saying, the doctype that seems to be recommended is XHTML transitional, so that's what I use as I don't have a strong reason for I would certainly not recommend any type of XHTML doctype (when designing apps for general web). I don't see a reason for Prototype to recommend or encourage it either. As I said, there's no point in using xhtml 99% of the time (for the reasons described well in that article). That's pretty much all I'm saying ;) [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
Hi, Isn't the recommended doctype when using Prototype xhtml transitional? br doesn't validate in xhtml transitional, it has no closing tag. -- T.J. :-) On Jun 13, 8:40 pm, kangax kan...@gmail.com wrote: On Jun 13, 3:32 am, T.J. Crowder t...@crowdersoftware.com wrote: [...] I don't think browsers ever put a \r before the \n in textareas, but I couldn't swear to it, so if it were me I'd probably hedge my bets and optionally include it: after = before.escapeHTML().replace(/\r?\n/g, br/); br/ should really be br 99% of the time ; ) [...] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
On Jun 14, 4:15 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi, Isn't the recommended doctype when using Prototype xhtml transitional? br doesn't validate in xhtml transitional, it has no closing tag. I thought it wouldn't come as a surprise that using XHTML makes no sense http://hixie.ch/advocacy/xhtml. I know that Rails blindly uses XHTML. I remember Mislav mentioned that the issue was brought up on Rails mailing list but that noone seemed to care http:// mislav.uniqpath.com/rails/cargo-culting-xhtml-considered-harmful/ I'm not sure about recommended doctype, but I know that Prototype most likely doesn't work when served and parsed as application/xhtml+xml. Object model of documents parsed as XML is different: from what I remember, `document.write` doesn't work, `innerHTML` parser works differently, etc. All of the Prototype's unit tests use XHTML doctype, but fail to set proper content-type response header. This means that browsers are told to *parse and render page as HTML*, but are actually being served a so- called xhtml tag soup http://en.wikipedia.org/wiki/Tag_soup, which they simply correct into proper HTML (this correction also takes time, of course, but I'm not sure if it's significant). I personally have never seen Prototype tests run as real XHTML, so I can't be sure that it works. [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
Hi, String#escapeHTML doesn't do anything with embedded newlines; it Converts HTML special characters to their entity equivalents. Newlines aren't special HTML characters, they're just whitespace. You can easily do what you want with a String#replace[1]: after = before.replace(/\n/g, br/); Be sure you do the replace *after* you escape the HTML, otherwise you'll end up with the br/ displayed literally. So: after = before.escapeHTML().replace(/\n/g, br/); I don't think browsers ever put a \r before the \n in textareas, but I couldn't swear to it, so if it were me I'd probably hedge my bets and optionally include it: after = before.escapeHTML().replace(/\r?\n/g, br/); [1] https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/String/Replace HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Jun 12, 8:36 pm, Kash kaushikagra...@gmail.com wrote: Hey Guys, I am using the escapeHTML() string function in the following manner. $('divElement').update( stringInput.escapeHTML() ); Now my stringInput is something like This is a test\nThis should be a new line!!! The \n does not show up as a new line on my HTML page. Was hoping someone could guide me what a work around could be so that a new line shows up on my HTML page. I did try putting lt;br#47;gt; instead of \n. But it just shows up as something weird on the HTML page. Please help. P.s: I would still like to keep using escapeHTML, so a solution which doesn't involve removing escapeHTML from the code would help... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Creating new lines and bypassing them through escapeHTML
On Jun 13, 3:32 am, T.J. Crowder t...@crowdersoftware.com wrote: [...] I don't think browsers ever put a \r before the \n in textareas, but I couldn't swear to it, so if it were me I'd probably hedge my bets and optionally include it: after = before.escapeHTML().replace(/\r?\n/g, br/); br/ should really be br 99% of the time ; ) [...] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---