问题描述
我在一个大型静态网站 (Jekyll) 上工作,希望能够点击浏览器 (Chrome) 中页面上的链接,这将在本地机器 (Sublime) 上打开相应的源文件.我可以得到文件的绝对链接.
I'm working on a large static website (Jekyll) and would like to be able to click on a link on a page in browser (Chrome) which will open it's corresponding source file on the local machine (Sublime). I can get the absolute link of the file.
从控制台 (Ubuntu) 我可以做到:
From the console (Ubuntu) I can do:
subl path/to/file.txt
打开一个文件,那么也许是一个允许在受信任域上执行命令的扩展?
to open a file, so perhaps an extension that allows command execution on trusted domains?
推荐答案
Ubuntu有一个 Ubuntu 解决方案
Windows 方法
您首先必须在 Windows 注册表中安装协议处理程序.(参考:chrome 中的自定义协议处理程序)
You first have to install a Protocol Handler in the Windows registry.(Reference:Custom protocol handler in chrome)
这将使 Chrome 在点击 subl:path/to/file
链接时运行命令.但是你不能简单地运行 sublime_text.exe subl:path/to/file
,因为 Sublime 不理解 subl:path/to/file
参数.您首先必须使用脚本提取文件名,然后使用单个文件参数调用 Sublime.
This will get Chrome to run a command when a subl:path/to/file
link is clicked.But you can't simply run sublime_text.exe subl:path/to/file
, because Sublime doesn't understand the subl:path/to/file
parameter. You first have to extract the filename with a script and then call Sublime with a single file parameter.
解决方案 1
这是一个适用于 Windows 的解决方案,可打开格式链接>
subl://open?url=file://<path_to_file>&line=4
它首先注册一个脚本作为协议处理程序,然后调用 Sublime
It first registers a Script as a Protocol Handler, which in turn calls Sublime
解决方案 2
我编辑了解决方案 1 以打开格式的链接
I edited Solution 1 to open links in the format
subl://path/to/file:line
只需按照解决方案 1,但将 open_file.vbs
更改为:
Just follow Solution 1, but change open_file.vbs
to:
' path to sublime_text.exe
Dim sublime_path
' CHANGE THIS:
sublime_path = "C:\Programme\Sublime Text 3\sublime_text.exe"
Dim text, filename
' get first command line argument
text = WScript.Arguments.Item(0)
filename = Split(text, ":/")(1)
Dim run_command
run_command = """"&sublime_path&""" """&filename&""""
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(run_command)
Set objShell = Nothing
(您必须更改 sublime_text.exe 的路径)
(You have to change the path to your sublime_text.exe)
Machttps://github.com/corysimmons/subl-handler
这篇关于如何获取网页上的超链接以在文本编辑器中打开文件(Sublime Text)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!