Slackify Markdown
A Python library that converts standard Markdown into Slack-compatible formatting (mrkdwn). It addresses the inconsistencies between standard Markdown and Slack's unique syntax, making it easy to display richly-formatted messages in Slack. The library is actively maintained with regular bug fixes and improvements.
Common errors
-
Markdown heading with bold text renders incorrectly in Slack (e.g., `### **Step 1**: Title` results in `**Step 1*: Title*`)
cause A bug in `slackify-markdown` versions prior to `0.2.1` incorrectly processed bold formatting within headings, leading to malformed Slack output.fixUpgrade the library to version `0.2.1` or higher using `pip install --upgrade slackify-markdown`. -
Inconsistent or corrupted Slack output when `slackify_markdown` is used in a multi-threaded application (e.g., different threads produce wrong heading formatting).
cause Versions of `slackify-markdown` prior to `0.2.2` contained a thread-safety bug where a shared class variable for heading state could be corrupted by concurrent calls.fixUpgrade the library to version `0.2.2` or higher using `pip install --upgrade slackify-markdown` to ensure thread-safe operation. -
ModuleNotFoundError: No module named 'slackify_markdown'
cause The `slackify-markdown` library is not installed in the active Python environment or is not accessible on the Python path.fixInstall the library using `pip install slackify-markdown`. If you are in a virtual environment, ensure it is activated before installation.
Warnings
- breaking Formatting of bold text within headings has been fixed in v0.2.1. If your application previously relied on the malformed output (e.g., `**Step 1*: Description*` instead of `*Step 1: Description*`), this change will alter the rendered output.
- gotcha Versions prior to v0.2.2 had a thread-safety issue where internal heading state was shared across instances. This could lead to incorrect output when `slackify_markdown` was called concurrently from multiple threads.
- gotcha Slack's `mrkdwn` is a specific dialect and not fully compatible with standard Markdown. For instance, Slack uses `*bold*` for bold and `_italic_` for italics in some contexts, and `[text](url)` becomes `<url|text>`. This library handles these conversions, but direct use of standard Markdown in Slack without conversion will often break.
Install
-
pip install slackify-markdown
Imports
- slackify_markdown
from slackify_markdown import slackify_markdown
Quickstart
from slackify_markdown import slackify_markdown
markdown_text = """
# Welcome to the **team**!
This is a *test* message with a [link](https://example.com).
- Item 1
- Item 2
```python
print("Hello, Slack!")
```
"""
slack_output = slackify_markdown(markdown_text)
print(slack_output)
# Expected output:
# *Welcome to the team!*
# This is *test* message with a <https://example.com|link>.
# • Item 1
# • Item 2
# ```python\nprint("Hello, Slack!")\n```