# Telegram Markdown Converter
A Python library for converting standard Markdown formatting to Telegram's MarkdownV2 format, with proper escaping of special characters.
[](https://www.python.org/downloads/)
[](https://opensource.org/licenses/MIT)
[](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 |
| `***bold italic***` | `*\_bold italic\_*` | Bold and Italic text |
| `*italic*`/`_italic_` | `_italic_` | Italic text |
| `~~strikethrough~~`/`~strikethrough~` | `~strikethrough~` | Strikethrough text |
| `__underline__` | `__underline__` | Underlined text |
| `\|\|spoiler\|\|` | `\|\|spoiler\|\|` | Spoiler text |
| `> blockquote` | `>blockquote` | Blockquotes |
| `[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 Boulatoff <ngoldo@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/aa/0c/5ee319a7ef01565e09f05413ae8da546a2c3deddbb1e4521521fd4e55782/telegram_markdown_converter-1.0.5.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[](https://www.python.org/downloads/)\n[](https://opensource.org/licenses/MIT)\n[](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| `***bold italic***` | `*\\_bold italic\\_*` | Bold and Italic text |\n| `*italic*`/`_italic_` | `_italic_` | Italic text |\n| `~~strikethrough~~`/`~strikethrough~` | `~strikethrough~` | Strikethrough text |\n| `__underline__` | `__underline__` | Underlined text |\n| `\\|\\|spoiler\\|\\|` | `\\|\\|spoiler\\|\\|` | Spoiler text |\n| `> blockquote` | `>blockquote` | Blockquotes |\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.5",
"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": "0f584472197179d67ae7c60a31084b8c6ed373fd23574aa124f3547431b2c439",
"md5": "8a627a1662bdf4624b5f44420bd2166b",
"sha256": "5c4318fcadc5f6935abeb2098174ac7fc0c53f149731e6a72942c812d7c1bb7f"
},
"downloads": -1,
"filename": "telegram_markdown_converter-1.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8a627a1662bdf4624b5f44420bd2166b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 8073,
"upload_time": "2025-08-04T21:36:36",
"upload_time_iso_8601": "2025-08-04T21:36:36.535320Z",
"url": "https://files.pythonhosted.org/packages/0f/58/4472197179d67ae7c60a31084b8c6ed373fd23574aa124f3547431b2c439/telegram_markdown_converter-1.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "aa0c5ee319a7ef01565e09f05413ae8da546a2c3deddbb1e4521521fd4e55782",
"md5": "046a924e7f327beb1293db64c4eb20d7",
"sha256": "c06f41bcfc5ea86219283e3bce1b9998ff06e6eb718446ed2234b683491030c5"
},
"downloads": -1,
"filename": "telegram_markdown_converter-1.0.5.tar.gz",
"has_sig": false,
"md5_digest": "046a924e7f327beb1293db64c4eb20d7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 15096,
"upload_time": "2025-08-04T21:36:37",
"upload_time_iso_8601": "2025-08-04T21:36:37.494802Z",
"url": "https://files.pythonhosted.org/packages/aa/0c/5ee319a7ef01565e09f05413ae8da546a2c3deddbb1e4521521fd4e55782/telegram_markdown_converter-1.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-04 21:36:37",
"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"
}