如果您的文档引用具有明确定义的 URI,您可以创建一个小程序,在给定文档 ID 和一些实体标识符的情况下自动构建正确的 URI。
例如,我编写了一个小的Ubiquity命令,它允许我快速打开任何 Qt 实体的最新文档,只需切换到 Firefox,输入ctrl+space以弹出 Ubiquity 控制台,然后输入qt QSomeClass
.
以下是 Ubiquity 命令的完整代码(如果您已经安装了 Ubiquity,您可以订阅此空白页面上的命令提要):
CmdUtils.makeSearchCommand({
names: ["qt"],
author: {name: "Luc Touraille"},
url: "http://doc.qt.nokia.com/main-snapshot/{QUERY}.html",
icon: "http://qt.nokia.com/favicon.ico",
description: "Searches the Qt Documentation for your word."
});
如您所见,它非常简单,可以很容易地适应其他在线文档,只要 URL 结构良好。
编辑
这是一个更通用的版本,您可以根据自己的需要进行调整(您只需要填写模板映射):
var urlTemplates = {
"QT": "http://doc.qt.nokia.com/main-snapshot/{QUERY}.html",
"MPL": "www.boost.org/doc/libs/release/libs/mpl/doc/refmanual/{QUERY}.html",
".NET": "http://msdn.microsoft.com/en-us/library/{QUERY}.aspx"
};
CmdUtils.CreateCommand({
names: ["doc"],
author: {name: "Luc Touraille"},
arguments: [ {role: "object",
nountype: /^[0-9a-zA-Z_.-]*$/,
label: "entity"
},
{role: "source",
nountype: [source for (source in urlTemplates)],
label: "documentation"
} ],
description: "Searches the documentation for some entity on a given documentation reference.",
_getSearchResultUrl: function( arguments ) {
var documentationSource = arguments.source.text;
var urlTemplate = urlTemplates[documentationSource.toUpperCase()];
return urlTemplate.replace("{QUERY}", arguments.object.text);
},
execute: function( arguments ) {
Utils.openUrlInBrowser(this._getSearchResultUrl(arguments));
}
});
样品用途:
doc QMainWindow from qt
doc from mpl vector
doc system.idisposable from .net
doc this from .net // with some text selected
当然,这是一个非常幼稚的实现,在大多数网站上都会失败。一种更先进的方法可能是用函数替换地图中的 URL 模板,从而对目标 URL 的构建提供更多控制。我将把它作为练习留给读者:)。另一种解决方案可能是在网站上执行搜索(假设它提供了适当的 REST API 用于搜索)并跳转到第一个结果。