def truncate_html(html, *args, **kwargs):
if hasattr(html, '<STR_LIT>'):<EOL><INDENT>etree = html<EOL><DEDENT>else:<EOL><INDENT>etree = html5lib.parse(html)<EOL><DEDENT>walker = html5lib.getTreeWalker('<STR_LIT>')<EOL>stream = walker(etree)<EOL>stream = TruncationFilter(stream, *args, **kwargs)<EOL>serializer = html5lib.serializer.HTMLSerializer()<EOL>serialized = serializer.serialize(stream)<EOL>return u'<STR_LIT>'.join(serialized).strip()<EOL>
Truncates HTML string.

    :param html: The HTML string or parsed element tree (with
                 :func:`html5lib.parse`).
    :param kwargs: Similar with :class:`.filters.TruncationFilter`.

    :return: The truncated HTML string.