Markdown to Slack Mrkdwn Converter
A lightweight, efficient Python library (current version 0.3.2) for converting standard Markdown to Slack's custom mrkdwn format. It helps maintain consistent formatting when sending messages to Slack from applications. The library features comprehensive support for various Markdown elements and includes a plugin system for extended functionality. It has a moderate release cadence, with several minor releases and bug fixes in the past year.
Warnings
- breaking The minimum required Python version has been updated from Python 3.6 to Python 3.8. Users on Python 3.6 or 3.7 will need to upgrade their Python environment to use versions 0.3.x and newer.
- gotcha Slack's 'mrkdwn' is a custom formatting syntax and is not identical to standard Markdown. While this library performs a conversion, some Markdown features (like multiple header levels beyond bolding, or complex tables) may be represented differently or have limitations due to mrkdwn's capabilities. Always test converted output in Slack's Block Kit Builder.
- gotcha The plugin system, introduced in v0.2.0, allows for custom conversion logic. While powerful, incorrectly implemented plugins can lead to unexpected or erroneous output. Ensure custom plugins are thoroughly tested for edge cases.
Install
-
pip install markdown-to-mrkdwn
Imports
- SlackMarkdownConverter
from markdown_to_mrkdwn import SlackMarkdownConverter
Quickstart
from markdown_to_mrkdwn import SlackMarkdownConverter
converter = SlackMarkdownConverter()
markdown_text = """
# Heading 1
**Bold text**
- List item
[Link](https://example.com)
~~Strikethrough text~~
```python
print("Hello, Slack!")
```
"""
mrkdwn_text = converter.convert(markdown_text)
print(mrkdwn_text)
# Expected output in Slack's mrkdwn format (approximately):
# *Heading 1*
# *Bold text*
# • List item
# <https://example.com|Link>
# ~Strikethrough text~
# ```python
# print("Hello, Slack!")
# ```