{"id":16738253,"url":"https://github.com/tonyseek/html5lib-truncation","last_synced_at":"2025-04-10T12:53:18.299Z","repository":{"id":28458911,"uuid":"31974593","full_name":"tonyseek/html5lib-truncation","owner":"tonyseek","description":"Truncating HTML with html5lib filter","archived":false,"fork":false,"pushed_at":"2017-09-30T10:51:01.000Z","size":10,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T11:38:37.813Z","etag":null,"topics":["html","python","text-processing"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tonyseek.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-10T18:31:19.000Z","updated_at":"2020-03-17T08:18:30.000Z","dependencies_parsed_at":"2022-09-15T11:00:41.401Z","dependency_job_id":null,"html_url":"https://github.com/tonyseek/html5lib-truncation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyseek%2Fhtml5lib-truncation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyseek%2Fhtml5lib-truncation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyseek%2Fhtml5lib-truncation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyseek%2Fhtml5lib-truncation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tonyseek","download_url":"https://codeload.github.com/tonyseek/html5lib-truncation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247896477,"owners_count":21014520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","python","text-processing"],"created_at":"2024-10-13T00:29:50.760Z","updated_at":"2025-04-10T12:53:18.274Z","avatar_url":"https://github.com/tonyseek.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"|Build Status| |Coverage Status| |PyPI Version| |Wheel Status|\n\nhtml5lib-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    \u003e\u003e\u003e from html5lib_truncation import truncate_html\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e html = u'\u003cp\u003eA \u003ca href=\"#\"\u003every very long link\u003c/a\u003e\u003c/p\u003e'\n    \u003e\u003e\u003e truncate_html(html, 8)\n    u'\u003cp\u003eA \u003ca href=#\u003every\u003c/a\u003e'\n    \u003e\u003e\u003e truncate_html(html, 8, break_words=True)\n    u'\u003cp\u003eA \u003ca href=#\u003every ve\u003c/a\u003e'\n    \u003e\u003e\u003e truncate_html(html, 20, end='...')\n    u'\u003cp\u003eA \u003ca href=#\u003every very...\u003c/a\u003e'\n    \u003e\u003e\u003e truncate_html(html, 20, end='...', break_words=True)\n    u'\u003cp\u003eA \u003ca href=#\u003every very lon...\u003c/a\u003e'\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'\u003cp\u003eA \u003ca href=\"#\"\u003every very long link\u003c/a\u003e\u003c/p\u003e')\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 ``\u003cp\u003eA \u003ca href=#\u003every very lon...\u003c/a\u003e``.\n\n\nIssues\n------\n\nIf you want to report bugs or other issues, please create issues on\n`GitHub Issues \u003chttps://github.com/tonyseek/html5lib-truncation/issues\u003e`_.\n\n\nContributes\n-----------\n\nYou can send a pull reueqst on\n`GitHub \u003chttps://github.com/tonyseek/html5lib-truncation/pulls\u003e`_.\n\n.. |Build Status| image:: https://img.shields.io/travis/tonyseek/html5lib-truncation.svg?style=flat\n   :target: https://travis-ci.org/tonyseek/html5lib-truncation\n   :alt: Build Status\n.. |Coverage Status| image:: https://img.shields.io/coveralls/tonyseek/html5lib-truncation.svg?style=flat\n   :target: https://coveralls.io/r/tonyseek/html5lib-truncation\n   :alt: Coverage Status\n.. |Wheel Status| image:: https://img.shields.io/pypi/wheel/html5lib-truncation.svg?style=flat\n   :target: https://warehouse.python.org/project/html5lib-truncation\n   :alt: Wheel Status\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/html5lib-truncation.svg?style=flat\n   :target: https://pypi.python.org/pypi/html5lib-truncation\n   :alt: PyPI Version\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonyseek%2Fhtml5lib-truncation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftonyseek%2Fhtml5lib-truncation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonyseek%2Fhtml5lib-truncation/lists"}