In mongo I have a document with a field like reviewText: 'this is line 1\nthis is line 2',
. I got that from a textarea
so the \n
is there because the user hit enter. I want to print the text on the screen in a div with a line break (preferably only one line break if he hits many enters) I don't know how to do that I dont get on the screen any \n
s
I do <div class = "displayReview"><%= e.reviewText %></div>
in EJS that just prints it all on oneline. It gets me <div class="displayReview">this is line 1 this is line 2</div>
in the browser.
I have someplace in my routes that updates the docs like:
.then(function(returnedReviews){
console.log(" returnedReview ",returnedReviews);
returnedReviews.forEach(function(e){
e.momented = moment(e.createdAt.getTime()).fromNow()
// e.reviewText = e.reviewText.replace(/\r?\n/g, '<br />')
})
I tried to do what I have in the comments. but that obviously just put <br />
(the text) in the string and not HTML. I was hoping there was an easy way to do this.
I want to see line breaks when it gets printed to the screen where the user hits enter in the textarea
before he sent the form. If the user hits the enter button multiple times in a row there should be only one line break.
white-space: pre;
to see the spaces but that is not what I want. One problem is that you could see the spaces where users hits a lot of spaces.