def entity2text(entitydef):
"""Convert an HTML entity reference into unicode.
http://stackoverflow.com/a/58125/408556
"""
if entitydef.startswith('&#x'):
cp = int(entitydef[3:-1], 16)
elif entitydef.startswith('&#'):
cp = int(entitydef[2:-1])
elif entitydef.startswith('&'):
cp = name2codepoint[entitydef[1:-1]]
else:
logger.debug(entitydef)
cp = None
return chr(cp) if cp else entitydef
评论列表
文章目录