|
@@ -27,7 +27,7 @@ from . import Node |
|
|
__all__ = ["HTMLEntity"] |
|
|
__all__ = ["HTMLEntity"] |
|
|
|
|
|
|
|
|
class HTMLEntity(Node): |
|
|
class HTMLEntity(Node): |
|
|
def __init__(self, value, named=None, hexadecimal=False): |
|
|
|
|
|
|
|
|
def __init__(self, value, named=None, hexadecimal=False, hex_char="x"): |
|
|
self._value = value |
|
|
self._value = value |
|
|
if named is None: # Try to guess whether or not the entity is named |
|
|
if named is None: # Try to guess whether or not the entity is named |
|
|
try: |
|
|
try: |
|
@@ -45,12 +45,13 @@ class HTMLEntity(Node): |
|
|
else: |
|
|
else: |
|
|
self._named = named |
|
|
self._named = named |
|
|
self._hexadecimal = hexadecimal |
|
|
self._hexadecimal = hexadecimal |
|
|
|
|
|
self._hex_char = hex_char |
|
|
|
|
|
|
|
|
def __unicode__(self): |
|
|
def __unicode__(self): |
|
|
if self.named: |
|
|
if self.named: |
|
|
return u"&{0};".format(self.value) |
|
|
return u"&{0};".format(self.value) |
|
|
if self.hexadecimal: |
|
|
if self.hexadecimal: |
|
|
return u"&#x{0};".format(self.value) |
|
|
|
|
|
|
|
|
return u"&#{0}{1};".format(self.hex_char, self.value) |
|
|
return u"&#{0};".format(self.value) |
|
|
return u"&#{0};".format(self.value) |
|
|
|
|
|
|
|
|
def __strip__(self, normalize, collapse): |
|
|
def __strip__(self, normalize, collapse): |
|
@@ -93,6 +94,10 @@ class HTMLEntity(Node): |
|
|
def hexadecimal(self): |
|
|
def hexadecimal(self): |
|
|
return self._hexadecimal |
|
|
return self._hexadecimal |
|
|
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
|
def hex_char(self): |
|
|
|
|
|
return self._hex_char |
|
|
|
|
|
|
|
|
def normalize(self): |
|
|
def normalize(self): |
|
|
if self.named: |
|
|
if self.named: |
|
|
return unichr(htmlentitydefs.name2codepoint[self.value]) |
|
|
return unichr(htmlentitydefs.name2codepoint[self.value]) |
|
|