def _escape_text(self, s):
"""Escape text
In addition to escaping text, unicode characters are replaced with a
span that will display the glyph using CSS. This is to ensure that the
text has a consistent width.
"""
tpl = ('<span class="u"><span class="g">&#x{0:x};</span>'
'<span class="ns">{1}</span></span>')
out = ''
for c in s:
w = utils.str_width(c)
if unicodedata.category(c) in ('Co', 'Cn', 'So'):
out += tpl.format(ord(c), ' ')
elif w > 1 or ord(c) > 255:
out += tpl.format(ord(c), ' ' * w)
else:
out += escape(c)
return out
评论列表
文章目录