Skip to main content

Turn HTML into equivalent Markdown-structured text.

Project description

html2text

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 [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='https://www.google.com/earth/'>world</a>!")
Hello, world!

>>> print(h.handle("<p>Hello, <a href='https://www.google.com/earth/'>world</a>!"))

Hello, world!

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

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

How to install

html2text is available on pypi https://pypi.org/project/html2text/

$ pip install html2text

How to run unit tests

tox

To see the coverage results:

coverage html

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

Documentation

Documentation lives here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

html2text_no_md_escapes-2020.1.16.tar.gz (52.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file html2text_no_md_escapes-2020.1.16.tar.gz.

File metadata

  • Download URL: html2text_no_md_escapes-2020.1.16.tar.gz
  • Upload date:
  • Size: 52.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for html2text_no_md_escapes-2020.1.16.tar.gz
Algorithm Hash digest
SHA256 1ac3a6241be2253d782a60fc59dab1faf812b02dd758142c83db8cc216489ca4
MD5 72952a8d4c2926c95ee2d8f6fb814d8c
BLAKE2b-256 7542718484848886f39ba44b7182601348af5816b890b0e78008a68182bf0233

See more details on using hashes here.

File details

Details for the file html2text_no_md_escapes-2020.1.16-py3-none-any.whl.

File metadata

  • Download URL: html2text_no_md_escapes-2020.1.16-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for html2text_no_md_escapes-2020.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 4496acba29af42d028637efdb1840556cca0008f3e4e42f02dd1e0ed16ab6f90
MD5 ae96739d3ae86f5d3bdc5d049be582e6
BLAKE2b-256 33088cd030e1393c09c9399ca84075d99b2691a14d51512e9ad4f6563b521a57

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page