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 demo

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.3.tar.gz (71.4 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.3-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mistune_slack-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6591410cb1efa6ebb895212414a4f42089bd0c4dcd9c9611ab674e06fd873ee8
MD5 7cef0bac896988236d83c182998ed35c
BLAKE2b-256 6696309cee6089bdab5bb6dd5122cf01525e05351e81cd717c13e06578ac6215

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mistune_slack-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7344463f968e6e7cf5000061646a28773038f6ddc7eb7a43eafa3d54bda267d3
MD5 25f2f16c936a9800e953f0a4749c8ea7
BLAKE2b-256 cdc1790c55de2b14ff4e145c048fb24b83f0c0df18bffab3ea877dd6be463a00

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