mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 16:57:59 +01:00
Automagically linkify help index descriptions.
This commit is contained in:
@@ -23,6 +23,7 @@ const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPr
|
||||
|
||||
function dataURL(type, data) "data:" + (type || "application/xml;encoding=UTF-8") + "," + escape(data);
|
||||
function makeChannel(url, orig) {
|
||||
try {
|
||||
if (url == null)
|
||||
return fakeChannel();
|
||||
if (typeof url === "function")
|
||||
@@ -34,6 +35,11 @@ function makeChannel(url, orig) {
|
||||
channel.originalURI = orig;
|
||||
return channel;
|
||||
}
|
||||
catch (e) {
|
||||
Components.utils.reportError(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
function fakeChannel(orig) makeChannel("chrome://dactyl/content/does/not/exist", orig);
|
||||
function redirect(to, orig, time) {
|
||||
let html = <html><head><meta http-equiv="Refresh" content={(time || 0) + ";" + to}/></head></html>.toXMLString();
|
||||
|
||||
@@ -448,6 +448,10 @@ const Commands = Module("commands", {
|
||||
|
||||
/** @property {Iterator(Command)} @private */
|
||||
__iterator__: function () {
|
||||
let sorted = this._exCommands.sort(function (a, b) a.name > b.name);
|
||||
return array.iterValues(sorted);
|
||||
},
|
||||
iterator: function () {
|
||||
let sorted = this._exCommands.sort(function (a, b) a.serialGroup - b.serialGroup || a.name > b.name);
|
||||
return array.iterValues(sorted);
|
||||
},
|
||||
|
||||
@@ -564,6 +564,8 @@ const Dactyl = Module("dactyl", {
|
||||
</document>.toXMLString()));
|
||||
fileMap["plugins"] = function () ['text/xml;charset=UTF-8', help];
|
||||
|
||||
default xml namespace = NS;
|
||||
|
||||
overlayMap["index"] = function () ['text/xml;charset=UTF-8',
|
||||
'<?xml version="1.0"?>\n' +
|
||||
'<overlay xmlns="' + NS + '">\n' +
|
||||
@@ -571,8 +573,7 @@ const Dactyl = Module("dactyl", {
|
||||
template.map(dactyl.indices, function ([name, iter])
|
||||
<dl insertafter={name + "-index"}>{
|
||||
template.map(iter(), util.identity)
|
||||
}</dl>, <>{"\n\n"}</>)))
|
||||
.replace('xmlns="' + XHTML + '"', "", "g") +
|
||||
}</dl>, <>{"\n\n"}</>))) +
|
||||
'\n</overlay>'];
|
||||
|
||||
addTags("plugins", util.httpGet("dactyl://help/plugins").responseXML);
|
||||
@@ -728,13 +729,16 @@ const Dactyl = Module("dactyl", {
|
||||
|
||||
XML.prettyPrinting = false;
|
||||
XML.ignoreWhitespace = false;
|
||||
default xml namespace = NS;
|
||||
|
||||
// E4X has its warts.
|
||||
let br = <>
|
||||
</>;
|
||||
|
||||
let res = <res>
|
||||
<dt>{link(obj.name)}</dt> <dd>{obj.description ? obj.description.replace(/\.$/, "") : ""}</dd></res>;
|
||||
<dt>{link(obj.name)}</dt> <dd>{
|
||||
template.linkifyHelp(obj.description ? obj.description.replace(/\.$/, "") : "", true)
|
||||
}</dd></res>;
|
||||
if (specOnly)
|
||||
return res.*;
|
||||
|
||||
@@ -750,7 +754,7 @@ const Dactyl = Module("dactyl", {
|
||||
<type>{obj.type}</type>
|
||||
<default>{obj.stringDefaultValue}</default></>}
|
||||
<description>{
|
||||
obj.description ? br + <p>{obj.description.replace(/\.?$/, ".")}</p> : "" }{
|
||||
obj.description ? br + <p>{template.linkifyHelp(obj.description.replace(/\.?$/, "."), true)}</p> : "" }{
|
||||
extraHelp ? br + extraHelp : "" }{
|
||||
!(extraHelp || obj.description) ? br + <p>Sorry, no help available.</p> : "" }
|
||||
</description>
|
||||
@@ -779,7 +783,10 @@ const Dactyl = Module("dactyl", {
|
||||
})</>
|
||||
}</>
|
||||
]));
|
||||
return res.*.toXMLString().replace(/^ {12}|[ \t]+$/gm, "").replace(/^.*\n|\n.*$/g, "") + "\n";
|
||||
return res.*.toXMLString()
|
||||
.replace(' xmlns="' + NS + '"', "", "g")
|
||||
.replace(/^ {12}|[ \t]+$/gm, "")
|
||||
.replace(/^\s*\n|\n\s*$/g, "") + "\n";
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -555,7 +555,7 @@ lookup:
|
||||
"E189: " + filename.quote() + " exists (add ! to override)");
|
||||
|
||||
// TODO: Use a set/specifiable list here:
|
||||
let lines = [cmd.serialize().map(commands.commandToString, cmd) for (cmd in commands) if (cmd.serialize)];
|
||||
let lines = [cmd.serialize().map(commands.commandToString, cmd) for (cmd in commands.iterator()) if (cmd.serialize)];
|
||||
lines = array.flatten(lines);
|
||||
|
||||
lines.unshift('"' + dactyl.version + "\n");
|
||||
|
||||
@@ -88,6 +88,16 @@ const Template = Module("Template", {
|
||||
/^:\w/.test(topic) ? "HelpEx" : "HelpKey");
|
||||
return <a highlight={type} tag={topic} href={"dactyl://help-tag/" + topic} dactyl:command="dactyl.help" xmlns:dactyl={NS}>{text || topic}</a>
|
||||
},
|
||||
HelpLink: function (topic) {
|
||||
if (services["dactyl:"].initialized && !set.has(services["dactyl:"].HELP_TAGS, topic))
|
||||
return <>{topic}</>;
|
||||
|
||||
XML.ignoreWhitespace = false; XML.prettyPrinting = false;
|
||||
let tag = (/^'.*'$/.test(topic) ? "o" :
|
||||
/^:\w/.test(topic) ? "ex" : "k");
|
||||
topic = topic.replace(/^'(.*)'$/, "$1");
|
||||
return <{tag} xmlns={NS}>{topic}</{tag}>
|
||||
},
|
||||
|
||||
// if "processStrings" is true, any passed strings will be surrounded by " and
|
||||
// any line breaks are displayed as \n
|
||||
@@ -210,7 +220,7 @@ const Template = Module("Template", {
|
||||
// </e4x>
|
||||
},
|
||||
|
||||
linkifyHelp: function linkifyHelp(str) {
|
||||
linkifyHelp: function linkifyHelp(str, help) {
|
||||
util.dactyl.initHelp();
|
||||
|
||||
let re = util.regexp(<![CDATA[
|
||||
@@ -222,7 +232,7 @@ const Template = Module("Template", {
|
||||
let res;
|
||||
while ((res = re.exec(str)) && res[2].length)
|
||||
yield [res.index + res[1].length, res[2].length];
|
||||
})(), template.helpLink);
|
||||
})(), template[help ? "HelpLink" : "helpLink"]);
|
||||
},
|
||||
|
||||
options: function options(title, opts) {
|
||||
|
||||
Reference in New Issue
Block a user