遇到的问题
我想在vscode所写代码的注释中,插入obsidian的链接,并且能通过直接点击obsidian链接打开对应的笔记,如上图。
预期的效果
能像点击https等超链接后,跳转浏览器访问一样;通过点击obsidian url打开obsidian跳转访问笔记
已尝试的解决方案
目前能找到的办法是使用file:访问绝对路径,在vscode中打开对应的md文件,利用插件直接在vscode中渲染。
我想在vscode所写代码的注释中,插入obsidian的链接,并且能通过直接点击obsidian链接打开对应的笔记,如上图。
能像点击https等超链接后,跳转浏览器访问一样;通过点击obsidian url打开obsidian跳转访问笔记
目前能找到的办法是使用file:访问绝对路径,在vscode中打开对应的md文件,利用插件直接在vscode中渲染。
试了一下Zed编辑器是原生支持obsidian URL的,VSCode可能需要插件
楼主试试这个:
在.md文件中vscode能够识别obsidian链接,但在.c尾缀的文件中vscode没有识别obsidian链接。
这和我想要的效果很接近了,但我还想要的是能够在代码文件中,比如.c, .py文件等等,打开obsidian链接,而不仅仅在md文件中打开obsidian链接。
请问是否还有其它办法
确实即使是VSCode插件也只支持md文档,可能还是编辑器的限制,如果不希望换编辑器的话,分享一个我自用的ahk脚本(ahk v1):
; Alt+C - 一键直达文件/链接/搜索/网址(自动识别剪贴板内容)
<!c::
if (ErrorLevel) {
return
}
; 打开剪贴板链接
if (RegExMatch(clipboard, "i)^(https?://|ftp://|edge://|zotero://|obsidian://|wox://|file:///)[^\s/$.?#].[^\s]*$")) {
Run, %clipboard%
}
; 打开剪贴板文件路径
else if (RegExMatch(clipboard, "^(S:|T:|U:|V:|W:)\\") || FileExist(clipboard)) {
Shellrun(clipboard)
}
; 搜索剪贴板
else {
Run, https://www.google.com/search?q=%clipboard%
}
return
;-----------------------------------------------------------------------------------
; 非管理员模式运行程序(管理员打开的ahk默认以管理员模式运行)
/*
ShellRun by Lexikos
requires: AutoHotkey v1.1
license: http://creativecommons.org/publicdomain/zero/1.0/
Credit for explaining this method goes to BrandonLive:
http://brandonlive.com/2008/04/27/getting-the-shell-to-run-an-application-for-you-part-2-how/
Shell.ShellExecute(File [, Arguments, Directory, Operation, Show])
http://msdn.microsoft.com/en-us/library/windows/desktop/gg537745
*/
ShellRun(prms*)
{
shellWindows := ComObjCreate("Shell.Application").Windows
VarSetCapacity(_hwnd, 4, 0)
desktop := shellWindows.FindWindowSW(0, "", 8, ComObj(0x4003, &_hwnd), 1)
; Retrieve top-level browser object.
if ptlb := ComObjQuery(desktop
, "{4C96BE40-915C-11CF-99D3-00AA004AE837}" ; SID_STopLevelBrowser
, "{000214E2-0000-0000-C000-000000000046}") ; IID_IShellBrowser
{
; IShellBrowser.QueryActiveShellView -> IShellView
if DllCall(NumGet(NumGet(ptlb+0)+15*A_PtrSize), "ptr", ptlb, "ptr*", psv:=0) = 0
{
; Define IID_IDispatch.
VarSetCapacity(IID_IDispatch, 16)
NumPut(0x46000000000000C0, NumPut(0x20400, IID_IDispatch, "int64"), "int64")
; IShellView.GetItemObject -> IDispatch (object which implements IShellFolderViewDual)
DllCall(NumGet(NumGet(psv+0)+15*A_PtrSize), "ptr", psv
, "uint", 0, "ptr", &IID_IDispatch, "ptr*", pdisp:=0)
; Get Shell object.
shell := ComObj(9,pdisp,1).Application
; IShellDispatch2.ShellExecute
shell.ShellExecute(prms*)
ObjRelease(psv)
}
ObjRelease(ptlb)
}
}