python convert text to html entities

from htmlentitydefs import codepoint2name

def htmlentities(u):
    result = []
    for c in u:
        if ord(c) < 128:
            result.append(c)
        else:
            result.append('&%s;' % codepoint2name[ord(c)])
    return ''.join(result)

0 Comments

Post A Comment