1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 01:27:59 +01:00

Automagically linkify help index descriptions.

This commit is contained in:
Kris Maglione
2010-12-23 02:05:04 -05:00
parent 45aea68aba
commit a6d067b33a
5 changed files with 64 additions and 37 deletions

View File

@@ -23,16 +23,22 @@ 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) {
if (url == null) try {
return fakeChannel(); if (url == null)
if (typeof url === "function") return fakeChannel();
url = dataURL.apply(null, url()); if (typeof url === "function")
let uri = ioService.newURI(url, null, null); url = dataURL.apply(null, url());
let channel = ioService.newChannelFromURI(uri); let uri = ioService.newURI(url, null, null);
channel.contentCharset = "UTF-8"; let channel = ioService.newChannelFromURI(uri);
channel.owner = systemPrincipal; channel.contentCharset = "UTF-8";
channel.originalURI = orig; channel.owner = systemPrincipal;
return channel; 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 fakeChannel(orig) makeChannel("chrome://dactyl/content/does/not/exist", orig);
function redirect(to, orig, time) { function redirect(to, orig, time) {

View File

@@ -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);
}, },

View File

@@ -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,33 +729,36 @@ 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.*;
res.* += <> res.* += <>
<item> <item>
<tags>{template.map(obj.names.slice().reverse(), tag, " ")}</tags> <tags>{template.map(obj.names.slice().reverse(), tag, " ")}</tags>
<spec>{ <spec>{
spec(template.highlightRegexp((obj.specs || obj.names)[0], spec(template.highlightRegexp((obj.specs || obj.names)[0],
/\[(.*?)\]/g, /\[(.*?)\]/g,
function (m, n0) <oa>{n0}</oa>)) function (m, n0) <oa>{n0}</oa>))
}</spec>{ }</spec>{
!obj.type ? "" : <> !obj.type ? "" : <>
<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>
</item></>; </item></>;
function add(ary) { function add(ary) {
res.item.description.* += br + res.item.description.* += br +
@@ -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";
}, },
/** /**
@@ -1798,10 +1805,10 @@ const Dactyl = Module("dactyl", {
keepQuotes: true, keepQuotes: true,
serialGroup: 10, serialGroup: 10,
serialize: function () [ serialize: function () [
{ {
command: this.name, command: this.name,
literalArg: options["loadplugins"].join(" ") literalArg: options["loadplugins"].join(" ")
} }
] ]
}); });

View File

@@ -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");

View File

@@ -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) {