How to display a greater-than symbol at the start of a Slack attachment line with markdown enabled?

人走茶凉 提交于 2019-12-24 02:25:48

问题


I am trying to match a mock-up of a Slack API message that has a greater-than (>) character in a link at the start of an attachment text line. The mock-up also uses italics and bold in the attachment text, so I have text in the mrkdown_in array. Unfortunately, this causes Slack to interpret > or > as a blockquote character when it occurs at the start of a line. Does anyone know how to work around this?

I could use small greater-than (﹥) or full-width greater-than (>), but it seems silly that I can't figure out how use the standard greater-than (>).

Here is a Slack sandbox message JSON that reproduces the problem I am having: https://api.slack.com/docs/messages/builder?msg=%7B%22attachments%22...

Here is my JSON message from the above URL:

{
    "attachments": [
        {
            "text": "_First line (needs to be italic)_\n<http://google.com|&gt; There should be a \"&gt;\" at the start of this line>",
            "mrkdwn_in": [ "text" ]
        }
    ],
    "text": "How do I display a greater-than character at the start of the link below?"
}

Here is how Slack renders my message, with some annotation from me in red: annotated image


回答1:


A partial solution is to enter a vertical tab (\u000b) before the greater-than-symbol. This apparently has the effect of escaping the greater-than symbol. However, this does not work inside the link, so you have to move the vertical tab and the greater-than-symbol outside of it.

Example:

"text": "_First line (needs to be italic)_\n\u000b&gt;<http://google.com|There should be a \"&gt;\" at the start of this line>"

Full example here: Message Builder

Other "invisible" characters will work too. The question author found that \u200a (hair space) worked best for him.

I found the original solution for this problem on another Stack Exchange community: link



来源:https://stackoverflow.com/questions/46331295/how-to-display-a-greater-than-symbol-at-the-start-of-a-slack-attachment-line-wit

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