以“vscode:”开头的 HTML 链接,用于在 Visual Studio Code 中打开文件

Jmi*_*ini 4 html hyperlink visual-studio-code

根据问题#4883和 PR #15320,vscode:/您可以在 HTML 中创建链接:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>

<h1>Test</h1>
<a href="vscode://path/to/my/file.md">open file.md in vscode</a> 

</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

这应该与在控制台中键入以下内容具有相同的效果:

code -g -r /path/to/my/file.md
Run Code Online (Sandbox Code Playgroud)

但我得到的却不同:

示例页面

点击后:

单击后的示例页面

单击“打开 Visual Studio Code”后,应用程序将打开(或置于前台),但文件未打开。

我错过了什么?

我已经尝试过,<a href="vscode:///path/to/my/file.md">但结果是一样的。

Jmi*_*ini 5

我在这个答案中找到了解决方案:您file/的文件路径之前需要一个前缀:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>

<h1>Test</h1>
<a href="vscode://file/path/to/my/file.md">open file.md in vscode</a> 

</body>
</html> 
Run Code Online (Sandbox Code Playgroud)