X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fhelp.jsm;h=623aeca1a6844dbd06842dc01095b43b48da5a3a;hb=3d837eb266a3a01d424192aa4ec1a167366178c5;hp=dadadfcd6993d2e78dd960a290fd91ca9762f2d4;hpb=5ebd29f56d17f62011cdd596b1d351947ee534ff;p=dactyl.git diff --git a/common/modules/help.jsm b/common/modules/help.jsm index dadadfc..623aeca 100644 --- a/common/modules/help.jsm +++ b/common/modules/help.jsm @@ -1,17 +1,17 @@ -// Copyright (c) 2008-2011 by Kris Maglione +// Copyright (c) 2008-2012 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -/* use strict */ +"use strict"; -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("help", { exports: ["help"], require: ["cache", "dom", "protocol", "services", "util"] -}, this); +}); -this.lazyRequire("completion", ["completion"]); -this.lazyRequire("overlay", ["overlay"]); +lazyRequire("completion", ["completion"]); +lazyRequire("overlay", ["overlay"]); +lazyRequire("template", ["template"]); var HelpBuilder = Class("HelpBuilder", { init: function init() { @@ -108,7 +108,7 @@ var Help = Module("Help", { { mimeType: "text/plain;charset=UTF-8" }) .responseText; - let re = util.regexp(UTF8( \s* # .*\n) | ^ (?P \s*) @@ -124,31 +124,29 @@ var Help = Module("Help", { ) | (?: ^ [^\S\n]* \n) + - ]]>), "gmxy"); + */)), "gmxy"); let betas = util.regexp(/\[((?:b|rc)\d)\]/, "gx"); let beta = array(betas.iterate(NEWS)) .map(function (m) m[1]).uniq().slice(-1)[0]; - - default xml namespace = NS; function rec(text, level, li) { - XML.ignoreWhitespace = XML.prettyPrinting = false; - - let res = <>; + let res = []; let list, space, i = 0; - for (let match in re.iterate(text)) { if (match.comment) continue; else if (match.char) { if (!list) - res += list =
    ; - let li =
  • ; - li.* += rec(match.content.replace(RegExp("^" + match.space, "gm"), ""), level + 1, li); - list.* += li; + res.push(list = ["ul", {}]); + let li = ["li", {}]; + li.push(rec(match.content + .replace(RegExp("^" + match.space, "gm"), ""), + level + 1, + li)); + list.push(li); } else if (match.par) { let [, par, tags] = /([^]*?)\s*((?:\[[^\]]+\])*)\n*$/.exec(match.par); @@ -158,58 +156,51 @@ var Help = Module("Help", { let group = !tags.length ? "" : !tags.some(function (t) t == beta) ? "HelpNewsOld" : "HelpNewsNew"; if (i === 0 && li) { - li.@highlight = group; + li[1]["dactyl:highlight"] = group; group = ""; } list = null; if (level == 0 && /^.*:\n$/.test(match.par)) { let text = par.slice(0, -1); - res +=

    {template.linkifyHelp(text, true)}

    ; + res.push(["h2", { tag: "news-" + text }, + template.linkifyHelp(text, true)]); } else { let [, a, b] = /^(IMPORTANT:?)?([^]*)/.exec(par); - res +=

    { - !tags.length ? "" : - {tags.join(" ")} - }{ - a ? {a} : "" - }{ - template.linkifyHelp(b, true) - }

    ; + + res.push(["p", { "dactyl:highlight": group + " HelpNews" }, + !tags.length ? "" : ["hl", { key: "HelpNewsTag" }, tags.join(" ")], + a ? ["hl", { key: "HelpWarning" }, a] : "", + template.linkifyHelp(b, true)]); } } i++; } - for each (let attr in res..@highlight) { - attr.parent().@NS::highlight = attr; - delete attr.parent().@highlight; - } + return res; } - XML.ignoreWhitespace = XML.prettyPrinting = false; let body = rec(NEWS, 0); - for each (let li in body..li) { - let list = li..li.(@NS::highlight == "HelpNewsOld"); - if (list.length() && list.length() == li..li.(@NS::highlight != "").length()) { - for each (let li in list) - li.@NS::highlight = ""; - li.@NS::highlight = "HelpNewsOld"; - } - } + // E4X-FIXME + // for each (let li in body..li) { + // let list = li..li.(@NS::highlight == "HelpNewsOld"); + // if (list.length() && list.length() == li..li.(@NS::highlight != "").length()) { + // for each (let li in list) + // li.@NS::highlight = ""; + // li.@NS::highlight = "HelpNewsOld"; + // } + // } return '\n' + '\n' + - '\n' + - -

    {config.appName} Versions

    - - - {body} -
    .toXMLString() + DOM.toXML(["document", { xmlns: "dactyl", name: "versions", + title: config.appName + " Versions" }, + ["h1", { tag: "versions news NEWS" }, config.appName + " Versions"], + ["toc", { start: "2" }], + + body]); }); }, @@ -234,7 +225,7 @@ var Help = Module("Help", { init: function init() { dactyl.commands["dactyl.help"] = function (event) { let elem = event.originalTarget; - help.help(elem.getAttribute("tag") || elem.textContent); + modules.help.help(elem.getAttribute("tag") || elem.textContent); }; }, @@ -304,7 +295,7 @@ var Help = Module("Help", { var addURIEntry = function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText); } else { - var zip = services.ZipWriter(FILE, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE); + var zip = services.ZipWriter(FILE.file, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE); addURIEntry = function addURIEntry(file, uri) zip.addEntryChannel(PATH + file, TIME, 9, @@ -321,10 +312,10 @@ var Help = Module("Help", { if (isinstance(node, [Ci.nsIDOMHTMLBaseElement])) return; - data.push("<"); data.push(node.localName); + data.push("<", node.localName); if (node instanceof Ci.nsIDOMHTMLHtmlElement) - data.push(" xmlns=" + XHTML.uri.quote(), - " xmlns:dactyl=" + NS.uri.quote()); + data.push(" xmlns=" + XHTML.quote(), + " xmlns:dactyl=" + NS.quote()); for (let { name, value } in array.iterValues(node.attributes)) { if (name == "dactyl:highlight") { @@ -352,22 +343,20 @@ var Help = Module("Help", { value = value.replace(/.*\//, ""); } - data.push(" ", name, '="', - <>{value}.toXMLString().replace(/"/g, """), - '"'); + data.push(" ", name, '="', DOM.escapeHTML(value), '"'); } if (node.localName in empty) data.push(" />"); else { data.push(">"); if (node instanceof Ci.nsIDOMHTMLHeadElement) - data.push(.toXMLString()); + data.push(''); Array.map(node.childNodes, fix); data.push(""); } break; case Ci.nsIDOMNode.TEXT_NODE: - data.push(<>{node.textContent}.toXMLString()); + data.push(DOM.escapeHTML(node.textContent, true)); } } @@ -414,7 +403,7 @@ var Help = Module("Help", { }) }, { }, { - commands: function init_commands(dactyl, modules, window) { + commands: function initCommands(dactyl, modules, window) { const { commands, completion, help } = modules; [ @@ -441,7 +430,7 @@ var Help = Module("Help", { }); }); }, - completion: function init_completion(dactyl, modules, window) { + completion: function initCompletion(dactyl, modules, window) { const { completion } = modules; completion.help = function completion_help(context, consolidated) { @@ -453,23 +442,19 @@ var Help = Module("Help", { context.keys = { text: 0, description: function () "all" }; }; }, - mappings: function init_mappings(dactyl, modules, window) { - const { help, mappings, modes } = modules; - - mappings.add([modes.MAIN], ["", ""], - "Open the introductory help page", - function () { help.help(); }); - - mappings.add([modes.MAIN], ["", ""], - "Open the single, consolidated help page", - function () { modules.ex.helpall(); }); - }, - javascript: function init_javascript(dactyl, modules, window) { + javascript: function initJavascript(dactyl, modules, window) { modules.JavaScript.setCompleter([modules.help.exportHelp], [function (context, args) overlay.activeModules.completion.file(context)]); + }, + options: function initOptions(dactyl, modules, window) { + const { options } = modules; + + options.add(["helpfile", "hf"], + "Name of the main help file", + "string", "intro"); } }); endModule(); -// vim: set fdm=marker sw=4 ts=4 et ft=javascript: +// vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript: