slack-blocks-markdown

raw JSON →
0.2.1 verified Fri May 01 auth: no python

Convert Markdown to Slack Block Kit blocks using mistletoe. Current version: 0.2.1, requires Python >=3.11. Releases are infrequent, mostly bugfixes and type hint improvements.

pip install slack-blocks-markdown
error AttributeError: module 'slack_blocks_markdown' has no attribute 'SlackBlocksMarkdown'
cause Incorrect import path: importing from the wrong module or misspelling.
fix
Use from slack_blocks_markdown import SlackBlocksMarkdown
error TypeError: 'NoneType' object is not iterable
cause Parsing a markdown string with unsupported syntax (e.g., definition list) may cause internal render methods to fail if token.children is None.
fix
Avoid unsupported Markdown elements. Check the README for supported syntax.
error KeyError: 'start'
cause Ordered list tokens may lack a `start` attribute when the list is not numerically starting? This was a bug fixed in v0.1.2. Ensure you are using >=0.1.2.
fix
Upgrade to the latest version: pip install slack-blocks-markdown --upgrade
deprecated The method `convert` was renamed to `markdown_to_blocks` in v0.1.2. Using `convert` may still work but will be removed in a future release.
fix Use `converter.markdown_to_blocks(md_string)` instead.
gotcha The library requires Python >=3.11 due to use of `str.removeprefix` and other 3.11+ features. Attempting to install on older Python will fail.
fix Ensure your Python version is 3.11 or higher. Use `python -V` to check.
gotcha Not all Markdown features are supported. The library maps a subset of Markdown elements to Slack's Block Kit; unsupported elements (e.g., definition lists, footnotes) are silently ignored.
fix Check the README or test coverage for a list of supported elements. Use only common Markdown (headers, paragraphs, lists, code, links, inline styles).
gotcha The returned blocks are plain Python dicts, not Slack SDK objects. You must post them to Slack via the Web API yourself.
fix Use the Slack SDK or direct HTTP POST to `chat.postMessage` with `"blocks": converter.markdown_to_blocks(md_string)`.

Parse Markdown string and output Slack Block Kit blocks as a list of dicts.

from slack_blocks_markdown import SlackBlocksMarkdown

converter = SlackBlocksMarkdown()
blocks = converter.markdown_to_blocks("# Hello\n\nThis is **bold** and `code`")
print(blocks)