ivaynberg/select2 — pull request #355 by slafs (2012-08-26 13:35:17+00:00)
Title: make escapeMarkup optional

This is my pull request on refactoring the place where the `escapeMarkup` lives and making it optional with an `doEscapeMarkup` parameter.

I'm no JS developer and I hope this changes makes sense.

## Reasoning

I'm using select2 with Django by supplying an `ajax` object and I'm generating the rich format of a selection items on server side (i.e. values from db wrapped by some nice tables and images). I want to display those items "as is" and I'm escaping all the user inputed data on server side (in json). So my json looks something like this:

{

"id": "2",
"value": "Pear",
"label": "\n

\n
\n	\n \n \n	Pear\n
\n
\n	this is a pear! and it is <script>alert('hacked');</script>\n
\n

"

},

and format funcs look like this:

formatResult : function (state) {
return state.label;
},
formatSelection : function (state) {
return state.value;
},

because i want to display:

this is a pear! and it is

In current implementation of select2 it seems that i can't do that because theres is no option to ignore the client side escaping.