I have a <p>
with some large content in it. This is paragraph is retrieved from firebase realtime database. As we cannot store use \n
directly in firebase database (because when retrieved it will simply print as \n in the paragraph).
So I store it in firebase database as _n_
and when retrieved in my JavaScript code I replace it with \n
. Just like below:
let formattedContent = String(content).replace(/_n_/g, "\n");
Content is just data received.
The \n
is not working here. But when I change the tag from <p>
to <pre>
it worked. All the \n present were doing the job of adding new lines.
But some of my lines are pretty long and content will overflow the container if I use the pre tag.
Even though I have added word wrap. word-wrap: break-word;
So how can I get \n
working in <p>
tag?
EDIT: I have tried replacing with <br/>
but it justs prints itself inside the P tag.
Also for some reason this solution kept overflowing my container.
`s, `\n` is not a part of HTML (excluding some special elements like `pre`), it's is renedered as it is. – Teemu May 04 '20 at 13:48
`?
– Pedro Lima May 04 '20 at 13:49