summaryrefslogtreecommitdiff
path: root/includes/js/dojox/highlight/tests/test_highlight.html
blob: 93b15340fd6bf25fc108590f980554fb879da404 (plain)
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE html>
<head>
	<title>dojox.highlight - syntax highlighting | The Dojo Toolkit</title>
	<style type="text/css">
		@import "../../../dijit/tests/css/dijitTests.css";

		/* a sample set of definitions to use as a foundation to color your code */
		@import "../resources/highlight.css";

		/* additional styling for this test case */
		pre code[class]:after {
		  content: 'highlight: ' attr(class);
		  display: block; text-align: right;
		  font-size: smaller;
		  color: #CCC; background: white;
		  border-top: solid 1px;
		  padding-top: 0.5em;
		}
		
		pre code {
		  display: block;
		}
		
		code {
		  background: #F0F0F0;
		}
		
		pre code, 
		.ruby .subst {
		  color: black;
		}
	</style>

	<script type="text/javascript" djConfig="parseOnLoad: true, isDebug: true" src="../../../dojo/dojo.js"></script>
	<script type="text/javascript" src="../_base.js"></script>

	<script type="text/javascript">
		// initHighlightOnLoad is deprecated.
		// if parseOnLoad==true, the onLoad init stuff is run.
		// if parseOnLoad==false, you can call dojox.highlight.init(domNode)
		// 
		// utilizing the dojo build system, the dojox.highlight engine
		// will "do it's best" based on the language maps available
		// at the time of construction.
		//
		dojo.require("dojox.highlight");

		// several layer-like files have been provided grouping
		// similar langauges, and a catch all language module
		// dojox.highlight.languages._all is available for "best results"

		// we need some language definitions:		
		dojo.require("dojox.highlight.languages._all");
		//dojo.require("dojox.highlight.languages._static");
		//dojo.require("dojox.highlight.languages._dynamic");
		//dojo.require("dojox.highlight.languages._www");

		var lazyCode = function(){
			
			dojo.query("code").forEach(dojox.highlight.init);
			
			dojo.xhrGet({
				url: "../../../dojo/_base.js",
				load: function(data){
					var n = dojo.byId("foobar"),
						c = document.createElement('div'),
						e = n.parentNode.parentNode;
					c.innerHTML = '<pre><code class="javascript">' + data.replace(/\</gi,"&lt;") + '</code></pre>';
					e.replaceChild(c.firstChild, n.parentNode);
					dojo.query("pre > code", e).forEach(dojox.highlight.init);
				}
			});
		};	
		dojo.addOnLoad(lazyCode); 

	</script>
</head>
<body>

<h1 class="testTitle">dojox.highlight</h1>

<p>client-side syntax highlighting for a number of languages.</p>

<p><em>NOTE:</em> All languages listed here have working language definitions, though
not all exist in the release or dojo subversion. The missing packs are not publically available.
<span style="display:none">based on</span>
</p>

<h2>Examples:</h2>

<p>Some Python code:</p>

<pre><code>@requires_authorization
def somefunc(param1, param2):
  '''A docstring'''
  if param1 > param2: # interesting
    print 'Gre\'ater'
    print ''
  return param2 - param1 + 1
  
class SomeClass:<br>    pass
</code></pre>
<!--

<p>Short sample of Ruby:</p>
	FIXME: example needed
-->

<!--

	<p>A bit of Perl:</p>
	 FIXME: example needed
-->

<p>A chunk of PHP: </p>

<pre><code class="php">
$opAr = array (    "-a|--append", // a or append toggle, nothing extra
        "-i|--input:", // i or input with next input being needed
        "-l|--list:",           // l with input needed
		//"--foo",     // broken
        "-f:",           // f with no input
        "--wot:"      // wot with input, no short
        );


$op = bgetop($opAr);
if (is_array($op)) { print_r($op); }

/* here is the code: */

