-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2012 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";
-Components.utils.import("resource://dactyl/bootstrap.jsm");
defineModule("highlight", {
exports: ["Highlight", "Highlights", "highlight"],
- require: ["services", "styles", "util"],
- use: ["messages", "template"]
-}, this);
+ require: ["services", "util"]
+});
+
+lazyRequire("styles", ["Styles", "styles"]);
+lazyRequire("template", ["template"]);
var Highlight = Struct("class", "selector", "sites",
"defaultExtends", "defaultValue",
let highlight = this.highlight[key] || this._create(false, [key]);
- let bases = extend || highlight.extend;
+ let bases = extend || highlight.extends;
if (append) {
newStyle = Styles.append(highlight.value || "", newStyle);
bases = highlight.extends.concat(bases);
* @param {string} group
*/
highlightNode: function highlightNode(node, group, applyBindings) {
- node.setAttributeNS(NS.uri, "highlight", group);
+ node.setAttributeNS(NS, "highlight", group);
let groups = group.split(" ");
for each (let group in groups)
* @param {string} class
*/
selector: function selector(class_)
- let (self = this)
- class_.replace(/(^|[>\s])([A-Z][\w-]+)\b/g,
- function (m, n1, hl) n1 +
- (self.highlight[hl] && self.highlight[hl].class != class_
- ? self.highlight[hl].selector : "[dactyl|highlight~=" + hl + "]")),
-
- groupRegexp: util.regexp(<![CDATA[
+ class_.replace(/(^|[>\s])([A-Z][\w-]+)\b/g,
+ (m, n1, hl) => {
+ if (this.highlight[hl] && this.highlight[hl].class != class_)
+ return n1 + this.highlight[hl].selector;
+ return n1 + "[dactyl|highlight~=" + hl + "]";
+ }),
+
+ groupRegexp: util.regexp(literal(/*
^
(\s* (?:\S|\s\S)+ \s+)
\{ ([^}]*) \}
\s*
$
- ]]>, "gmx"),
- sheetRegexp: util.regexp(<![CDATA[
+ */), "gmx"),
+ sheetRegexp: util.regexp(literal(/*
^\s*
!? \*?
(?P<group> (?:[^;\s]|\s[^;\s])+ )
(?:; (?P<extends> (?:[^;\s]|\s[^;\s])+ )? )?
\s* (?P<css> .*)
$
- ]]>, "x"),
+ */), "x"),
+ // </css>
/**
* Bulk loads new CSS rules, in the format of,
commands.add(["hi[ghlight]"],
"Set the style of certain display elements",
function (args) {
- let style = <![CDATA[
+ let style = literal(/*
;
display: inline-block !important;
position: static !important;
width: 3em !important; min-width: 3em !important; max-width: 3em !important;
height: 1em !important; min-height: 1em !important; max-height: 1em !important;
overflow: hidden !important;
- ]]>;
+ */);
let clear = args[0] == "clear";
if (clear)
args.shift();
["padding: 0 1em 0 0; vertical-align: top; max-width: 16em; overflow: hidden;",
"text-align: center"],
([h.class,
- <span style={"text-align: center; line-height: 1em;" + h.value + style}>XXX</span>,
- template.map(h.extends, template.highlight),
+ ["span", { style: "text-align: center; line-height: 1em;" + h.value + style }, "XXX"],
+ template.map(h.extends, function (s) template.highlight(s), ","),
template.highlightRegexp(h.value, /\b[-\w]+(?=:)|\/\*.*?\*\//g,
- function (match) <span highlight={match[0] == "/" ? "Comment" : "Key"}>{match}</span>)
+ function (match) ["span", { highlight: match[0] == "/" ? "Comment" : "Key" }, match])
]
for (h in highlight)
if (!key || h.class.indexOf(key) > -1))));
{
command: this.name,
arguments: [v.class],
- literalArg: v.value
+ literalArg: v.value,
+ options: {
+ "-link": v.extends.length ? v.extends : undefined
+ }
}
for (v in Iterator(highlight))
if (v.value != v.defaultValue)
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: