# html2text: Convert HTML to Clean, Readable Markdown Text in Python

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Source: osrepos.com
Repository profile: https://osrepos.com/repo/alir3z4-html2text
Generated for open source discovery and AI-assisted research.

html2text is a powerful Python script designed to transform HTML content into clean, easy-to-read plain ASCII text, formatted as valid Markdown. This tool is ideal for developers needing to process web content or convert rich text into a more manageable, structured plain text format. It offers both command-line utility and a flexible Python API for integration into projects.

GitHub: https://github.com/Alir3z4/html2text
OSRepos URL: https://osrepos.com/repo/alir3z4-html2text

## Summary

html2text is a powerful Python script designed to transform HTML content into clean, easy-to-read plain ASCII text, formatted as valid Markdown. This tool is ideal for developers needing to process web content or convert rich text into a more manageable, structured plain text format. It offers both command-line utility and a flexible Python API for integration into projects.

## Topics

- markdown
- markdown-parser
- python
- html conversion
- text processing
- command-line tool
- developer tools

## Repository Information

Last analyzed by OSRepos: Sat Jul 25 2026 21:41:18 GMT+0100 (Western European Summer Time)
Detail views: 0
GitHub clicks: 1

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## Introduction
`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 popular text-to-HTML format. Originally written by Aaron Swartz, this tool provides a robust solution for transforming complex HTML structures into simple, readable Markdown.

## Installation
You can easily install `html2text` using pip, as it is available on PyPI.

shell
$ pip install html2text


## Examples
`html2text` can be used both as a command-line tool and within your Python applications.

### Command-line Usage
Here are some common options for command-line usage:

*   `--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 inline links to create markdown.
*   `--mark-code`: Mark preformatted and code blocks with `[code]...[/code]`.

For a complete list of options, refer to the [official documentation](https://github.com/Alir3z4/html2text/blob/master/docs/usage.md).

### Python Usage
You can integrate `html2text` directly into your Python code:

python
import html2text

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


You can also configure its behavior with specific options:

python
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>!</p>"))
# Expected output: Hello, world!

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


## Why Use It?
Converting HTML to Markdown offers several advantages. Markdown is lightweight, human-readable, and easy to write, making it ideal for documentation, content management, and plain text storage. `html2text` automates this conversion, preserving formatting like bold, italics, and links while stripping away the complexities of HTML tags, resulting in clean and portable text. This is particularly useful for data scraping, content migration, or generating reports from web pages.

## Links
*   **GitHub Repository**: [https://github.com/Alir3z4/html2text](https://github.com/Alir3z4/html2text)
*   **PyPI Project**: [https://pypi.org/project/html2text/](https://pypi.org/project/html2text/)
*   **Documentation**: [https://github.com/Alir3z4/html2text/blob/master/docs/usage.md](https://github.com/Alir3z4/html2text/blob/master/docs/usage.md)