Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert \n to HTML line break

Tags:

javascript

I am using this plugin to parse bbcode bbcodeparser

but it has no functionality to convert \n to <br/>.

I tried adding this:

replace(/\r?\n|\r/g, '<br>') 

...but it didn't work.

How can I implement line break functionality?

like image 248
user007 Avatar asked Feb 19 '13 01:02

user007


People also ask

How do I make a line break in HTML?

The <br> HTML element produces a line break in text (carriage-return).

Can we use \n in HTML?

This is to show new line and return carriage in HTML, then you don't need to do it explicitly. You can do it in CSS by setting the white-space attribute pre-line value.

How do you put a line break in space in HTML?

If you want to prevent a line break between two words, use a non-breaking space. If you want to insert a line break, use the HTML break tag, written as <br>. You don't need a closing tag here — just writing <br> adds a line break.


1 Answers

If you are doing this to show new line and return carriage in html, then you don't need to do it explicitly. You can do it in css by setting the white-space attribute pre-line value.

<span style="white-space: pre-line">@Model.CommentText</span> 
like image 183
Foreever Avatar answered Sep 18 '22 12:09

Foreever