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