vscode:如何在HTML模式下将文本链接到URL?

ijxebb2r  于 2022-12-09  发布在  Vscode
关注(0)|答案(1)|浏览(246)

Is there a way to quickly create a hyperlink in a HTML file given a text selection and a URL in the clipboard?
In markdown mode in vscode pasting a URL while some text is selected (e.g. W3 Consortium ) will result in a markdown link being created, i.e. [W3 Consortium](https://www.w3.org) . (Similar functionality is also available in slack's richtext editor)
Is similar functionality available for the HTML mode, ootb or via an extension?
E.g. given a text selection of W3 Consortium by pasting a URL like https://www.w3.org/ I expect to get:

<a href="https://www.w3.org">W3 Consortium</a>

Currently the selection is simply replaced with the URL.
Is this available in vscode and if so then how to enable it? Or is there an extension that could do it? This is a pretty common use case so I assume it might be implemented but not clear what to search for.

ncgqoxb0

ncgqoxb01#

这在vscode中是无法原生完成的,但是你可以很容易地为它创建一个代码片段/键绑定。

{
  "key": "alt+m",                          // whatever keybinding you want
  "command": "editor.action.insertSnippet",
  "when": "editorHasSelection  && editorLangId == html",
  "args": {
      "snippet": "<a href=\"${CLIPBOARD}\">${TM_SELECTED_TEXT}<\/a>"
  }
}

您可以看到它为您选择的文本和剪贴板内容使用变量。演示:

相关问题