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.2.tar.gz (71.2 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.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mistune_slack-0.1.2.tar.gz
Algorithm Hash digest
SHA256 26fbe94cfed6269e24d8c204467c6e524b4a3fa8333deb32690068f5514fb2b2
MD5 3c28a76ee7b3815b0c2142735b210242
BLAKE2b-256 6d341072ffc33e0e63bd06ed39904256eb56d5b747ffe69594c42c1d3afd14de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mistune_slack-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9e6bb8596fc8411907597a5480cc28829010ff4a426421186a8ec6c5fc42bee7
MD5 d28c22feb95cd56efc714f64a3ebef7d
BLAKE2b-256 8362fdfc3af5d311231b46c2c0502fd5ed2c25bf95002cffa7660b8b2b379c73

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