Skip to main content
Inspiring
January 14, 2009
Answered

HTMLEditFormat/HTMLCodeFormat with line breaks and word wrap

  • January 14, 2009
  • 1 reply
  • 1679 views
I'm attempting to output some user entered information to the screen and am running into a formatting problem. If I use HTMLEditFormat(), I lose all the line breaks, but it word wraps nicely. If I use HTMLCodeFormat(), I get the line breaks, but the text also doesn't word wrap, making some really wide screens, even if I put the information in a table with specific a specific width defined. Isn't there some way to get the best of both?? I need to be able to keep any line breaks (sometimes they've entered lists or have multiple paragraphs) but would like it to word wrap too so that it's easy to read without scrolling sideways. Any ideas??
    This topic has been closed for replies.
    Correct answer DeliK
    Thanks for your suggestions. Since the information is input by external users and then displayed to the public, I am using HTMLEditFormat and HTMLCodeFormat to help prevent cross scripting attacks, so don't really want to jettison them altogether. However, I did discover after playing with the suggestion listed here, that this will work: #Replace(HTMLEditFormat(mytext),chr(10),"<br />","all")#

    HTMLEditFormat gets rid of the return character, but not the line feed, so it is possible to replace the line feeds with <br /> to create the desired affect.

    Thanks for your suggestions.

    1 reply

    Inspiring
    January 15, 2009
    use Replace() or REReplace cf functions to replace plain-text linebreaks
    with html <br> element. off the top of my head, something like this:

    <cfoutput>#replace(mytext, chr(10)&chr(13), "<br />", "all")#</cfoutput>

    or

    <cfoutput>#rereplace(mytext, "\n", "<br />", "all")#</cfoutput>

    hth


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Participating Frequently
    January 15, 2009
    I had a similar situation on a project several years ago and that solution is in the same vein as the one I used - it should get you the results you're looking for.