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.0.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.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mistune_slack-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 c42400e9c5d8a79462d8601a3ed839d5cf917ec3b2228e6d0a8592916dd747f0
MD5 b22c8c1c5a2bf9dbb63142801a00662b
BLAKE2b-256 b129bc5b9e01454d149b0cf4e8d40563601131e24a9f1b1cb29d7a0a25d2a493

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mistune_slack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15f6189bbca6ef654080a98b8ca985896d5d81b165cad74acdf9344c1039021b
MD5 788446252b07e7c169a02ab6d5539262
BLAKE2b-256 1ae4a036edbb27b073d8f319071f19bf54464173060b5e83d95e03eb91fecae8

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