So I have this block of jquery inside a coffeescript file;
$("#parser-results").append(
"<tr><td>" + d.id + "</td>" +
"<td>" + d.received_at + "</td>" +
"<td>" + d.from_address + "</td>" +
"<td>" + d.to_address + "</td>" +
"<td>" + d.subject_text + "</td></tr>" +
"<tr><td colspan=5><div class='body-text'>" + d.body_text.replace(/\n/g, "<br />") + "</div></td></tr>"
)
The problem here relates to the variable d.body_text, which is a retrieved TEXT field from a database.
I am trying to replace all instances of \n with a <br> and I have literally tried every jquery, javascript and coffeescript variation of every approach that I could find on the internet. I've also tried preg_replace and nl2br before the data is entered in the database to no avail.
Also, the data is coming from a mail parsing service called mailparser.io. I doubt it has anything to do with that but I'm really just not sure anymore.
What is missing here? I need some help identifying what the problem could be.
<br>to get line breaks. Just usewhite-space:pre-wrap;in your css, and leave the text alone. Or usepre-lineif you want to have multiple spaces collapsed into one. See developer.mozilla.org/en-US/docs/Web/CSS/white-space .d.body_textlooks like? Are you sure you have newlines and not\ns as two characters?\nchars in the database. e.ghey guys\nhow are you?\nd.body_text.replace(/\\n/g, '<br>')gives you the results you want then?