Convert Markdown to Slack blocks - useful for chatbots
Project description
Mistune Slack Renderer
Convert Markdown into Slack Block Kit format using Mistune. Useful for LLM-powered chatbots!
Kitchen sink demo
- View Kitchen Sink Markdown: test/testdata/kitchen_sink.md.txt
- View Output in Block Kit Builder: https://app.slack.com/block-kit-builder/#...
Features
- Produces Slack Block Kit JSON for posting messages to Slack
- Renders Slack users, channels, broadcasts, and emojis
- Supports strikethrough, task lists, URLs, and code blocks
- Headings, paragraphs, block quotes, and dividers
- Ordered and bullet lists (with nesting and task-list support)
- Inline code and fenced code-block rendering
- Link conversion into Slack link elements
- Note: images not supported. It should be easy to add by subclassing
mistune_slack.renderer.SlackRendererand adding your own logic (such as you may want to upload the image somewhere as well)
Install
uv add mistune-slack
Usage
from mistune_slack import render_slack_blocks_from_markdown
markdown = "# Hello, *world*!"
blocks = render_slack_blocks_from_markdown(markdown)
print(blocks) # post `blocks` to Slack
Advanced usage
import mistune
from mistune.plugins.formatting import strikethrough
from mistune.plugins.task_lists import task_lists
from mistune.plugins.url import url
from mistune_slack import SlackRenderer, slack_pluginSlackRenderer
markdown = "# Hello, *world*!"
renderer = mistune.create_markdown(renderer=SlackRenderer(), plugins=[slack_plugin, strikethrough, url, task_lists])
blocks: list[dict] = renderer(markdown) # type: ignore
print(blocks) # post `blocks` to Slack
Testing
uv run test
License
MIT
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
mistune_slack-0.1.4.tar.gz
(71.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mistune_slack-0.1.4.tar.gz.
File metadata
- Download URL: mistune_slack-0.1.4.tar.gz
- Upload date:
- Size: 71.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae0f2690868328645fc5ca0a7642159e150f342f274046071bfc7fb480f2fea6
|
|
| MD5 |
45c2725dbd4ba290461b315cdd59ab60
|
|
| BLAKE2b-256 |
813608b5c3ef1757a9638789a2bc03346a612f75fb837ca008b124b2c721df8b
|
File details
Details for the file mistune_slack-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mistune_slack-0.1.4-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66b3f0ea3ef034049493c7dafd47f67870804b35a0352fd4ab952e077ca3a5a6
|
|
| MD5 |
e5b97090c484c0e86817ee122cd55a8a
|
|
| BLAKE2b-256 |
0bbf2f1eb4f250d754994d1671a03b34fecf7ae6023427594ea02fcd394697e5
|