function bgetop($opAr=array(),$unknown=true) {

$argv = $_SERVER['argv'];
$argc = $_SERVER['argc'];
$argPos = 1; // zero is program running

// foreach arg
while ($argPos&lt;$argc) {
    $arg = $argv[$argPos];
    if ($arg{0}=="-") {
        if ($arg{1}=="-") {
        $var = substr($arg,2,strlen($arg));
        } else { $var = $arg{1}; }
        foreach ($opAr as $opk => $opv) {
            if (!isset($return[$var])) {
            if (strpos($opv,$arg) !== FALSE) {
                // this is where the -f -foo fix needs to be,
                // the partial string exists in this record,
                // but we need to determine if it's accurate
                // somehow (i'm thinking: eregi?)
                if ($accurate=1) {
                    // we foudn the key
                    if (strpos($opv,':') !== FALSE) {
                        // next value is the one to use,
                        // then skip it in the parser.
                        if (isset($argv[$argPos+1])) {
                            $return[$var] = $argv[++$argPos];
                            } else {
                            $return[$var] = FALSE;     
                            }
                        } else {
                        // just set the toggle
                        $return[$var] = TRUE;
                        }
                    // don't check this opAr value again
                    unset($opAr[$opk]);
                    }
                } // if accurate
            } // !isset already
            } // foreach opAr    
    } else { // we weren't expecting a non-hyphened argument, possibly just a filename, or whatnot
        if ($unknown) { $return['unknown'][]=$arg; }
    }
    $argPos++;
} // while argPos < argc

if (is_array($return)) {
return $return;
} else { return 0; }

} // end function bgetop

</code></pre>

<p>A custom XML document:</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;response value="ok"&gt;
  &lt;text&gt;Ok&lt;/text&gt;
  &lt;comment/&gt;
  &lt;ns:description&gt;&lt;![CDATA[ 
  CDATA is &lt;not&gt; magical. 
  ]]&gt;&lt;/ns:description&gt;
&lt;/response&gt;
</code></pre>

<p>Some HTML code:</p>

<pre><code>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
&lt;body&gt;
  &lt;p class="something"&gt;Something&lt;/p&gt;
  &lt;p class=something&gt;Something&lt;/p&gt;
  &lt;!-- comment --&gt;
  &lt;p class&gt;Something&lt;/p&gt;
  &lt;p class="something" title="p"&gt;Something&lt;/p&gt;
&lt;/body&gt;
</code></pre>

<p>HTML with Django templates:</p>

<pre><code>{% if articles|length %}
{% for article in articles %}

{# Striped table #}
&lt;tr class="{% cycle odd,even %}"&gt;
  &lt;td&gt;{{ article|default:"Hi... "|escape }}&lt;/td&gt;
  &lt;td&gt;{{ article.date|date:"d.m.Y" }}&lt;/td&gt;
&lt;/tr&gt;
  
{% endfor %}
{% endif %}

{% comment %}
Comments may be long and
multiline.
{% endcomment %}
</code></pre>

<p>Some CSS code:</p>

<pre><code>body, 
html {
  font: Tahoma, Arial, san-serif;
}

#content {
  width: 100%; /* css comment */
  height: 100%
}

p[lang=ru] {
  color: red;
}
</pre></code>

<p>Explicit Python highlight:</p>

<pre><code class="python">for x in [1, 2, 3]:
  count(x)
</code></pre>

<p>Disabled highlighting:</p>

<pre><code class="no-highlight">&lt;div id="contents"&gt;
  &lt;p&gt;Hello, World!
&lt;/div&gt;
</code></pre>

<p>Normal dojo-looking code</p>

<pre><code>
dojo.provide("some.object");
dojo.declare("some.object",null,{
	param: "value",
	_myMethod: function(/* Event */e){
		this.inherited(arguments);
	},
	// comments
	_another: function(){
		dojo.addClass("foo","hovered");
	}
});
dojo.addOnLoad(function(){
	//
	// comments with &lt;HTML&gt; inline
	var d = dojo;
	d.mixin(d,{
		foo: function(e){
			d.bar(e);
		},
		bar: function(e){
			alert(e);
		}
	});
});
</code></pre>

<p>Lazy, xhr'd code:</p>

<pre><code id="foobar"></code></pre>

<hr>

<p>Text with inlined JavaScript code: <code class="javascript">dojo.forEach(a, function(x){ console.log(x); });</code> &mdash; that was the inlined sample.</p>

<hr>

<p>Markuped code (python), no language was specified:</p>

<pre><code dojoType="dojo.highlight.Code">@requires_authorization
def somefunc(param1, param2):
  '''A docstring'''
  if param1 > param2: # interesting
    print 'Gre\'ater'
    print ''
  return param2 - param1 + 1
  
class SomeClass:<br>    pass
</code></pre>

<p>Markuped code, "python" was specified:</p>

<pre><code dojoType="dojo.highlight.Code" class="python">@requires_authorization
def somefunc(param1, param2):
  '''A docstring'''
  if param1 > param2: # interesting
    print 'Gre\'ater'
    print ''
  return param2 - param1 + 1
  
class SomeClass:<br>    pass
</code></pre>


</body><html>