Opened 17 years ago

Closed 17 years ago

#5821 closed (wontfix)

Adds decode_entities to utils.html

Reported by: Samuel Adam <samuel.adam@…> Owned by: nobody
Component: Tools Version: dev
Severity: Keywords: html
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This patch adds html entities decoding function to utils.html

Description

Replaces HTML entities (name, decimal and hexadecimal) with unicode equivalents.

Ampersands, quotes and carets are not replaced by default.

Usage

decode_entities can be used to normalize and store user input from a js html editor for example.
If you need to cut a string that could contain HTML entities, you can decode it before the cut without the fear of cutting through an entity.

Examples

>>> from django.utils.html import decode_entities
>>> html = u'&lt;D&eacute;j&agrave; &#9001;&gt;'
>>> decode_entities(html)
u'&lt;D\xe9j\xe0 \u2329&gt;'
>>> decode_entities(html, decode_all=True)
u'<D\xe9j\xe0 \u2329>'

Attachments (2)

5821_decode_entities.patch (4.1 KB ) - added by Samuel Adam <samuel.adam@…> 17 years ago.
decode_entities and tests
5821_decode_entities.2.patch (4.1 KB ) - added by Samuel Adam <samuel.adam@…> 17 years ago.
decode_entities and test ( fixed regexp )

Download all attachments as: .zip

Change History (4)

by Samuel Adam <samuel.adam@…>, 17 years ago

Attachment: 5821_decode_entities.patch added

decode_entities and tests

by Samuel Adam <samuel.adam@…>, 17 years ago

decode_entities and test ( fixed regexp )

comment:1 by Simon G <dev@…>, 17 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by Jacob, 17 years ago

Resolution: wontfix
Status: newclosed

This is a good candidate for a custom template tag in a third-party app or library, but it's a bit too special case for Django proper.

Note: See TracTickets for help on using tickets.
Back to Top