Hi, I''ve got some code that takes what a user writes in a text area, and puts it into an html tag on the page. I want to display line breaks as they are entered, but I don''t want to use white-space:pre, and white-space:pre-line doesn''t seem to be supported (or isn''t what I thought it was). So I came up with this: DOMElement.innerHTML=text.escapeHTML().replace(/\n/g,"<br/>"); This works in FireFox, but in IE the escapeHTML function destroys all the carriage returns from the original text, so the replace always does nothing. Does anyone know how to either: - do what I want to do by another (sensible) means, - fix the code above, or - fix the prototype escapeHTML function, so that it doesn''t remove line breaks? Thanks, Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Maybe switch the order of operations? DOMElement.innerHTML = text.replace(/\n/g,"<br/>").escapeHTML(); ...or would that be worse? Just a thought. On 9/22/06, Chris Lear <chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org> wrote:> > > Hi, > > I''ve got some code that takes what a user writes in a text area, and > puts it into an html tag on the page. I want to display line breaks as > they are entered, but I don''t want to use white-space:pre, and > white-space:pre-line doesn''t seem to be supported (or isn''t what I > thought it was). > > So I came up with this: > > DOMElement.innerHTML=text.escapeHTML().replace(/\n/g,"<br/>"); > > This works in FireFox, but in IE the escapeHTML function destroys all > the carriage returns from the original text, so the replace always does > nothing. > > Does anyone know how to either: > > - do what I want to do by another (sensible) means, > - fix the code above, or > - fix the prototype escapeHTML function, so that it doesn''t remove line > breaks? > > Thanks, > Chris > > > >-- Ryan Gahl Application Development Consultant Athena Group, Inc. Inquire: 1-920-954-9798 x2903 Blog: http://www.someElement.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
My layout is all setup to allow design-time switching of stylesheets. Is there a prototypeish add-in or method that supports dynamic stylesheet switching? Sam --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Sam wrote:> My layout is all setup to allow design-time switching of stylesheets. > > Is there a prototypeish add-in or method that supports dynamic > stylesheet switching? > > Sam > > >There was this one that was posted a little while back: http://burnfield.com/martin/2006/07/12/prototypish-style-sheet-switcher --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
* Ryan Gahl wrote (22/09/06 17:58):> Maybe switch the order of operations? > > DOMElement.innerHTML = text.replace(/\n/g,"<br/>").escapeHTML(); > > ...or would that be worse? Just a thought.It''s worse. The <br/> gets escaped, so the markup is displayed on screen, rather than producing a newline. Chris> > On 9/22/06, *Chris Lear* <chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org > <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org>> wrote: > > > Hi, > > I''ve got some code that takes what a user writes in a text area, and > puts it into an html tag on the page. I want to display line breaks as > they are entered, but I don''t want to use white-space:pre, and > white-space:pre-line doesn''t seem to be supported (or isn''t what I > thought it was). > > So I came up with this: > > DOMElement.innerHTML=text.escapeHTML().replace(/\n/g,"<br/>"); > > This works in FireFox, but in IE the escapeHTML function destroys all > the carriage returns from the original text, so the replace always does > nothing. > > Does anyone know how to either: > > - do what I want to do by another (sensible) means, > - fix the code above, or > - fix the prototype escapeHTML function, so that it doesn''t remove line > breaks? > > Thanks, > Chris--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
What about DOMElement.innerHTML = text.replace(/\n/g, "[br]").escapeHTML().replace("/\[b\]/g", "<br/>"); hth On 9/25/06, Chris Lear <chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org> wrote:> > > * Ryan Gahl wrote (22/09/06 17:58): > > Maybe switch the order of operations? > > > > DOMElement.innerHTML = text.replace(/\n/g,"<br/>").escapeHTML(); > > > > ...or would that be worse? Just a thought. > > It''s worse. The <br/> gets escaped, so the markup is displayed on > screen, rather than producing a newline. > > Chris > > > > > On 9/22/06, *Chris Lear* <chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org > > <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org>> wrote: > > > > > > Hi, > > > > I''ve got some code that takes what a user writes in a text area, and > > puts it into an html tag on the page. I want to display line breaks > as > > they are entered, but I don''t want to use white-space:pre, and > > white-space:pre-line doesn''t seem to be supported (or isn''t what I > > thought it was). > > > > So I came up with this: > > > > DOMElement.innerHTML=text.escapeHTML().replace(/\n/g,"<br/>"); > > > > This works in FireFox, but in IE the escapeHTML function destroys > all > > the carriage returns from the original text, so the replace always > does > > nothing. > > > > Does anyone know how to either: > > > > - do what I want to do by another (sensible) means, > > - fix the code above, or > > - fix the prototype escapeHTML function, so that it doesn''t remove > line > > breaks? > > > > Thanks, > > Chris > > > >-- Siegfried Puchbauer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
oops, small typo ;) it should be: DOMElement.innerHTML text.replace(/\n/g, "[br]").escapeHTML().replace("/\[br\]/g", "<br/>"); On 9/25/06, Siegfried Puchbauer <siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > What about > > DOMElement.innerHTML = text.replace(/\n/g, > "[br]").escapeHTML().replace("/\[b\]/g", "<br/>"); > > hth > > On 9/25/06, Chris Lear <chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org> wrote: > > > > > > * Ryan Gahl wrote (22/09/06 17:58): > > > Maybe switch the order of operations? > > > > > > DOMElement.innerHTML = text.replace(/\n/g,"<br/>").escapeHTML(); > > > > > > ...or would that be worse? Just a thought. > > > > It''s worse. The <br/> gets escaped, so the markup is displayed on > > screen, rather than producing a newline. > > > > Chris > > > > > > > > On 9/22/06, *Chris Lear* < chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org > > > <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org>> wrote: > > > > > > > > > Hi, > > > > > > I''ve got some code that takes what a user writes in a text area, > > and > > > puts it into an html tag on the page. I want to display line > > breaks as > > > they are entered, but I don''t want to use white-space:pre, and > > > white-space:pre-line doesn''t seem to be supported (or isn''t what I > > > > > thought it was). > > > > > > So I came up with this: > > > > > > DOMElement.innerHTML=text.escapeHTML().replace(/\n/g,"<br/>"); > > > > > > This works in FireFox, but in IE the escapeHTML function destroys > > all > > > the carriage returns from the original text, so the replace always > > does > > > nothing. > > > > > > Does anyone know how to either: > > > > > > - do what I want to do by another (sensible) means, > > > - fix the code above, or > > > - fix the prototype escapeHTML function, so that it doesn''t remove > > line > > > breaks? > > > > > > Thanks, > > > Chris > > > > > > > > > > > -- > Siegfried Puchbauer-- Siegfried Puchbauer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
* Siegfried Puchbauer wrote (25/09/06 10:28):> oops, small typo ;) > > it should be: > DOMElement.innerHTML > text.replace(/\n/g, "[br]").escapeHTML().replace("/\[br\]/g", "<br/>");Yes, that would work OK, as long as nobody enters "[br]" into the text box. But it does an extra needless replace operation, and isn''t robust (replaces text that might be wanted). Here''s what I''m using now: text.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"); I have a feeling I can get away with only replacing one set of angle brackets, like this: text.replace(/&/g,"&").replace(/</g,"<").replace(/\n/g,"<br/>"); This is presumably the normal way that people without prototype escape their html, and I don''t like it much. I''d be much happier if IE didn''t destroy newlines in the prototype .escapeHTML function. If anyone can come up with a fix/workaround for that, I''d be interested. Chris> > On 9/25/06, *Siegfried Puchbauer* <siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <mailto:siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > > What about > > DOMElement.innerHTML = text.replace(/\n/g, > "[br]").escapeHTML().replace("/\[b\]/g", "<br/>"); > > hth > > > On 9/25/06, * Chris Lear* <chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org > <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org>> wrote: > > > * Ryan Gahl wrote (22/09/06 17:58): >> Maybe switch the order of operations? >> >> DOMElement.innerHTML = text.replace(/\n/g,"<br/>").escapeHTML(); >> >> ...or would that be worse? Just a thought. > > It''s worse. The <br/> gets escaped, so the markup is displayed on > screen, rather than producing a newline. > > Chris > >> >> On 9/22/06, *Chris Lear* < chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org > <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org> >> <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org > <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org>>> wrote: >> >> >> Hi, >> >> I''ve got some code that takes what a user writes in a text > area, and >> puts it into an html tag on the page. I want to display > line breaks as >> they are entered, but I don''t want to use white-space:pre, and >> white-space:pre-line doesn''t seem to be supported (or isn''t > what I >> thought it was). >> >> So I came up with this: >> >> DOMElement.innerHTML=text.escapeHTML().replace(/\n/g,"<br/>"); >> >> This works in FireFox, but in IE the escapeHTML function > destroys all >> the carriage returns from the original text, so the replace > always does >> nothing. >> >> Does anyone know how to either: >> >> - do what I want to do by another (sensible) means, >> - fix the code above, or >> - fix the prototype escapeHTML function, so that it doesn''t > remove line >> breaks? >> >> Thanks, >> Chris >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Be sure to use $(DOMElement).update(blah) instead of DOMElement.innerHTML = blah Prototype has built-in workarounds for issues with IE and table-based elements, and there might be other stuff in the future. With .update() you can feel a bit safer here. Best, Thomas Am 25.09.2006 um 12:21 schrieb Chris Lear:> > * Siegfried Puchbauer wrote (25/09/06 10:28): >> oops, small typo ;) >> >> it should be: >> DOMElement.innerHTML >> text.replace(/\n/g, "[br]").escapeHTML().replace("/\[br\]/g", "<br/ >> >"); > > Yes, that would work OK, as long as nobody enters "[br]" into the text > box. But it does an extra needless replace operation, and isn''t robust > (replaces text that might be wanted). > > Here''s what I''m using now: > > text.replace(/&/g,"&").replace(/</g,"<").replace(/>/ > g,">").replace(/\n/g,"<br/>"); > > I have a feeling I can get away with only replacing one set of angle > brackets, like this: > > text.replace(/&/g,"&").replace(/</g,"<").replace(/\n/g,"<br/ > >"); > > This is presumably the normal way that people without prototype escape > their html, and I don''t like it much. I''d be much happier if IE didn''t > destroy newlines in the prototype .escapeHTML function. If anyone can > come up with a fix/workaround for that, I''d be interested. > > Chris > > >> >> On 9/25/06, *Siegfried Puchbauer* <siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >> <mailto:siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: >> >> What about >> >> DOMElement.innerHTML = text.replace(/\n/g, >> "[br]").escapeHTML().replace("/\[b\]/g", "<br/>"); >> >> hth >> >> >> On 9/25/06, * Chris Lear* <chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org >> <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org>> wrote: >> >> >> * Ryan Gahl wrote (22/09/06 17:58): >>> Maybe switch the order of operations? >>> >>> DOMElement.innerHTML = text.replace(/\n/g,"<br/>").escapeHTML(); >>> >>> ...or would that be worse? Just a thought. >> >> It''s worse. The <br/> gets escaped, so the markup is >> displayed on >> screen, rather than producing a newline. >> >> Chris >> >>> >>> On 9/22/06, *Chris Lear* < chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org >> <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org> >>> <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org >> <mailto:chris.lear-kZMsvDh4tCZWk0Htik3J/w@public.gmane.org>>> wrote: >>> >>> >>> Hi, >>> >>> I''ve got some code that takes what a user writes in a text >> area, and >>> puts it into an html tag on the page. I want to display >> line breaks as >>> they are entered, but I don''t want to use white-space:pre, and >>> white-space:pre-line doesn''t seem to be supported (or isn''t >> what I >>> thought it was). >>> >>> So I came up with this: >>> >>> DOMElement.innerHTML=text.escapeHTML().replace(/\n/g,"<br/>"); >>> >>> This works in FireFox, but in IE the escapeHTML function >> destroys all >>> the carriage returns from the original text, so the replace >> always does >>> nothing. >>> >>> Does anyone know how to either: >>> >>> - do what I want to do by another (sensible) means, >>> - fix the code above, or >>> - fix the prototype escapeHTML function, so that it doesn''t >> remove line >>> breaks? >>> >>> Thanks, >>> Chris >> > > >-- Thomas Fuchs wollzelle http://www.wollzelle.com questentier on AIM madrobby on irc.freenode.net http://www.fluxiom.com :: online digital asset management http://script.aculo.us :: Web 2.0 JavaScript http://mir.aculo.us :: Where no web developer has gone before --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
* Thomas Fuchs wrote (25/09/06 11:49):> Be sure to use > > $(DOMElement).update(blah) > > instead of > > DOMElement.innerHTML = blah > > Prototype has built-in workarounds for issues with IE and table-based > elements, > and there might be other stuff in the future. With .update() you can > feel a bit safer > here.In my version of prototype, it looks like I need to do Element.update(DOMElement,blah) rather than what''s suggested above. Thanks for the tip. Chris> > Best, > Thomas > > Am 25.09.2006 um 12:21 schrieb Chris Lear: > >> >> * Siegfried Puchbauer wrote (25/09/06 10:28): >>> oops, small typo ;) >>> >>> it should be: >>> DOMElement.innerHTML >>> text.replace(/\n/g, "[br]").escapeHTML().replace("/\[br\]/g", "<br/ >>> >"); >> >> Yes, that would work OK, as long as nobody enters "[br]" into the text >> box. But it does an extra needless replace operation, and isn''t robust >> (replaces text that might be wanted). >> >> Here''s what I''m using now: >> >> text.replace(/&/g,"&").replace(/</g,"<").replace(/>/ >> g,">").replace(/\n/g,"<br/>"); >> >> I have a feeling I can get away with only replacing one set of angle >> brackets, like this: >> >> text.replace(/&/g,"&").replace(/</g,"<").replace(/\n/g,"<br/ >> >"); >> >> This is presumably the normal way that people without prototype escape >> their html, and I don''t like it much. I''d be much happier if IE didn''t >> destroy newlines in the prototype .escapeHTML function. If anyone can >> come up with a fix/workaround for that, I''d be interested. >>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---