BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
856 stars 130 forks source link

custom converter html encoding #392

Closed ainglese closed 6 years ago

ainglese commented 6 years ago

Hi,i've a custom converter witch should output raw html, but the output of the converter gets html-encoded. i can't find any documentation if this is by design and how to avoid that.

//pseudocode
$.views.converters({
    _f:function(val){ return "€" + " " + val; }
});
<span data-link="{_f:amount}"></span>
//the output is €&nbsp;1234
BorisMoore commented 6 years ago

I'm travelling at the moment so can't reply until after returning on the 20th

BorisMoore commented 6 years ago

Yes, it is by design: the default data-linking target is innerText - so it HTML encodes by default.

See the following topics:

So with your converter, you can choose the html target:

<span data-link="html{_f:amount}"></span>

Alternatively you could use:

{^{_f:amount}}
ainglese commented 6 years ago

ok, so the encoding is done on the default binding to innerText, i was assuming it was being done in the converter. now it's clear, thank you!