Browse Source

调整语法高亮。

oldj 10 years ago
parent
commit
1a7420f740

+ 1 - 1
app/SH3/MacGap/SwitchHosts!-Info.plist

@@ -21,7 +21,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>2833</string>
+	<string>2834</string>
 	<key>LSApplicationCategoryType</key>
 	<string>public.app-category.developer-tools</string>
 	<key>LSMinimumSystemVersion</key>

+ 4 - 0
app/SH3/public/css/style.css

@@ -261,6 +261,10 @@ a:hover {
 .cm-s-default .cm-comment {
   color: #090;
 }
+.cm-s-default .cm-ip {
+  color: #00c;
+  font-weight: bold;
+}
 .CodeMirror-gutters {
   border-right: none;
   padding-right: 6px;

+ 3 - 0
app/SH3/public/css/style.styl

@@ -286,6 +286,9 @@ unselectable()
 // CodeMirror
 .cm-s-default .cm-comment
   color #090
+.cm-s-default .cm-ip
+  color #00c
+  font-weight bold
 .CodeMirror-gutters
   border-right none
   padding-right 6px

File diff suppressed because it is too large
+ 0 - 0
app/SH3/public/js/main.js


+ 29 - 33
app/src/cm_hl.js

@@ -7,42 +7,38 @@
     "use strict";
 
     CodeMirror.defineMode('host', function () {
+        function tokenBase(stream) {
+            if (stream.eatSpace()) return null;
 
-        return {
-            token: function(stream) {
-                var tw_pos = stream.string.search(/[\t ]+?$/);
-
-                //if (!stream.sol() || tw_pos === 0) {
-                //    stream.skipToEnd();
-                    //return ("error " + (TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, '');
-                //}
-                //console.log(stream.string);
-
-                var c = stream.peek();
-                var token_name;
-                if (c == '#') {
-                    token_name = 'comment';
-                //} else if (!stream.string.match(/^\s*[\d\.]+\s+\w/i)) {
-                } else if (!stream.string.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
-                    token_name = 'error';
-                } else {
-                    token_name = stream.skipToEnd();
-                }
-
-                //var ip = stream.string.match(/^[\d\.]+\s/);
-                //if (ip) {
-                //    token_name = 'positive';
-                //    stream.pos = ip[0].length - 1;
-                //}
-
-                //if (tw_pos === -1) {
-                //    stream.skipToEnd();
-                //} else {
-                //    stream.pos = tw_pos;
-                //}
+            var sol = stream.sol();
+            var ch = stream.next();
+
+            if (ch === '#') {
                 stream.skipToEnd();
+                return 'comment';
+            }
+            if (!stream.string.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
+                return 'error';
+            }
+
+            if (sol && ch.match(/[\w\.:%]/)) {
+                stream.eatWhile(/[\w\.:%]/);
+                return 'ip';
+            }
+
+            return null;
+        }
 
-                return token_name;
+        function tokenize(stream, state) {
+            return (state.tokens[0] || tokenBase)(stream, state);
+        }
+
+        return {
+            startState: function () {
+                return {tokens: []};
+            },
+            token: function (stream, state) {
+                return tokenize(stream, state);
             },
             lineComment: '#'
         };

+ 86 - 0
app/src/tt/hl.html

@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="UTF-8">
+	<title>hl</title>
+	<link rel="stylesheet" href="../../../node_modules/codemirror/lib/codemirror.css">
+	<link rel="stylesheet" href="../../../app/SH3/public/css/style.css">
+	<script src="../../../node_modules/codemirror/lib/codemirror.js"></script>
+</head>
+
+<body>
+
+<textarea name="" id="t" cols="30" rows="10">
+127.0.0.1 localhost
+	127.0.0.1 wfw afwef
+aaa
+bbb #bbb
+#cmt
+127.0.0.1 localhost
+255.255.255.255 broadcasthost
+::1 localhost
+fe80::1%lo0 localhost
+
+</textarea>
+
+<script src="hl.js"></script>
+<script>
+	CodeMirror.defineMode('tt', function () {
+
+		return {
+			startStat: function (base) {
+				return {
+					baseIndent: base || 0,
+					stack: []
+				}
+			},
+			token: function (stream, state) {
+				var tw_pos = stream.string.search(/[\t ]+?$/);
+
+				//if (!stream.sol() || tw_pos === 0) {
+				//    stream.skipToEnd();
+				//return ("error " + (TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, '');
+				//}
+				//console.log(stream.string);
+
+				var c = stream.peek();
+				var token_name;
+				if (c == '#') {
+					token_name = 'comment';
+					//} else if (!stream.string.match(/^\s*[\d\.]+\s+\w/i)) {
+				} else if (!stream.string.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
+					token_name = 'error';
+				} else {
+					token_name = stream.skipToEnd();
+				}
+
+				//var ip = stream.string.match(/^[\d\.]+\s/);
+				//if (ip) {
+				//    token_name = 'positive';
+				//    stream.pos = ip[0].length - 1;
+				//}
+
+				//if (tw_pos === -1) {
+				//    stream.skipToEnd();
+				//} else {
+				//    stream.pos = tw_pos;
+				//}
+				stream.skipToEnd();
+
+				return token_name;
+			}
+
+			,
+			lineComment: '#'
+		};
+	})
+	;
+
+	my_codemirror = CodeMirror.fromTextArea(document.getElementById('t'), {
+		lineNumbers: true,
+		readOnly: true,
+		mode: 'host'
+	});
+</script>
+</body>
+</html>

+ 58 - 0
app/src/tt/hl.js

@@ -0,0 +1,58 @@
+/**
+ * @author oldj
+ * @blog http://oldj.net
+ */
+
+'use strict';
+
+(function (mod) {
+    if (typeof exports == "object" && typeof module == "object") // CommonJS
+        mod(require("../../lib/codemirror"));
+    else if (typeof define == "function" && define.amd) // AMD
+        define(["../../lib/codemirror"], mod);
+    else // Plain browser env
+        mod(CodeMirror);
+})(function (CodeMirror) {
+    "use strict";
+
+    CodeMirror.defineMode('host', function () {
+        function tokenBase(stream) {
+            if (stream.eatSpace()) return null;
+
+            var sol = stream.sol();
+            var ch = stream.next();
+
+            if (ch === '#') {
+                stream.skipToEnd();
+                return 'comment';
+            }
+            if (!stream.string.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
+                return 'error';
+            }
+
+            if (sol && ch.match(/[\w\.:%]/)) {
+                stream.eatWhile(/[\w\.:%]/);
+                return 'ip';
+            }
+
+            return null;
+        }
+
+        function tokenize(stream, state) {
+            return (state.tokens[0] || tokenBase)(stream, state);
+        }
+
+        return {
+            startState: function () {
+                return {tokens: []};
+            },
+            token: function (stream, state) {
+                return tokenize(stream, state);
+            },
+            lineComment: '#'
+        };
+    });
+
+    CodeMirror.defineMIME('text/x-sh', 'shell');
+
+});

+ 0 - 2
app/src/ui.js

@@ -21,8 +21,6 @@ function resize() {
 
 function init(app) {
 
-
-
     $(document).ready(function () {
         var el_textarea = $('#host-code');
         //el_textarea.css('height', window.innerHeight - 8);

Some files were not shown because too many files changed in this diff