Skip to content

Commit

Permalink
Merge pull request #117 from pallets/html-unescape
Browse files Browse the repository at this point in the history
use html.unescape
  • Loading branch information
davidism committed Apr 9, 2020
2 parents 10b931f + c35603a commit 0d5fa7e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 272 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,8 @@ Version 2.0.0
Unreleased

- Drop Python 2.7, 3.4, and 3.5 support.
- ``Markup.unescape`` uses :func:`html.unescape` to support HTML5
character references. :pr:`117`


Version 1.1.1
Expand Down
19 changes: 2 additions & 17 deletions src/markupsafe/__init__.py
Expand Up @@ -5,7 +5,6 @@
__version__ = "2.0.0a1"

_striptags_re = re.compile(r"(<!--.*?-->|<[^>]*>)")
_entity_re = re.compile(r"&([^& ;]+);")


class Markup(str):
Expand Down Expand Up @@ -110,23 +109,9 @@ def unescape(self):
>>> Markup("Main &raquo; <em>About</em>").unescape()
'Main » <em>About</em>'
"""
from ._constants import HTML_ENTITIES
from html import unescape

def handle_match(m):
name = m.group(1)
if name in HTML_ENTITIES:
return chr(HTML_ENTITIES[name])
try:
if name[:2] in ("#x", "#X"):
return chr(int(name[2:], 16))
elif name.startswith("#"):
return chr(int(name[1:]))
except ValueError:
pass
# Don't modify unexpected input.
return m.group()

return _entity_re.sub(handle_match, str(self))
return unescape(str(self))

def striptags(self):
""":meth:`unescape` the markup, remove tags, and normalize
Expand Down
255 changes: 0 additions & 255 deletions src/markupsafe/_constants.py

This file was deleted.

0 comments on commit 0d5fa7e

Please sign in to comment.