Does Slack support Markdown tables?

让人想犯罪 __ 提交于 2020-01-22 14:34:26

问题


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?


回答1:


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:

  • In Markdown, both * and _ are used for emphasis
  • In Markdown, both ** and __ are used for bold
  • In mrkdwn * is used for bold and _ is used for emphasis
  • Markdown has no syntax for strikethrough (though some implementations have added it, e.g. in GFM which uses ~~) but mrkdwn uses ~ for strikethrough
  • Link syntax is very different
  • mrkdwn doesn't support headings
  • Probably more

Don'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.




回答2:


Slack does not support rendering of tables so this markup will not work.

You have two alternatives:

  • You can use fields, which will be rendered as 2 columns on most devices. See fields in layout blocks.
  • You can convert your table into an image (outside Slack) and
    attach the image to your message.


来源:https://stackoverflow.com/questions/55816333/does-slack-support-markdown-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!