Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you make newline characters \n display as breaks <br />?

I'm trying to display emails with IMAP. When the email is text though, the newlines \n don't display properly. I'd rather not convert them to breaks < br /> because if the user wanted to reply to that email, it would now be in HTML instead of plain text. Is there perhaps a javascript function that could display it as a line break without changing the code?

like image 269
James Avatar asked Oct 29 '12 09:10

James


People also ask

What is \n line break?

Newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in a character encoding specification (e.g., ASCII, EBCDIC) that is used to signify the end of a line of text and the start of a new one.

How do you show line break in code?

<br>: The Line Break element. The <br> HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.

How do you line break without br?

Use block-level elements to break the line without using <br> tag. There are many ways to break the line without using <br> tag. The used properties are listed below: white-space: pre; It is used to make elements acts like <pre> tag.

How do you make a line break in HTML?

The <br> tag inserts a single line break. The <br> tag is useful for writing addresses or poems. The <br> tag is an empty tag which means that it has no end tag.


1 Answers

How about HTML/CSS? If you put your text inside a <pre> tag, it will show all newlines exactly as they were. Alternatively, you can achieve the same effect by applying the CSS style white-space:pre to any element.

Don't forget to HTMLencode it still (< to &lt; etc.), otherwise it will all break apart at the first angle bracket.

like image 126
Vilx- Avatar answered Sep 24 '22 00:09

Vilx-