views:

16

answers:

1

I have a problem with my templates, when I return HTML, it's encoded by default, and I cannot find a way to "fix" it.

I want to replace NewLines (\u000a) with a straight <br />, but I always end up with &amp;lt;br&amp;gt;

I've tried to fix it with this function:

function cleanNewLines(text)
{
   return $("<div>" + text.replace(/\u000a/ig, "<br />") + "</div>").html();
}

But without any luck.

I call bind the template with: {{cleanNewLines(NoteText)}}

What I am trying to accomplish is the ability to render HTML with client-side templates, so if my database contains newlines, I want to be able to replace them with a <br />-tag

So if my database contains the string Hi\u000aThis is a test, I want to replace the \u000a with a <br />, so that the string would be Hi<br />This is a test

A: 

I fixed this by taking the data-container into consideration:

function cleanNewLines(sender, args) 
{
    var data = $("#divNotes");
    data.html(data.html().replace(/\u000a/ig, "<br />"));
}

So when I call the dataview:onrendered I added the cleanNewLines-function and it replaced all newlines (even the ones it shouldn't replace), but I just removed the newlines from the original html and that solved it.

Note: I use jQuery to get the .html()-function

NoLifeKing