Skip to main content

mdclense

A lightweight, efficient Python library for converting Markdown to plain text. mdclense strips away all Markdown formatting while preserving the original content, making it perfect for text analysis, content extraction, and data processing pipelines.

Features

  • Comprehensive Markdown support
  • Preserves content while removing formatting
  • Handles complex nested structures
  • Clean whitespace management
  • JSON-like structure support
  • Zero dependencies beyond Python standard library

Supported Markdown Elements

  • Headers (ATX and Setext style)
  • Emphasis (bold, italic, bold-italic)
  • Links and images
  • Lists (ordered, unordered, and task lists)
  • Code blocks and inline code
  • Blockquotes
  • Tables
  • Horizontal rules
  • HTML tags
  • Strikethrough
  • Footnotes
  • Escaped characters

Installation

pip install mdclense

Quick Start

from mdclense.parser import MarkdownParser


# Create a parser instance
parser = MarkdownParser()

# Convert markdown to plain text
markdown_text = """
# Hello World

This is a **bold** and *italic* text with a [link](http://example.com).

- List item 1
- List item 2
"""

plain_text = parser.parse(markdown_text)
print(plain_text)

Output:

Hello World

This is a bold and italic text with a link.

List item 1
List item 2

Advanced Usage

Handling JSON-like Structures

# Parse markdown content from JSON-like structure
json_text = '"answer": "This is **bold** text with a [link](url)"'
plain_text = parser.parse(json_text)
print(plain_text)  # Output: This is bold text with a link

Working with Code Blocks

markdown_text = '''
Here's some code:

```python
def hello():
    print("world")

'''

plain_text = parser.parse(markdown_text) print(plain_text) # Code blocks are replaced with [CODE BLOCK] placeholder


## API Reference

### MarkdownParser Class

```python
class MarkdownParser:
    def parse(markdown_text: str) -> str:
        """
        Convert markdown text to plain text by removing all markdown formatting.

        Args:
            markdown_text (str): The markdown text to be converted

        Returns:
            str: Plain text without markdown formatting
        """

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Testing

# Install development dependencies
pip install pytest

# Run tests
pytest tests/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Inspired by the need for a simple, dependency-free Markdown to plain text converter
  • Thanks to all contributors who have helped shape this project

Metadata

Release files for mdclense 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdclense 0.1.2
File Size Uploaded
mdclense-0.1.2.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mdclense 0.1.2
File Interpreter ABI Platform
mdclense-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / mdclense-0.1.2.tar.gz

Download URL mdclense-0.1.2.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e8464f17bde450cff66aba64d5391f146432e293434619e7798fb7166e33a515
BLAKE2b-256 checksum
How to use checksums
b27e0f7547766716534a8ed484f0509f1f296d7b820e352642e3412ead030acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / mdclense-0.1.2-py3-none-any.whl

Download URL mdclense-0.1.2-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41c9c45a099478424b866b3c1a23c51397a4d135f0dce019c9128bbb4f4fb987
BLAKE2b-256 checksum
How to use checksums
9171dd6769438749c63b7b2cd09e4374e0be6e9a0752a4850d7d8b51ef9c879b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page