Skip to main content

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 example

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.SlackRenderer and 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.1.tar.gz (70.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mistune_slack-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file mistune_slack-0.1.1.tar.gz.

File metadata

  • Download URL: mistune_slack-0.1.1.tar.gz
  • Upload date:
  • Size: 70.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.1

File hashes

Hashes for mistune_slack-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a5212657420cb8fe1604e1290a41c0be11e738806cde2be4ef1b2e7d2d6d97f5
MD5 fe734b09d6c9cab50f5f8d17b8a2f973
BLAKE2b-256 19e85c721b8bbf71bd022f9c60fc9b6c20938150b9f2920d0d0fe44d4f483b3a

See more details on using hashes here.

File details

Details for the file mistune_slack-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mistune_slack-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 94080b691a2481c98c8733ea95e50a2f538827a5b9cea72f70fef2adf647d6d4
MD5 c58f239191cf04317df7abefd0158b60
BLAKE2b-256 2d069c6245a0f6a1d19b5ddf1a4bb6ec05f97c92f9711110deaf049dae8cb63c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page