Roland
Roland

Reputation: 7853

HTMLEditFormat and take care of line breaks

I have some text that I get from my database and want to insert into an HTML page. I'm using HTMLEditFormat to take care of special characters like '<' etc...

Problem: When this is displayed in the browser all the line breaks are gone. Is there a special formatting function in CF that will automatically replace all line breaks with the correct HTML tag?

Upvotes: 0

Views: 509

Answers (1)

Brad Wood
Brad Wood

Reputation: 3953

HTMLEditFormat() will escape any HTML markup, but the line breaks are a separate issue. By definition, line breaks in HTML don't affect rendering. Same as multiple spaces and tabs.

If the text in question was collected in a textarea, one option is to output it in a disabled textarea, which will render the line breaks and spaces as they were typed.

My usual approach to to replace new lines with a
tag and tabs with 5  's. The paragraphFormat() function will handle new lines. http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e24.html

Or this function from CFLib will also handle the tabs for you: http://www.cflib.org/udf/ParagraphFormat2

Upvotes: 5

Related Questions