-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.html
executable file
·246 lines (214 loc) · 7.06 KB
/
test.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Code Highlighter 0.2</title>
<script type="text/javascript" src="CodeHighlighter.js"></script>
<script type="text/javascript" src="javascript.js"></script>
<script type="text/javascript" src="css.js"></script>
<script type="text/javascript" src="html.js"></script>
<style type="text/css">
body {
background : #EEE;
font-family: Arial, Helvetica, sans-serif;
margin : 3em 5em;
line-height : 1.5;
font-size: 80%;
}
pre {
border: 1px solid black;
border-color: #BBB #DDD #DDD #BBB;
margin : 2em;
padding : 1em;
line-height: 1.5;
background: white;
overflow: auto;
}
code {
font-size: 1.2em;
}
h1 span {
font-size : 0.5em;
}
a {
color : gray;
}
/* end of page css - below is for the code highlighter */
.javascript .comment {
color : green;
}
.javascript .string {
color : teal;
}
.javascript .keywords {
color : navy;
}
.javascript .global {
color : blue;
}
.javascript .brackets {
color : navy;
}
.css .comment {
color : gray;
}
.css .properties {
color : navy;
}
.css .selectors {
color : maroon;
font-weight : bold;
}
.css .units {
color :red;
}
.css .urls {
color :green;
}
.html .tag {
color : purple;
}
.html .comment {
color : gray;
font-style: italic;
}
.html .string {
color : navy;
}
.html .doctype {
color : teal;
}
</style>
</head>
<body>
<h1>CodeHighlighter 0.2 <span>by <a href="http://www.danwebb.net">Dan Webb</a></span></h1>
<p>CodeHighlighter is a lightweight, unobstrusive and fully configurable script for displaying code examples highlighted in a way similar to the way many text editors highlight code. It weighs in at just under 4K, allows users to configure their own style sets so that you can highlight any language you like and is deployable simply by attaching it to a page with the script tag and adding class names as hooks. It should also play nicely with any other scripts on your page as it has a tiny footprint on the global namespace.</p>
<p>Many thanks to <a href="http://dean.edwards.name">Dean Edwards</a> who's star-light behaviour inspired this.</p>
<h3>Deploying the script</h3>
<ol>
<li>Add a <script> tag for <a href="CodeHighlighter.js">CodeHighlighter.js</a> and a script tag for each of the code types you want to highlight on your page. At this time there are only very basic style sets for <a href="javascript.js">JavaScript</a>, <a href="css.js">CSS</a> and <a href="html.js">HTML</a>. But it's easy to make your own for any language you like if you know regular expressions. Let me know if you do and I'll link to them.</li>
<li>Add an appropriate class to each <pre> element that contains code. 'javascript', 'css' or 'html' will do the trick.</li>
<li>Define CSS styles for each code element, the script simply parses the code and wraps a <span> tag around each element with the appropriate class name. You just need to write CSS to style the code the way you want. No programming or weirdness required. See the source of this code as an example.</li>
</ol>
<h3>Testing</h3>
<p>Known to work on:</p>
<ul>
<li>IE 5.5+ PC</li>
<li>Firefox 1.0/Mozilla 1.3 + PC</li>
<li>Opera 7.23 + PC</li>
<li>Netscape 7.2 PC</li>
</ul>
<p>Known to degrade well on:</p>
<ul>
<li>IE 5.0 PC</li>
</ul>
<p>Any other feedback for any other browser would be greatly apprieciated. Please email Dan Webb at dan[at]danwebb[dot]net. Have a look through the small examples below.</p>
<h3>Creating your own style sets for other languages</h3>
<p>Have a look at this <a href="stylesetguide.htm">guide to creating style sets</a>.</p>
<p>Cheers,<br /><strong>Dan</strong></p>
<h2>Inline code</h2>
<p>Hopefully, you should be able to put some code inline like this: <code class="javascript">document.write("bong")</code> and hopefully it should work.</p>
<h2>JavaScript Example</h2>
<pre><code class="javascript">/*
This script detects external links in a page
and attaches a behaviour to them so they open
in a external window.
*/
function initialiseLinks() {
if (document.getElementsByTagName) {
var links = document.getElementsByTagName("A");
for (var i = 0; i < links.length; i++) {
if (links[i].href.indexOf("http:")==0) {
// if the links URL starts with http: then we assume it's an external link
links[i].onclick = function() {
window.open(this.href);
return false; // stop normal link behaviour
}
}
}
}
}
window.onload = initialiseLinks();</code></pre>
<h2>CSS Example</h2>
<pre><code class="css">.javascript .comment {
color : green; /* ffbgffg */
}
.javascript .string {
color : maroon;
}
.javascript .keywords {
font-weight : bold;
}
.javascript .global {
color : blue;
font-weight: bolder;
}
.javascript .brackets {
color : Gray;
}
.javascript .thing {
font-size : 10px;
background : url(ghgfhfg gh f.rtjhf);
}</code></pre>
<h2>HTML Example</h2>
<pre><code class="javascript">
function suckerfish(type, tag, parentId) {
if (window.attachEvent) {
window.attachEvent("onload", function() {
var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
type(sfEls);
});
}
}
sfHover = function(sfEls) {
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
sfFocus = function(sfEls) {
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onfocus=function() {
this.className+=" sffocus";
}
sfEls[i].onblur=function() {
this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
}
}
}
sfActive = function(sfEls) {
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmousedown=function() {
this.className+=" sfactive";
}
sfEls[i].onmouseup=function() {
this.className=this.className.replace(new RegExp(" sfactive\\b"), "");
}
}
}
sfTarget = function(sfEls) {
var aEls = document.getElementsByTagName("A");
document.lastTarget = null;
for (var i=0; i<sfEls.length; i++) {
if (sfEls[i].id) {
if (location.hash==("#" + sfEls[i].id)) {
sfEls[i].className+=" sftarget";
document.lastTarget=sfEls[i];
}
for (var j=0; j<aEls.length; j++) {
if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i];
aEls[j].onclick = function() {
if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
if (this.targetEl) this.targetEl.className+=" sftarget";
document.lastTarget=this.targetEl;
return true;
}
}
}
}
}</code></pre>
</body>
</html>