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

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

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

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

Analyzed by OSRepos on July 25, 2026

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

Related repositories

Similar repositories that may be relevant next.

Notes: A Fast and Beautiful Cross-Platform Note-Taking App

Notes: A Fast and Beautiful Cross-Platform Note-Taking App

June 18, 2026

Notes is an open-source, cross-platform note-taking application designed for speed and beauty. Written in C++ with Qt, it offers robust features like Markdown support, Kanban boards for tasks, and comprehensive organization options. This app prioritizes user privacy, ensuring a secure and efficient environment for capturing your thoughts.

note-taking-appcross-platformmarkdown
Sphinx: The Intelligent Documentation Generator for Python Projects

Sphinx: The Intelligent Documentation Generator for Python Projects

February 6, 2026

Sphinx is a powerful documentation generator that simplifies the creation of intelligent and beautiful documentation. It leverages reStructuredText as its markup language and offers extensive features for various output formats, cross-references, and an active extension ecosystem. Widely used, it provides a robust solution for technical writing needs across multiple programming languages.

documentationpythonrestructuredtext
markdown-to-image: Render Markdown into Beautiful Poster Images

markdown-to-image: Render Markdown into Beautiful Poster Images

December 3, 2025

markdown-to-image is a versatile React component designed to transform Markdown content into visually appealing poster images. It supports various social media formats and offers features like customizable themes and one-click deployment for a web editor. This tool is ideal for creating shareable content from plain Markdown.

markdownimage generationReact component
Streamdown: A React-Markdown Replacement for AI Streaming

Streamdown: A React-Markdown Replacement for AI Streaming

November 28, 2025

Streamdown is an innovative library from Vercel, designed as a drop-in replacement for `react-markdown`. It is specifically engineered to handle AI-powered streaming scenarios, providing efficient and robust markdown parsing for dynamic content generation. This tool is ideal for developers building applications that require real-time markdown rendering from AI outputs.

aimarkdownstreaming

Source repository

Open the original repository on GitHub.

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️