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 unmarked

Quick Start

from unmarked 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.0.tar.gz (4.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.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mdclense-0.1.0.tar.gz
  • Upload date:
  • Size: 4.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.0.tar.gz
Algorithm Hash digest
SHA256 864762136f5e4ec7384894c956b8946471fc46d799cadc156a3819582148daa1
MD5 23a4371fc0958c19042f31ee6c76dffb
BLAKE2b-256 1f0a830d9652a1008f50fd719ce6e746a9cc8f29227f5b58a6097f03cc098a14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mdclense-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7edc66dba9a19fe03e7f631300d14d641216198f9e6ba98a6457f37dd170d5f4
MD5 bf3ece03bcab877200e62904b7457042
BLAKE2b-256 079162a52af9a618e4901bebb85e590691621dd57d8696c3f29d544ff716ecd3

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