README.md
1# html2text
2
3[![Build Status](https://secure.travis-ci.org/Alir3z4/html2text.png)](https://travis-ci.org/Alir3z4/html2text)
4[![Coverage Status](https://coveralls.io/repos/Alir3z4/html2text/badge.png)](https://coveralls.io/r/Alir3z4/html2text)
5[![Downloads](http://badge.kloud51.com/pypi/d/html2text.png)](https://pypi.org/project/html2text/)
6[![Version](http://badge.kloud51.com/pypi/v/html2text.png)](https://pypi.org/project/html2text/)
7[![Wheel?](http://badge.kloud51.com/pypi/wheel/html2text.png)](https://pypi.org/project/html2text/)
8[![Format](http://badge.kloud51.com/pypi/format/html2text.png)](https://pypi.org/project/html2text/)
9[![License](http://badge.kloud51.com/pypi/license/html2text.png)](https://pypi.org/project/html2text/)
10
11
12html2text 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).
13
14
15Usage: `html2text [filename [encoding]]`
16
17| Option | Description
18|--------------------------------------------------------|---------------------------------------------------
19| `--version` | Show program's version number and exit
20| `-h`, `--help` | Show this help message and exit
21| `--ignore-links` | Don't include any formatting for links
22|`--escape-all` | Escape all special characters. Output is less readable, but avoids corner case formatting issues.
23| `--reference-links` | Use reference links instead of links to create markdown
24| `--mark-code` | Mark preformatted and code blocks with [code]...[/code]
25
26For a complete list of options see the [docs](https://github.com/Alir3z4/html2text/blob/master/docs/usage.md)
27
28
29Or you can use it from within `Python`:
30
31```
32>>> import html2text
33>>>
34>>> print(html2text.html2text("<p><strong>Zed's</strong> dead baby, <em>Zed's</em> dead.</p>"))
35**Zed's** dead baby, _Zed's_ dead.
36
37```
38
39
40Or with some configuration options:
41```
42>>> import html2text
43>>>
44>>> h = html2text.HTML2Text()
45>>> # Ignore converting links from HTML
46>>> h.ignore_links = True
47>>> print h.handle("<p>Hello, <a href='https://www.google.com/earth/'>world</a>!")
48Hello, world!
49
50>>> print(h.handle("<p>Hello, <a href='https://www.google.com/earth/'>world</a>!"))
51
52Hello, world!
53
54>>> # Don't Ignore links anymore, I like links
55>>> h.ignore_links = False
56>>> print(h.handle("<p>Hello, <a href='https://www.google.com/earth/'>world</a>!"))
57Hello, [world](https://www.google.com/earth/)!
58
59```
60
61*Originally written by Aaron Swartz. This code is distributed under the GPLv3.*
62
63
64## How to install
65
66`html2text` is available on pypi
67https://pypi.org/project/html2text/
68
69```
70$ pip install html2text
71```
72
73
74## How to run unit tests
75
76 tox
77
78To see the coverage results:
79
80 coverage html
81
82then open the `./htmlcov/index.html` file in your browser.
83
84## Documentation
85
86Documentation lives [here](https://github.com/Alir3z4/html2text/blob/master/docs/usage.md)
87