Skip to main content

A library for cleaning, stripping markdown and converting it to text

Project description

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

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

mdclense-0.1.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdclense-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mdclense-0.1.2.tar.gz.

File metadata

  • Download URL: mdclense-0.1.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for mdclense-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e8464f17bde450cff66aba64d5391f146432e293434619e7798fb7166e33a515
MD5 80f7964224a3ee544791054277ccdb00
BLAKE2b-256 b27e0f7547766716534a8ed484f0509f1f296d7b820e352642e3412ead030acc

See more details on using hashes here.

File details

Details for the file mdclense-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mdclense-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for mdclense-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 41c9c45a099478424b866b3c1a23c51397a4d135f0dce019c9128bbb4f4fb987
MD5 80965a5ed7e702b388c1f25e43cddf21
BLAKE2b-256 9171dd6769438749c63b7b2cd09e4374e0be6e9a0752a4850d7d8b51ef9c879b

See more details on using hashes here.

Supported by

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