{ "info": { "author": "Jiangge Zhang", "author_email": "tonyseek@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "html5lib-truncation\n===================\n\n``html5lib-truncation`` is a html5lib_ filter implementation, which can\ntruncate HTML to specific length in display, but never breaks HTML tags.\n\nThere is a shortcut function, the simplest way to use it:\n\n.. code-block:: python\n\n >>> from html5lib_truncation import truncate_html\n >>>\n >>> html = u'
'\n >>> truncate_html(html, 8)\n u'A very'\n >>> truncate_html(html, 8, break_words=True)\n u'
A very ve'\n >>> truncate_html(html, 20, end='...')\n u'
A very very...'\n >>> truncate_html(html, 20, end='...', break_words=True)\n u'
A very very lon...'\n\n\n.. _html5lib: https://github.com/html5lib/html5lib-python\n\n\nInstallation\n------------\n\n::\n\n pip install html5lib-truncation\n\nDon't forget to put it into your ``requirements.txt`` or ``setup.py``.\n\n\nAPI Overview\n------------\n\nThe core API of html5lib-truncation is the filter:\n\n.. code-block:: python\n\n import html5lib\n from html5lib_truncation import TruncationFilter\n\n etree = html5lib.parse(u'
')\n walker = html5lib.getTreeWalker('etree')\n\n stream = walker(etree)\n stream = TruncationFilter(stream, 20, end='...', break_words=True)\n\n serializer = html5lib.serializer.HTMLSerializer()\n serialized = serializer.serialize(stream)\n\n print(u''.join(serialized).strip())\n\nThe output is ``A very very lon...``.\n\n\nIssues\n------\n\nIf you want to report bugs or other issues, please create issues on\n`GitHub Issues