25 | | "Returns the given HTML with ampersands, quotes and carets encoded" |
26 | | if not isinstance(html, basestring): |
27 | | html = str(html) |
28 | | return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''') |
| 25 | """ |
| 26 | HTML escape the given text with ampersands, quotes and carets encoded. |
| 27 | Alternately, if a list is given, a copy of the list is returned with each |
| 28 | item html escaped (recursively if necessary). |
| 29 | |
| 30 | Useful for this sort of thing: |
| 31 | |
| 32 | {{ names_list|escape|join:'<br />' }} |
| 33 | """ |
| 34 | if isinstance(html, (list, tuple)): |
| 35 | return map(escape, html) |
| 36 | else: |
| 37 | if not isinstance(html, basestring): |
| 38 | html = str(html) |
| 39 | return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''') |