|
@@ -2,6 +2,7 @@
|
|
|
import html
|
|
|
from html.parser import HTMLParser
|
|
|
|
|
|
+from django.utils.html import VOID_ELEMENTS
|
|
|
from django.utils.regex_helper import _lazy_re_compile
|
|
|
|
|
|
|
|
@@ -200,27 +201,6 @@ class HTMLParseError(Exception):
|
|
|
|
|
|
|
|
|
class Parser(HTMLParser):
|
|
|
-
|
|
|
- SELF_CLOSING_TAGS = {
|
|
|
- "area",
|
|
|
- "base",
|
|
|
- "br",
|
|
|
- "col",
|
|
|
- "embed",
|
|
|
- "hr",
|
|
|
- "img",
|
|
|
- "input",
|
|
|
- "link",
|
|
|
- "meta",
|
|
|
- "param",
|
|
|
- "source",
|
|
|
- "track",
|
|
|
- "wbr",
|
|
|
-
|
|
|
- "frame",
|
|
|
- "spacer",
|
|
|
- }
|
|
|
-
|
|
|
def __init__(self):
|
|
|
super().__init__()
|
|
|
self.root = RootElement()
|
|
@@ -248,14 +228,14 @@ class Parser(HTMLParser):
|
|
|
|
|
|
def handle_startendtag(self, tag, attrs):
|
|
|
self.handle_starttag(tag, attrs)
|
|
|
- if tag not in self.SELF_CLOSING_TAGS:
|
|
|
+ if tag not in VOID_ELEMENTS:
|
|
|
self.handle_endtag(tag)
|
|
|
|
|
|
def handle_starttag(self, tag, attrs):
|
|
|
attrs = normalize_attributes(attrs)
|
|
|
element = Element(tag, attrs)
|
|
|
self.current.append(element)
|
|
|
- if tag not in self.SELF_CLOSING_TAGS:
|
|
|
+ if tag not in VOID_ELEMENTS:
|
|
|
self.open_tags.append(element)
|
|
|
self.element_positions[element] = self.getpos()
|
|
|
|