r""" htmlize(): generic function example # BEGIN HTMLIZE_DEMO >>> htmlize({1, 2, 3}) # <1> '
{1, 2, 3}'
>>> htmlize(abs)
'<built-in function abs>' >>> htmlize('Heimlich & Co.\n- a game') # <2> '
Heimlich & Co.
\n- a game
42 (0x2a)' >>> print(htmlize(['alpha', 66, {3, 2, 1}])) # <4>
alpha
66 (0x42)
{1, 2, 3}{}'.format(content)
@htmlize.register(str) # <2>
def _(text): # <3>
content = html.escape(text).replace('\n', '{0}
'.format(content) @htmlize.register(numbers.Integral) # <4> def _(n): return '{0} (0x{0:x})'.format(n)
@htmlize.register(tuple) # <5>
@htmlize.register(abc.MutableSequence)
def _(seq):
inner = '\n