格式化来自 Slack 的消息
Format messages from Slack
所以我向 Slack api 请求获取特定频道的消息历史记录。一切正常,除了返回的消息仍然是松弛格式。有没有办法把它转换成HTML格式?
谢谢。
没有。 Slack api 只会为您提供 Slack 标记中的消息。如果你想在 html 中使用它们,你需要自己转换它们或找一个库。
以下是如何解析 Slack 标记,以便将其转换为另一种格式,例如 HTML:
If you're retrieving messages, we've included some extra details in
the sections above to help you parse the formatting syntax. This will
let you properly format it for display on a different service, or to
help your app fully understand the intent of a message. Here are the
general steps involved for detecting advanced formatting syntax:
Detect all sub-strings matching <(.*?)>
Within those sub-strings, format content starting with #C as a channel link
Format content starting with @U or @W as a user mention
Format content starting with !subteam as a user group mention
Format content starting with ! according to the rules for special mentions
For any other content within those sub-strings, format as a URL link
Once the format has been determined, check for a pipe (|) - if present, use the text following the pipe as the label for the link or
mention.
来自 Formatting 上的官方 Slack 文档。
所以我向 Slack api 请求获取特定频道的消息历史记录。一切正常,除了返回的消息仍然是松弛格式。有没有办法把它转换成HTML格式?
谢谢。
没有。 Slack api 只会为您提供 Slack 标记中的消息。如果你想在 html 中使用它们,你需要自己转换它们或找一个库。
以下是如何解析 Slack 标记,以便将其转换为另一种格式,例如 HTML:
If you're retrieving messages, we've included some extra details in the sections above to help you parse the formatting syntax. This will let you properly format it for display on a different service, or to help your app fully understand the intent of a message. Here are the general steps involved for detecting advanced formatting syntax:
Detect all sub-strings matching <(.*?)>
Within those sub-strings, format content starting with #C as a channel link
Format content starting with @U or @W as a user mention
Format content starting with !subteam as a user group mention
Format content starting with ! according to the rules for special mentions
For any other content within those sub-strings, format as a URL link
Once the format has been determined, check for a pipe (|) - if present, use the text following the pipe as the label for the link or mention.
来自 Formatting 上的官方 Slack 文档。