html2text: Convert HTML to Clean, Readable Markdown Text in Python
This repository profile is provided by osrepos.com, an open source repository discovery platform.
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.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
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.
$ 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.
Python Usage
You can integrate html2text directly into your Python code:
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:
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
- PyPI Project: https://pypi.org/project/html2text/
- Documentation: https://github.com/Alir3z4/html2text/blob/master/docs/usage.md
Related repositories
Similar repositories that may be relevant next.

Mistune: A Fast and Powerful Python Markdown Parser
August 30, 2026
Mistune is a high-performance Python library designed for parsing Markdown into HTML. It offers a fast and powerful solution for developers needing to convert Markdown text, featuring extensive support for renderers and plugins to customize the parsing process. This makes it a versatile tool for various web development and content processing needs.

Python-Markdown: A Versatile Python Implementation for Markdown to HTML Conversion
August 30, 2026
Python-Markdown is a robust Python implementation of John Gruber's Markdown, offering extensive support for standard Markdown syntax. It stands out with its powerful extension system, allowing users to add custom features and modify existing behaviors. This makes it a versatile tool for converting Markdown text into HTML within Python applications and documentation.

MkDocs: Fast and Simple Static Site Generator for Project Documentation
August 29, 2026
MkDocs is a fast, simple, and visually appealing static site generator designed for building project documentation. It allows users to write documentation source files in Markdown, configured via a single YAML file. This tool is highly extensible with third-party themes, plugins, and Markdown extensions, making it a versatile choice for various documentation needs.

Nikola: A Powerful Static Website and Blog Generator
August 6, 2026
Nikola is an open-source static website and blog generator written in Python. It transforms content into a deployable website, offering a secure and resource-efficient alternative to dynamic sites. With features like theming, fast builds, and multilingual support, Nikola is a versatile tool for web development.
Source repository
Open the original repository on GitHub.
14 counted GitHub visits