Light markup like <BR> inside text won't get added to the DOM

24 views
Skip to first unread message

Arturo

unread,
Nov 2, 2012, 4:35:22 PM11/2/12
to transpa...@googlegroups.com

HTML

 <div id="dialog"><p id="message"></p></div>

 

JSON

 data = {message='There should be<br>two lines here'};

$('#dialog').render(data);

Rendered HTML

 <div id="dialog"><p id="message">There should be<br>two lines here</p></div>


And the <br> shouws up as text in the browser, which implies that the dom does not change. Is there a simple way say $('#dialog').flatten(); so it expands out the HTML?


Any help will be appreciated.

Arturo





Arturo

unread,
Nov 2, 2012, 5:13:09 PM11/2/12
to transpa...@googlegroups.com
I'll answer my own question.

the following code will tell transparency to use innerHTML rather than nodeValue

directives = { 
message: {
html: function(params) {
return this.message;
}
}
}

$('#dialog').render(data);

Mikko Ohtamaa

unread,
Nov 2, 2012, 5:16:32 PM11/2/12
to transpa...@googlegroups.com
JSON

 data = {message='There should be<br>two lines here'};

$('#dialog').render(data);

Rendered HTML

 <div id="dialog"><p id="message">There should be<br>two lines here</p></div>


 

And the <br> shouws up as text in the browser, which implies that the dom does not change. Is there a simple way say $('#dialog').flatten(); so it expands out the HTML?

What you probably mean is showing unescaped HTML code which is disabled by default due to safety reasons as it opens a door for cross-site scripting attack.

HTML escaping is controlled with directives and "html" attribute. Please see https://github.com/leonidas/transparency/ Nested Directives example where it outputs plain HTML.

Ps. <br> tag has been deprecated as far back as early 2000 and you should use <p> for formatting paragraphs.


 
Reply all
Reply to author
Forward
0 new messages