mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-29 01:02:27 +01:00
Death to E4X and stuff.
This commit is contained in:
@@ -1501,11 +1501,14 @@ var DOM = Class("DOM", {
|
|||||||
* entities.
|
* entities.
|
||||||
*
|
*
|
||||||
* @param {string} str
|
* @param {string} str
|
||||||
|
* @param {boolean} simple If true, only escape for the simple case
|
||||||
|
* of text nodes.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
escapeHTML: function escapeHTML(str) {
|
escapeHTML: function escapeHTML(str, simple) {
|
||||||
let map = { "'": "'", '"': """, "%": "%", "&": "&", "<": "<", ">": ">" };
|
let map = { "'": "'", '"': """, "%": "%", "&": "&", "<": "<", ">": ">" };
|
||||||
return str.replace(/['"&<>]/g, function (m) map[m]);
|
let regexp = simple ? /[<>]/g : /['"&<>]/g;
|
||||||
|
return str.replace(regexp, function (m) map[m]);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// This work is licensed for reuse under an MIT license. Details are
|
// This work is licensed for reuse under an MIT license. Details are
|
||||||
// given in the LICENSE.txt file included with this file.
|
// given in the LICENSE.txt file included with this file.
|
||||||
/* use strict */
|
"use strict";
|
||||||
|
|
||||||
defineModule("help", {
|
defineModule("help", {
|
||||||
exports: ["help"],
|
exports: ["help"],
|
||||||
@@ -11,7 +11,7 @@ defineModule("help", {
|
|||||||
|
|
||||||
lazyRequire("completion", ["completion"]);
|
lazyRequire("completion", ["completion"]);
|
||||||
lazyRequire("overlay", ["overlay"]);
|
lazyRequire("overlay", ["overlay"]);
|
||||||
lazyRequire("template", ["template"]);
|
lazyRequire("template", ["template", "template_"]);
|
||||||
|
|
||||||
var HelpBuilder = Class("HelpBuilder", {
|
var HelpBuilder = Class("HelpBuilder", {
|
||||||
init: function init() {
|
init: function init() {
|
||||||
@@ -132,11 +132,8 @@ var Help = Module("Help", {
|
|||||||
.map(function (m) m[1]).uniq().slice(-1)[0];
|
.map(function (m) m[1]).uniq().slice(-1)[0];
|
||||||
|
|
||||||
|
|
||||||
default xml namespace = NS;
|
|
||||||
function rec(text, level, li) {
|
function rec(text, level, li) {
|
||||||
XML.ignoreWhitespace = XML.prettyPrinting = false;
|
let res = [];
|
||||||
|
|
||||||
let res = <></>;
|
|
||||||
let list, space, i = 0;
|
let list, space, i = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -145,10 +142,13 @@ var Help = Module("Help", {
|
|||||||
continue;
|
continue;
|
||||||
else if (match.char) {
|
else if (match.char) {
|
||||||
if (!list)
|
if (!list)
|
||||||
res += list = <ul/>;
|
res.push(list = ["ul", {}]);
|
||||||
let li = <li/>;
|
let li = ["li", {}];
|
||||||
li.* += rec(match.content.replace(RegExp("^" + match.space, "gm"), ""), level + 1, li);
|
li.push(rec(match.content
|
||||||
list.* += li;
|
.replace(RegExp("^" + match.space, "gm"), ""),
|
||||||
|
level + 1,
|
||||||
|
li));
|
||||||
|
list.push(li);
|
||||||
}
|
}
|
||||||
else if (match.par) {
|
else if (match.par) {
|
||||||
let [, par, tags] = /([^]*?)\s*((?:\[[^\]]+\])*)\n*$/.exec(match.par);
|
let [, par, tags] = /([^]*?)\s*((?:\[[^\]]+\])*)\n*$/.exec(match.par);
|
||||||
@@ -158,57 +158,52 @@ var Help = Module("Help", {
|
|||||||
let group = !tags.length ? "" :
|
let group = !tags.length ? "" :
|
||||||
!tags.some(function (t) t == beta) ? "HelpNewsOld" : "HelpNewsNew";
|
!tags.some(function (t) t == beta) ? "HelpNewsOld" : "HelpNewsNew";
|
||||||
if (i === 0 && li) {
|
if (i === 0 && li) {
|
||||||
li.@highlight = group;
|
li[1]["dactyl:highlight"] = group;
|
||||||
group = "";
|
group = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
list = null;
|
list = null;
|
||||||
if (level == 0 && /^.*:\n$/.test(match.par)) {
|
if (level == 0 && /^.*:\n$/.test(match.par)) {
|
||||||
let text = par.slice(0, -1);
|
let text = par.slice(0, -1);
|
||||||
res += <h2 tag={"news-" + text}>{template.linkifyHelp(text, true)}</h2>;
|
res.push(["h2", { tag: "news-" + text },
|
||||||
|
template_.linkifyHelp(text, true)]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let [, a, b] = /^(IMPORTANT:?)?([^]*)/.exec(par);
|
let [, a, b] = /^(IMPORTANT:?)?([^]*)/.exec(par);
|
||||||
res += <p highlight={group + " HelpNews"}>{
|
|
||||||
!tags.length ? "" :
|
res.push(["p", { "dactyl:highlight": group + " HelpNews" },
|
||||||
<hl key="HelpNewsTag">{tags.join(" ")}</hl>
|
!tags.length ? "" : ["hl", { key: "HelpNewsTag" }, tags.join(" ")],
|
||||||
}{
|
a ? ["hl", { key: "HelpWarning" }, a] : "",
|
||||||
a ? <hl key="HelpWarning">{a}</hl> : ""
|
template_.linkifyHelp(b, true)]);
|
||||||
}{
|
|
||||||
template.linkifyHelp(b, true)
|
|
||||||
}</p>;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
for each (let attr in res..@highlight) {
|
|
||||||
attr.parent().@NS::highlight = attr;
|
|
||||||
delete attr.parent().@highlight;
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
XML.ignoreWhitespace = XML.prettyPrinting = false;
|
|
||||||
let body = rec(NEWS, 0);
|
let body = rec(NEWS, 0);
|
||||||
for each (let li in body..li) {
|
|
||||||
let list = li..li.(@NS::highlight == "HelpNewsOld");
|
// E4X-FIXME
|
||||||
if (list.length() && list.length() == li..li.(@NS::highlight != "").length()) {
|
// for each (let li in body..li) {
|
||||||
for each (let li in list)
|
// let list = li..li.(@NS::highlight == "HelpNewsOld");
|
||||||
li.@NS::highlight = "";
|
// if (list.length() && list.length() == li..li.(@NS::highlight != "").length()) {
|
||||||
li.@NS::highlight = "HelpNewsOld";
|
// for each (let li in list)
|
||||||
}
|
// li.@NS::highlight = "";
|
||||||
}
|
// li.@NS::highlight = "HelpNewsOld";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
return '<?xml version="1.0"?>\n' +
|
return '<?xml version="1.0"?>\n' +
|
||||||
'<?xml-stylesheet type="text/xsl" href="dactyl://content/help.xsl"?>\n' +
|
'<?xml-stylesheet type="text/xsl" href="dactyl://content/help.xsl"?>\n' +
|
||||||
<document xmlns={NS} xmlns:dactyl={NS}
|
DOM.toXML(["document", { xmlns: "dactyl", name: "versions",
|
||||||
name="versions" title={config.appName + " Versions"}>
|
title: config.appName + " Versions" },
|
||||||
<h1 tag="versions news NEWS">{config.appName} Versions</h1>
|
["h1", { tag: "versions news NEWS" }, config.appName + " Versions"],
|
||||||
<toc start="2"/>
|
["toc", { start: "2" }],
|
||||||
|
|
||||||
{body}
|
body]);
|
||||||
</document>.toXMLString()
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -351,22 +346,20 @@ var Help = Module("Help", {
|
|||||||
value = value.replace(/.*\//, "");
|
value = value.replace(/.*\//, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
data.push(" ", name, '="',
|
data.push(" ", name, '="', DOM.escapeHTML(value), '"');
|
||||||
<>{value}</>.toXMLString().replace(/"/g, """),
|
|
||||||
'"');
|
|
||||||
}
|
}
|
||||||
if (node.localName in empty)
|
if (node.localName in empty)
|
||||||
data.push(" />");
|
data.push(" />");
|
||||||
else {
|
else {
|
||||||
data.push(">");
|
data.push(">");
|
||||||
if (node instanceof Ci.nsIDOMHTMLHeadElement)
|
if (node instanceof Ci.nsIDOMHTMLHeadElement)
|
||||||
data.push(<link rel="stylesheet" type="text/css" href="help.css"/>.toXMLString());
|
data.push('<link rel="stylesheet" type="text/css" href="help.css"/>');
|
||||||
Array.map(node.childNodes, fix);
|
Array.map(node.childNodes, fix);
|
||||||
data.push("</", node.localName, ">");
|
data.push("</", node.localName, ">");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Ci.nsIDOMNode.TEXT_NODE:
|
case Ci.nsIDOMNode.TEXT_NODE:
|
||||||
data.push(<>{node.textContent}</>.toXMLString());
|
data.push(DOM.escapeHTML(node.textContent, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user