]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/highlight.jsm
Import r6948 from upstream hg supporting Firefox up to 24.*
[dactyl.git] / common / modules / highlight.jsm
index 73b6b06ae7cf35ed166aa9b003e442d3285538bd..fca93478b3f7ce514cabba374e700eaf5bde62a8 100644 (file)
@@ -1,15 +1,16 @@
-// 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",
@@ -152,7 +153,7 @@ var Highlights = Module("Highlight", {
 
         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);
@@ -196,7 +197,7 @@ var Highlights = Module("Highlight", {
      * @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)
@@ -217,20 +218,21 @@ var Highlights = Module("Highlight", {
      * @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])+ )
@@ -239,7 +241,8 @@ var Highlights = Module("Highlight", {
         (?:; (?P<extends>  (?:[^;\s]|\s[^;\s])+ )? )?
         \s*  (?P<css>      .*)
         $
-    ]]>, "x"),
+    */), "x"),
+    // </css>
 
     /**
      * Bulk loads new CSS rules, in the format of,
@@ -321,7 +324,7 @@ var Highlights = Module("Highlight", {
         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;
@@ -329,7 +332,7 @@ var Highlights = Module("Highlight", {
                     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();
@@ -348,10 +351,10 @@ var Highlights = Module("Highlight", {
                             ["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))));
@@ -404,7 +407,10 @@ var Highlights = Module("Highlight", {
                     {
                         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)
@@ -447,4 +453,4 @@ var Highlights = Module("Highlight", {
 
 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: