I want to send a Markdown table to Slack with its postMessage
API, but I got raw content in Slack instead of a rendered table. Does Slack support Markdown tables? Ir is there any other way to present tabular data in Slack? I know Slack doesn't support HTML.
I tried chat.postMessage
and files.upload
, also formatting text with fixed column length but it looks kind of ugly, so I am figuring out a way to make it look better.
Here is my HTTP request code, content-type is JSON:
url : https://slack.com/api/chat.postMessage body : { "channel": "RKAID4I", "text": " | Tables | Are | Cool | |---------- |:-------------: |------: | | col 1 is | left-aligned | $1600 | | col 2 is | centered | $12 | | col 3 is | right-aligned | $1 |" }
I was expect table like format, but the actual output is exactly as what I sent. Is it because my Markdown message is wrong or Slack simply doesn't support Markdown tables?
Slack has no built-in support to render tables in messages. Your workaround options are: Draw table with chars in the message using a monospace font (Example)
Slack is a popular team messaging and collaboration application that supports a subset of the Markdown syntax. Different parts of the interface provide different levels of Markdown support.
From your desktop, click the plus icon next to the message field. Search for and select Create a text snippet from the menu. Enter a title if you'd like, then choose a file type from the drop-down menu. Type or paste your snippet in the Content field.
No, in fact, Slack doesn't support Markdown in messages¹ at all. It uses its own similar-at-a-glance format called mrkdwn
which has some notable differences with Markdown:
*
and _
are used for emphasis **
and __
are used for bold mrkdwn
*
is used for bold and _
is used for emphasis ~~
) but mrkdwn
uses ~
for strikethroughmrkdwn
doesn't support headingsDon't expect arbitrary Markdown² to work in Slack messages.
¹Slack does support Markdown in posts which can be created using the files.upload
API endpoint setting filetype
to post
.
²Note that tables aren't supported in regular Markdown either. Like strikethrough, some implementations have added these.
Slack does not support rendering of tables so this markup will not work.
You have two alternatives:
fields
in layout blocks.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With