-
Notifications
You must be signed in to change notification settings - Fork 1
/
2013-05-30-语法高亮.html
170 lines (129 loc) · 4.14 KB
/
2013-05-30-语法高亮.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!-- Syntax highlighting demo
multiline comment -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<script src="highlight.js"></script>
<script src="lang-js.js"></script>
<script src="lang-xml.js"></script>
<script src="lang-html.js"></script>
<script src="lang-css.js"></script>
<script src="helpers.js"></script>
<script>
function doIt() {
var args = {
showWhitespace : document.getElementById("f_showWhitespace").checked,
lineNumbers : document.getElementById("f_lineNumbers").checked
};
DlHighlight.HELPERS.highlightByName('dlhl', "pre", args);
};
</script>
</head>
<body>
<h1>DlHighlight</h1>
<p>A JavaScript-based syntax highlighting engine.</p>
<p>
<button
onclick="doIt()">Highlight
all</button>
|
<label><input id="f_lineNumbers" type="checkbox" /> Line
numbers</label>
|
<label><input id="f_showWhitespace" type="checkbox" /> Show whitespace
in strings</label>
</p>
<h2>JavaScript</h2>
<pre name="dlhl" class="js">// single line comment
/*************
**
* multi-line
* comment containing
* an url: http://www.dynarch.com/
**
*************/
// ** Some code
// whitespace in strings can be displayed (check "Show whitespace
// in strings")
var str = "This string has some whitespace: foo bar baz";
// function names are bolded (gets "defun" class)
function Foo(name, age) {
this.name = name;
this.age = age;
};
// works also in this case:
Foo.prototype.getName = function() {
return this.name;
};
var f = new Foo("John", 20);
// ** Literal regexps
// regexp quotes (/) and modifiers (mg) are highlighted with a different style
test(/(^foo|bar)/mg, "foo");
// supports ", ', \ and / inside the regexp -- even Emacs messes this out ;)
if (/'foo\/bar"baz/.test("foo")) {
alert("match");
}
// ** Hashes
/**
* Hash keys are colored with a <span class="hashkey">different style</span>.
* They also can get additional styles depending on the context--for example,
* when the value is a function, the key name is bolded (gets "defun" class).
**/
var hash = {
foo : "bar",
five : 5,
word_regexp : /\b(\$?[a-z][a-z0-9]*)\b/ig,
doSomething : function () {
alert("blah");
}
};</pre>
<h2>CSS</h2>
<pre name="dlhl" class="css">/* General style */
.DlHighlight {
background-color: #eee;
border-left: 2px solid #0c0;
font: 10pt monospace;
padding: 10px;
margin-left: 3em;
}
.DlHighlight .keyword { color: #00f; font-weight: bold; }
.DlHighlight .builtin { color: #22c; }
.DlHighlight .string { color: #282; }
.DlHighlight .string .before, .DlHighlight .string .after { color: #040; }
.DlHighlight .regexp { color: #b2c; }
.DlHighlight .regexp .before, .DlHighlight .regexp .after { color: #509; font-weight: bold; }
.DlHighlight .comment { color: #c22; }
.DlHighlight .comment .before, .DlHighlight .comment .after { color: #baa; }
.DlHighlight .hashkey { color: #a51; }
.DlHighlight .hasharrow { color: #f00; }
.DlHighlight .paren { font-weight: bold; }
.DlHighlight .operator { color: #077; }
.DlHighlight .error { background-color: #c00; color: #fff; }
.DlHighlight .defun { font-weight: bold; }
.DlHighlight .line-numbers {
float: left;
margin-left: -4.5em;
width: 3em;
text-align: right;
color: #999;
font: 0.8em tahoma,verdana,sans-serif;
padding-top: 0.1em;
}
.DlHighlight .line-numbers:after { content: "." }
/* XML */
.DlHighlight .xml-tag-close .before { color: #52a; }
.DlHighlight .xml-entity { color: #b2a; }
.DlHighlight .xml-entity .before, .DlHighlight .xml-entity .after { color: #607; }
/* CSS */
.DlHighlight .css-class { color: #000; font-style: italic; }
.DlHighlight .css-pseudo-class { color: #777; }
.DlHighlight .css-id { font-weight: bold; }
.DlHighlight .css-color-spec { color: #a51; }
.DlHighlight .css-length { color: #a19; }
.DlHighlight .css-length .after { font-weight: bold; }
.DlHighlight .css-declaration-kw { font-weight: bold; }
.DlHighlight .css-comma { color: red; }</pre>
<h2>HTML</h2>
<pre name="dlhl" class="html"></pre>
</body>
</html>