我做错了什么?到目前为止,在我的Slack应用程序中,还没有一个降价链接的例子。

我在我的Slack应用程序的聊天中粘贴了下面的例子。我从Slack markdown语法中得到了这个例子,它仍然将其视为Slack应用程序中的文字文本:

[like this](http://someurl)

所以我最终在Slack聊天中看到的不是“像这样”的链接。

或许上面的说法是错误的,在这种情况下,我的问题是如何在Slack中显式地创建链接?我想要一些文本,我指定可以点击到特定的URL(超链接)。


当前回答

以下是spottedman的回答,我是如何让它在Javascript中工作的。注意,对于Firefox,用户需要启用一个标志才能使其工作。

a.addEventListener("click", function() {
    var textToDisplay = "foo";
    var url = "https://stackoverflow.com";
    var message = `<html><body>
    <!--StartFragment-->
    <a href="${url}">${textToDisplay}</a>
    <!--EndFragment-->
    </body></html>`;
    const htmlBlob = new Blob([message], {type : 'text/html'});
    const textBlob = new Blob(["sda"], {type : 'text/plain'});

    const cbi = new ClipboardItem({
        ['text/html']: htmlBlob,
        ['text/plain']: textBlob
    });
    navigator.clipboard.write([cbi]);
});

其他回答

超级晚的派对,但我最近发现,你可以使用URL缩短器创建一个https链接,然后你可以引用使用markdown链接。

截至2021年8月,该功能最终在slack应用程序的标记模式中启用。在首选项中启用标记模式->高级->输入选项->用标记格式化消息。

https://slack.com/help/articles/202288908-Format-your-messages#markup

Surround text with brackets, then surround the link with parentheses:
[your text](the link)

我写了这段代码来转换markdown链接在一个文本体到链接格式slack期望:

// Pretty hacky, convert [sup](http://example.com) to <http://example.com|sup>
const reformatLinks = /\[(.*?)\]\((.*?)\)/g
const slackBody = body.replace(reformatLinks, (_m, text, url) => `<${url}|${text}>`)

据我所知,slack不支持文本内的图像链接。

当url涉及一个垂直栏|时,这种形式的降价有问题吗 用urltext解决了这个问题。替换(“|”、“% 7 c”)

我的标记设置是禁用的,一旦我启用了它(首选项->高级->格式消息与标记),它就工作了。