Skip to main content

A utility for converting between Slack's formats.

Project description

SlackFormat

CI codecov

SlackFormat is a Python library that enables easy manipulation of Slack messages in any format. It provides a simple and intuitive way to convert between Slack's Markdown, Rich Text, and Block Kit formats.


Features

  • Markdown to Rich Text: Convert Slack's Markdown to a Rich Text object.
  • Rich Text to Block Kit: Convert a Rich Text object to a Block Kit JSON structure.
  • Block Kit to Rich Text: Convert Block Kit JSON to a Rich Text object.
  • Block Kit to Markdown: Convert Block Kit JSON to a Markdown string.
  • Rich Text to Markdown: Convert a Rich Text object to a Markdown string.
  • Markdown to Block Kit: A convenience function to convert a Markdown string directly to a Block Kit object.
  • Comprehensive Formatting Support: Supports various formatting options including bold, italic, strikethrough, code, links, and lists.

Installation

To install the library, you can use pip: (hopefully soon lol -- sorry to get ur hopes up)

pip install slackformat

Usage

Here are some examples of how to use the SlackFormat library.

Markdown to Rich Text

You can convert a Markdown string to a Slack Rich Text object.

from slackformat import md_to_richtext

md = "Hello *bold* and _italic_ text"
richtext = md_to_richtext(md)
print(richtext)

Rich Text to Block Kit

You can convert a Rich Text object to a Block Kit JSON structure.

from slackformat import richtext_to_blockkit

richtext = {
    "type": "rich_text_section",
    "elements": [
        {"type": "text", "text": "Hello "},
        {"type": "text", "text": "world", "style": {"bold": True}}
    ]
}
blockkit = richtext_to_blockkit(richtext)
print(blockkit)

Block Kit to Rich Text

You can convert a Block Kit JSON structure to a Rich Text object.

from slackformat import blockkit_to_richtext

blockkit = {
    "type": "section",
    "text": {"type": "mrkdwn", "text": "*Bold* text"}
}
richtext = blockkit_to_richtext(blockkit)
print(richtext)

Block Kit to Markdown

You can convert a Block Kit JSON structure to a Markdown string.

from slackformat import blockkit_to_markdown

blockkit = {
    "type": "section",
    "text": {"type": "mrkdwn", "text": "*Bold* text"}
}
markdown = blockkit_to_markdown(blockkit)
print(markdown)

Rich Text to Markdown

You can convert a Rich Text object to a Markdown string.

from slackformat import richtext_to_markdown

richtext = {
    "type": "rich_text_section",
    "elements": [
        {"type": "text", "text": "Hello "},
        {"type": "text", "text": "world", "style": {"bold": True}}
    ]
}
markdown = richtext_to_markdown(richtext)
print(markdown)

Markdown to Block Kit

You can convert a Markdown string directly to a Block Kit object.

from slackformat import md_to_blockkit

md = "Hello *bold* and _italic_ text"
blockkit = md_to_blockkit(md)
print(blockkit)

Testing

To run the tests for this library, you can use pytest.

python -m pytest

With coverage reporting (requires pytest-cov):

pytest --cov=slackformat --cov-report=term-missing --cov-report=xml

The tests cover the following:

  • Markdown to Rich Text Converter (tests/converters/test_md_to_richtext.py)
  • Rich Text to Block Kit Converter (tests/converters/test_richtext_to_blockkit.py)
  • Block Kit to Rich Text Converter (tests/converters/test_blockkit_to_richtext.py)
  • Block Kit to Markdown Converter (tests/converters/test_blockkit_to_md.py)
  • Rich Text to Markdown Converter (tests/converters/test_richtext_to_md.py)
  • Markdown to Block Kit Converter (tests/converters/test_md_to_blockkit.py)
  • Integration Tests (tests/test_integration.py)

License

This project is licensed under the Apache License 2.0.

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

slackformat-1.0.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

slackformat-1.0.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file slackformat-1.0.0.tar.gz.

File metadata

  • Download URL: slackformat-1.0.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for slackformat-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ce83a83448a8e9bd08780f7a3e4456415ca9a2ce1c9eaa7686364120b13c8db0
MD5 2dc4dad6fbe68acad693ddf6d25ffb1a
BLAKE2b-256 2b8621bac87bf9b4ba77760a2eede94846e6e7a493c8700bf28b959fa94ceff9

See more details on using hashes here.

File details

Details for the file slackformat-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: slackformat-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for slackformat-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c2ea0cd046f691e22f3223ab18a703c3cb91ab498eef6e1d165f469526ce5af
MD5 52eb572be0bc4e3b19711f6d438e7c75
BLAKE2b-256 250ea3ecff99b430de804e17f0d5833fc5eac12c341b73c23f90b3a5f1941f1d

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