html2text 0,0 travis-ci python

Convert HTML to Markdown-formatted text.


Build Status Coverage Status Downloads Version Wheel? Format License

html2text is a Python script that converts a page of HTML into clean, easy-to-read plain ASCII text. Better yet, that ASCII also happens to be valid Markdown (a text-to-HTML format).

Usage: html2text [(filename|url) [encoding]]

Option Description
--version Show program’s version number and exit
-h, --help Show this help message and exit
--ignore-links Don’t include any formatting for links
--escape-all Escape all special characters. Output is less readable, but avoids corner case formatting issues.
--reference-links Use reference links instead of links to create markdown
--mark-code Mark preformatted and code blocks with [code]…[/code]

For a complete list of options see the docs

Or you can use it from within Python:

>>> import html2text
>>> print(html2text.html2text("<p><strong>Zed's</strong> dead baby, <em>Zed's</em> dead.</p>"))
**Zed's** dead baby, _Zed's_ dead.

Or with some configuration options:

>>> import html2text
>>> h = html2text.HTML2Text()
>>> # Ignore converting links from HTML
>>> h.ignore_links = True
>>> print h.handle("<p>Hello, <a href=''>world</a>!")
Hello, world!

>>> print(h.handle("<p>Hello, <a href=''>world</a>!"))

Hello, world!

>>> # Don't Ignore links anymore, I like links
>>> h.ignore_links = False
>>> print(h.handle("<p>Hello, <a href=''>world</a>!"))
Hello, [world](!

Originally written by Aaron Swartz. This code is distributed under the GPLv3.

How to install

html2text is available on pypi

$ pip install html2text

How to run unit tests

PYTHONPATH=$PYTHONPATH:. coverage run --source=html2text test -v

To see the coverage results:

coverage combine
coverage html

then open the ./htmlcov/index.html file in your browser.


Documentation lives here

Related Repositories



Convert HTML to Markdown-formatted text. ...



Zhihu UNOFFICIAL API library in python3, with help of bs4, lxml, requests and html2text. ...



Convert HTML to Markdown-formatted text. ...



PHP library to convert HTML to formatted plain text ...



A PHP component to convert HTML into a plain text format ...

Top Contributors

Alir3z4 theSage21 aaronsw nushoin dreikanter mcepl stefanor mdorn ZumZoom stephenmcd brondsem JocelynDelalande abgoyal adhiraj eevee IanLewis summerisgone mgontav smblackburn szepeviktor wking ap lovemyliwu emfree alawibaba amitu brutasse blueyed dvj Savageman


-   2016.9.19 zip tar
-   2016.5.29 zip tar
-   2016.4.2 zip tar
-   2016.1.8 zip tar
-   2015.11.4 zip tar
-   2015.6.21 zip tar
-   2015.6.12 zip tar
-   2015.6.6 zip tar
-   2015.4.14 zip tar
-   2015.4.13 zip tar
-   2015.2.18 zip tar
-   2014.12.29 zip tar
-   2014.12.24 zip tar
-   2014.12.5 zip tar
-   2014.9.25 zip tar
-   2014.9.8 zip tar
-   2014.9.7 zip tar
-   2014.7.3 zip tar
-   2014.4.5 zip tar
-   3.02 zip tar
-   3.01 zip tar