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

Add :sty! and :hi! to allow instantiation without error checking

This commit is contained in:
Kris Maglione
2008-10-06 15:17:19 +00:00
parent 2dd206df47
commit d5f8ce6438

View File

@@ -52,18 +52,18 @@ liberator.Buffer = function () //{{{
* they're members of the window object, which disappear * they're members of the window object, which disappear
* with this window. * with this window.
*/ */
const util = liberator.util;
const consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
const sleep = liberator.sleep;
const storage = liberator.storage;
function Styles(name, store, serial) function Styles(name, store, serial)
{ {
const XHTML = "http://www.w3.org/1999/xhtml"; const xmlToDom = liberator.util.xmlToDom;
const sleep = liberator.sleep;
const storage = liberator.storage;
const consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
const ios = Components.classes["@mozilla.org/network/io-service;1"] const ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService); .getService(Components.interfaces.nsIIOService);
const sss = Components.classes["@mozilla.org/content/style-sheet-service;1"] const sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
.getService(Components.interfaces.nsIStyleSheetService); .getService(Components.interfaces.nsIStyleSheetService);
const XHTML = "http://www.w3.org/1999/xhtml";
const namespace = "@namespace html url(" + XHTML + ");\n" + const namespace = "@namespace html url(" + XHTML + ");\n" +
"@namespace xul url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);\n"; "@namespace xul url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);\n";
@@ -76,13 +76,16 @@ liberator.Buffer = function () //{{{
this.__defineGetter__("systemSheets", function () Iterator(systemSheets)); this.__defineGetter__("systemSheets", function () Iterator(systemSheets));
this.__defineGetter__("userSheets", function () Iterator(userSheets)); this.__defineGetter__("userSheets", function () Iterator(userSheets));
this.addSheet = function (filter, css, system) this.addSheet = function (filter, css, system, force)
{ {
let sheets = system ? systemSheets : userSheets; let sheets = system ? systemSheets : userSheets;
let errors = checkSyntax(css); if (!force)
if (errors.length) {
return errors.map(function (e) "CSS: " + filter + ": " + e).join("\n"); let errors = checkSyntax(css);
if (errors.length)
return errors.map(function (e) "CSS: " + filter + ": " + e).join("\n");
}
if (sheets.some(function (s) s[0] == filter && s[1] == css)) if (sheets.some(function (s) s[0] == filter && s[1] == css))
return null; return null;
@@ -104,7 +107,7 @@ liberator.Buffer = function () //{{{
if (filter == undefined) if (filter == undefined)
filter = ""; filter = "";
/* Find all sheets which match the filter */ /* Find all sheets with URIs matching the filter */
let matches = [s for (s in Iterator(sheets)) let matches = [s for (s in Iterator(sheets))
if (filter == "" || s[1][0].indexOf(filter) >= 0)]; if (filter == "" || s[1][0].indexOf(filter) >= 0)];
@@ -181,7 +184,7 @@ liberator.Buffer = function () //{{{
consoleService.registerListener(listener); consoleService.registerListener(listener);
if (testDoc.documentElement.firstChild) if (testDoc.documentElement.firstChild)
testDoc.documentElement.removeChild(testDoc.documentElement.firstChild); testDoc.documentElement.removeChild(testDoc.documentElement.firstChild);
testDoc.documentElement.appendChild(util.xmlToDom( testDoc.documentElement.appendChild(xmlToDom(
<html><head><link type="text/css" rel="stylesheet" href={cssUri(namespace + css)}/></head></html>, testDoc)); <html><head><link type="text/css" rel="stylesheet" href={cssUri(namespace + css)}/></head></html>, testDoc));
while (true) while (true)
@@ -739,20 +742,23 @@ liberator.Buffer = function () //{{{
liberator.commands.add(["sty[le]"], liberator.commands.add(["sty[le]"],
"Add or list user styles", "Add or list user styles",
function (args) function (args, special)
{ {
let [, filter, css] = args.match(/(\S+)\s*((?:.|\n)*)/) || []; let [, filter, css] = args.match(/(\S+)\s*((?:.|\n)*)/) || [];
if (!css) if (!css)
{ {
let str = liberator.template.tabular(["", "Filter", "CSS"], let str = liberator.template.tabular(["", "Filter", "CSS"],
["padding: 0 1em 0 1ex; vertical-align: top", "padding: 0 1em 0 0; vertical-align: top"], ["padding: 0 1em 0 1ex; vertical-align: top", "padding: 0 1em 0 0; vertical-align: top"],
([i, style[0].join(","), style[1]] for ([i, style] in styles.userSheets) ([i,
if (!filter || style[0].indexOf(filter) >= 0))); style[0].join(","),
style[1]]
for ([i, style] in styles.userSheets)
if (!filter || style[0].indexOf(filter) >= 0)));
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
} }
else else
{ {
let err = styles.addSheet(filter, css); let err = styles.addSheet(filter, css, false, special);
if (err) if (err)
liberator.echoerr(err); liberator.echoerr(err);
} }
@@ -764,6 +770,7 @@ liberator.Buffer = function () //{{{
.concat([[s, ""] for each (s in styles.sites)]) .concat([[s, ""] for each (s in styles.sites)])
, filter)], , filter)],
hereDoc: true, hereDoc: true,
bang: true,
}); });
liberator.commands.add(["dels[tyle]"], liberator.commands.add(["dels[tyle]"],
@@ -790,7 +797,7 @@ liberator.Buffer = function () //{{{
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
return; return;
} }
liberator.buffer.highlight(key, css); liberator.buffer.highlight(key, css, special);
}, },
{ {
completer: function (filter) [0, liberator.completion.filter([[v, ""] for ([k, v] in Iterator(highlightClasses))], filter)], completer: function (filter) [0, liberator.completion.filter([[v, ""] for ([k, v] in Iterator(highlightClasses))], filter)],
@@ -1080,7 +1087,7 @@ liberator.Buffer = function () //{{{
addPageInfoSection: addPageInfoSection, addPageInfoSection: addPageInfoSection,
highlight: function (key, style) highlight: function (key, style, force)
{ {
let [, class, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/); let [, class, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/);
@@ -1090,7 +1097,7 @@ liberator.Buffer = function () //{{{
return; return;
} }
let getCSS = function (style) ".hl-" + class + selectors + " { " + style.replace(/;|;?$/g, "!important;") + " }"; let getCSS = function (style) ".hl-" + class + selectors + " { " + style.replace(/(?:!\s*important\s*)?;|(?:!\s*important\s*)?;?$/g, "!important;") + " }";
let css = getCSS(style); let css = getCSS(style);
liberator.log("css: " + css); liberator.log("css: " + css);
@@ -1100,7 +1107,7 @@ liberator.Buffer = function () //{{{
if (/^\s*$/.test(style)) if (/^\s*$/.test(style))
return highlight.remove(key); return highlight.remove(key);
let error = styles.addSheet(highlightDocs, css, true); let error = styles.addSheet(highlightDocs, css, true, force);
if (error) if (error)
liberator.echoerr(error); liberator.echoerr(error);
else else