telegram-markdown-converter


Nametelegram-markdown-converter JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryA Python library for converting Markdown to Telegram-safe MarkdownV2 formatting
upload_time2025-07-19 03:52:34
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords telegram markdown converter formatting markdownv2
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Telegram Markdown Converter

A Python library for converting standard Markdown formatting to Telegram's MarkdownV2 format, with proper escaping of special characters.

[![Python Version](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Tests](https://github.com/ngoldo/telegram-markdown-converter/workflows/Tests/badge.svg)](https://github.com/ngoldo/telegram-markdown-converter/actions)

## Features

- ✅ Convert standard Markdown to Telegram MarkdownV2 format
- ✅ Proper escaping of special characters
- ✅ Preserve code blocks and inline code without modification
- ✅ Handle nested markdown formatting
- ✅ Support for links, bold, italic, strikethrough, underline, and spoiler text
- ✅ Recursive processing of nested markdown structures
- ✅ Type hints for better IDE support

## Installation

### From PyPI (coming soon)

```bash
pip install telegram-markdown-converter
```

### From Source

```bash
git clone https://github.com/ngoldo/telegram-markdown-converter.git
cd telegram-markdown-converter
pip install -e .
```

## Quick Start

```python
from telegram_markdown_converter import convert_markdown

# Basic usage
text = "This is **bold** and *italic* text with a [link](https://example.com)"
converted = convert_markdown(text)
print(converted)  # Output: This is *bold* and _italic_ text with a [link](https://example.com)

# Handle special characters
text = "Special chars: . ! - = + will be escaped"
converted = convert_markdown(text)
print(converted)  # Output: Special chars: \. \! \- \= \+ will be escaped

# Code blocks and inline code are preserved
text = "Here's some `inline code` and a code block:\n```python\nprint('hello')\n```"
converted = convert_markdown(text)
# Code sections remain unchanged
```

## Supported Markdown Elements

| Standard Markdown          | Telegram MarkdownV2        | Description        |
| -------------------------- | -------------------------- | ------------------ |
| `**bold**`                 | `*bold*`                   | Bold text          |
| `*italic*`                 | `_italic_`                 | Italic text        |
| `~~strikethrough~~`        | `~strikethrough~`          | Strikethrough text |
| `__underline__`            | `__underline__`            | Underlined text    |
| `\|\|spoiler\|\|`          | `\|\|spoiler\|\|`          | Spoiler text       |
| `[link](url)`              | `[link](url)`              | Hyperlinks         |
| `` `inline code` ``        | `` `inline code` ``        | Inline code        |
| ```` ```code block``` ```` | ```` ```code block``` ```` | Code blocks        |

## API Reference

### `convert_markdown(text: str) -> str`

Converts standard Markdown text to Telegram MarkdownV2 format.

**Parameters:**
- `text` (str): The input text with standard Markdown formatting

**Returns:**
- `str`: The converted text with Telegram MarkdownV2 formatting and properly escaped special characters

**Example:**
```python
result = convert_markdown("**Hello** *world*!")
# Returns: "*Hello* _world_\\!"
```

## Development

### Setting up the development environment

```bash
git clone https://github.com/ngoldo/telegram-markdown-converter.git
cd telegram-markdown-converter
pip install -e ".[dev]"
```

### Running tests

```bash
pytest
```

### Running tests with coverage

```bash
pytest --cov=telegram_markdown_converter --cov-report=html
```

### Code formatting

```bash
black src/ tests/
isort src/ tests/
```

### Type checking

```bash
mypy src/
```

### Pre-commit hooks

```bash
pre-commit install
pre-commit run --all-files
```

## Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add tests for your changes
5. Ensure all tests pass (`pytest`)
6. Format your code (`black . && isort .`)
7. Commit your changes (`git commit -am 'Add some amazing feature'`)
8. Push to the branch (`git push origin feature/amazing-feature`)
9. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- Built for use with the Telegram Bot API
- Follows Telegram's MarkdownV2 specification
- Inspired by the need for safe markdown formatting in Telegram bots

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "telegram-markdown-converter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "telegram, markdown, converter, formatting, markdownv2",
    "author": null,
    "author_email": "Evan Bulatoff <ngoldo@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/18/f0/b045ab66c214360594eb1d750eb519f5af14fa04ff52874a2c0a9da7a108/telegram_markdown_converter-1.0.1.tar.gz",
    "platform": null,
    "description": "# Telegram Markdown Converter\n\nA Python library for converting standard Markdown formatting to Telegram's MarkdownV2 format, with proper escaping of special characters.\n\n[![Python Version](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Tests](https://github.com/ngoldo/telegram-markdown-converter/workflows/Tests/badge.svg)](https://github.com/ngoldo/telegram-markdown-converter/actions)\n\n## Features\n\n- \u2705 Convert standard Markdown to Telegram MarkdownV2 format\n- \u2705 Proper escaping of special characters\n- \u2705 Preserve code blocks and inline code without modification\n- \u2705 Handle nested markdown formatting\n- \u2705 Support for links, bold, italic, strikethrough, underline, and spoiler text\n- \u2705 Recursive processing of nested markdown structures\n- \u2705 Type hints for better IDE support\n\n## Installation\n\n### From PyPI (coming soon)\n\n```bash\npip install telegram-markdown-converter\n```\n\n### From Source\n\n```bash\ngit clone https://github.com/ngoldo/telegram-markdown-converter.git\ncd telegram-markdown-converter\npip install -e .\n```\n\n## Quick Start\n\n```python\nfrom telegram_markdown_converter import convert_markdown\n\n# Basic usage\ntext = \"This is **bold** and *italic* text with a [link](https://example.com)\"\nconverted = convert_markdown(text)\nprint(converted)  # Output: This is *bold* and _italic_ text with a [link](https://example.com)\n\n# Handle special characters\ntext = \"Special chars: . ! - = + will be escaped\"\nconverted = convert_markdown(text)\nprint(converted)  # Output: Special chars: \\. \\! \\- \\= \\+ will be escaped\n\n# Code blocks and inline code are preserved\ntext = \"Here's some `inline code` and a code block:\\n```python\\nprint('hello')\\n```\"\nconverted = convert_markdown(text)\n# Code sections remain unchanged\n```\n\n## Supported Markdown Elements\n\n| Standard Markdown          | Telegram MarkdownV2        | Description        |\n| -------------------------- | -------------------------- | ------------------ |\n| `**bold**`                 | `*bold*`                   | Bold text          |\n| `*italic*`                 | `_italic_`                 | Italic text        |\n| `~~strikethrough~~`        | `~strikethrough~`          | Strikethrough text |\n| `__underline__`            | `__underline__`            | Underlined text    |\n| `\\|\\|spoiler\\|\\|`          | `\\|\\|spoiler\\|\\|`          | Spoiler text       |\n| `[link](url)`              | `[link](url)`              | Hyperlinks         |\n| `` `inline code` ``        | `` `inline code` ``        | Inline code        |\n| ```` ```code block``` ```` | ```` ```code block``` ```` | Code blocks        |\n\n## API Reference\n\n### `convert_markdown(text: str) -> str`\n\nConverts standard Markdown text to Telegram MarkdownV2 format.\n\n**Parameters:**\n- `text` (str): The input text with standard Markdown formatting\n\n**Returns:**\n- `str`: The converted text with Telegram MarkdownV2 formatting and properly escaped special characters\n\n**Example:**\n```python\nresult = convert_markdown(\"**Hello** *world*!\")\n# Returns: \"*Hello* _world_\\\\!\"\n```\n\n## Development\n\n### Setting up the development environment\n\n```bash\ngit clone https://github.com/ngoldo/telegram-markdown-converter.git\ncd telegram-markdown-converter\npip install -e \".[dev]\"\n```\n\n### Running tests\n\n```bash\npytest\n```\n\n### Running tests with coverage\n\n```bash\npytest --cov=telegram_markdown_converter --cov-report=html\n```\n\n### Code formatting\n\n```bash\nblack src/ tests/\nisort src/ tests/\n```\n\n### Type checking\n\n```bash\nmypy src/\n```\n\n### Pre-commit hooks\n\n```bash\npre-commit install\npre-commit run --all-files\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Make your changes\n4. Add tests for your changes\n5. Ensure all tests pass (`pytest`)\n6. Format your code (`black . && isort .`)\n7. Commit your changes (`git commit -am 'Add some amazing feature'`)\n8. Push to the branch (`git push origin feature/amazing-feature`)\n9. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- Built for use with the Telegram Bot API\n- Follows Telegram's MarkdownV2 specification\n- Inspired by the need for safe markdown formatting in Telegram bots\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library for converting Markdown to Telegram-safe MarkdownV2 formatting",
    "version": "1.0.1",
    "project_urls": {
        "Documentation": "https://github.com/ngoldo/telegram-markdown-converter#readme",
        "Homepage": "https://github.com/ngoldo/telegram-markdown-converter",
        "Issues": "https://github.com/ngoldo/telegram-markdown-converter/issues",
        "Repository": "https://github.com/ngoldo/telegram-markdown-converter"
    },
    "split_keywords": [
        "telegram",
        " markdown",
        " converter",
        " formatting",
        " markdownv2"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b80620291b5da38334cdef55b0c8533e8ae6831473b86c3c706f1e0a0102958f",
                "md5": "fda7577d2315ea8281f20713455bd90a",
                "sha256": "c8c355fd6a23d0e56c9e19f7aa36d5ccb80fff3e8bae1481ec4a3197b2446434"
            },
            "downloads": -1,
            "filename": "telegram_markdown_converter-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fda7577d2315ea8281f20713455bd90a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6236,
            "upload_time": "2025-07-19T03:52:32",
            "upload_time_iso_8601": "2025-07-19T03:52:32.848503Z",
            "url": "https://files.pythonhosted.org/packages/b8/06/20291b5da38334cdef55b0c8533e8ae6831473b86c3c706f1e0a0102958f/telegram_markdown_converter-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "18f0b045ab66c214360594eb1d750eb519f5af14fa04ff52874a2c0a9da7a108",
                "md5": "bb68e710a1bd44d3aed81df324edca23",
                "sha256": "23d10f972193abfbf4c7dfc093e7644c1105e21500d916211eb19b6318c4f309"
            },
            "downloads": -1,
            "filename": "telegram_markdown_converter-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bb68e710a1bd44d3aed81df324edca23",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 11555,
            "upload_time": "2025-07-19T03:52:34",
            "upload_time_iso_8601": "2025-07-19T03:52:34.097694Z",
            "url": "https://files.pythonhosted.org/packages/18/f0/b045ab66c214360594eb1d750eb519f5af14fa04ff52874a2c0a9da7a108/telegram_markdown_converter-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-19 03:52:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ngoldo",
    "github_project": "telegram-markdown-converter#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "telegram-markdown-converter"
}
        
Elapsed time: 0.49953s