This repository was archived by the owner on Apr 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 886
Expand file tree
/
Copy pathprettify_test.html
More file actions
1462 lines (1260 loc) · 34.2 KB
/
prettify_test.html
File metadata and controls
1462 lines (1260 loc) · 34.2 KB
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Code Prettifier</title>
<script type="text/javascript" src="prettify_test.js"></script>
<script type="text/javascript" src="test_base.js"></script>
<link rel="stylesheet" type="text/css" href="test_styles.css">
<script type="text/javascript">
(function () {
// keep track of when window.onload fires, this is to make sure that we dont
// miss it as it might occur before or after dynamic scripts are loaded
var isReady = false;
window.onload = function () { isReady = true; };
// run tests when page is fully loaded
function onReady() {
runTests(goldens);
}
// JS & CSS prettify files to load
var base = /[&?]loader\b/.test(location.search) ? '../loader/' : '../src/';
var sources = [
'lang-css.js',
'lang-erlang.js',
'lang-go.js',
'lang-hs.js',
'lang-lisp.js',
'lang-lua.js',
'lang-ml.js',
'lang-proto.js',
'lang-rust.js',
'lang-scala.js',
'lang-sql.js',
'lang-vb.js',
'lang-vhdl.js',
'lang-wiki.js',
'lang-yaml.js',
'lang-ini.js'
];
var styles = [
'prettify.css'
];
// load skin(s)
while (styles.length) {
injectCSS(base + styles.shift());
}
// first load prettify.js
injectJS(base + 'prettify.js', function () {
// then load all lang-*.js concurrently
while (sources.length) {
injectJS(base + sources.shift(),
(sources.length) ? undefined : function () {
// then after last one is loaded, run tests when page is ready
// (piggyback on window.onload if it hasn't already fired)
if (isReady) {
onReady();
} else {
window.onload = onReady;
}
});
}
});
})();
</script>
</head>
<body>
<h1>Test Results</h1>
<div id="report"></div>
<hr>
<h1>Bash</h1>
<pre class="prettyprint" id="bash">#!/bin/bash
# Fibonacci numbers
# Writes an infinite series to stdout, one entry per line
function fib() {
local a=1
local b=1
while true ; do
echo $a
local tmp=$a
a=$(( $a + $b ))
b=$tmp
done
}
# output the 10th element of the series and halt
fib | head -10 | tail -1
</pre>
<h1>Bash w/ language specified</h1>
<pre class="prettyprint lang-sh linenums" id="bash_lang">#!/bin/bash
# Fibonacci numbers
# Writes an infinite series to stdout, one entry per line
function fib() {
local a=1
local b=1
while true ; do
echo $a
local tmp=$a
a=$(( $a + $b ))
b=$tmp
done
}
# output the 10th element of the series and halt
fib | /usr/bin/*head -10 | tail -1
</pre>
<h1>Bash special characters</h1>
<p><a href="https://github.com/google/code-prettify/issues/165">Issue #165</a></p>
<pre class="prettyprint lang-sh" id="issue_165"># Comment
local $x = ${#x[@]} # Previous is not a comment
# A comment</pre>
<h1>C</h1>
<pre class="prettyprint" id="c">
#include <stdio.h>
/* the n-th fibonacci number.
*/
unsigned int fib(unsigned int n) {
unsigned int a = 1, b = 1;
unsigned int tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
main() {
printf("%u", fib(10));
}
</pre>
<h1>C w/ language specified</h1>
<pre class="prettyprint lang-c" id="c_lang">
#include <stdio.h>
/* the n<sup>th</sup> fibonacci number. */
uint32 fib(unsigned int n) {
uint32 a = 1, b = 1;
uint32 tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
void main() {
size_t size = sizeof(wchar_t);
ASSERT_EQ(size, 1);
printf("%u", fib(10));
}
#define ZERO 0 /* a
multiline comment */
</pre>
<h1>C++</h1>
<pre class="prettyprint" id="cpp">
#include <iostream>
using namespace std;
//! fibonacci numbers with gratuitous use of templates.
//! \param n an index into the fibonacci series
//! \param fib0 element 0 of the series
//! \return the nth element of the fibonacci series
template <class T>
T fib(unsigned int n, const T& fib0) {
T a(fib0), b(fib0);
for (; n; --n) {
T tmp(a);
a += b;
b = tmp;
}
return a;
}
int main(int argc, char **argv) {
cout << fib(10, 1U);
}
</pre>
<h1>C++ w/ language specified</h1>
<pre class="prettyprint lang-cc" id="cpp_lang">
#include <iostream>
using namespace std;
//! fibonacci numbers with gratuitous use of templates.
//! \param n an index into the fibonacci series
//! \param fib0 element 0 of the series
//! \return the nth element of the fibonacci series
template <class T>
T fib(int n, const T& fib0) {
T a(fib0), b(fib0);
while (--n >= 0) {
T tmp(a);
a += b;
b = tmp;
}
return a;
}
int main(int argc, char **argv) {
cout << fib(10, 1U);
}
</pre>
<h1>Java</h1>
<pre class="prettyprint" id="java">
package foo;
import java.util.Iterator;
/**
* the fibonacci series implemented as an Iterable.
*/
public final class Fibonacci implements Iterable<Integer> {
/** the next and previous members of the series. */
private int a = 1, b = 1;
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
/** the series is infinite. */
public boolean hasNext() { return true; }
public Integer next() {
int tmp = a;
a += b;
b = tmp;
return a;
}
public void remove() { throw new UnsupportedOperationException(); }
};
}
/**
* the n<sup>th</sup> element of the given series.
* @throws NoSuchElementException if there are less than n elements in the
* given Iterable's {@link Iterable#iterator iterator}.
*/
public static <T>
T nth(int n, Iterable<T> iterable) {
Iterator<? extends T> it = iterable.iterator();
while (--n > 0) {
it.next();
}
return it.next();
}
public static void main(String[] args) {
System.out.print(nth(10, new Fibonacci()));
}
}
</pre>
<h1>Java w/ language specified</h1>
<p>(first line shown is line 12)</p>
<pre class="prettyprint lang-java linenums:12" id="java_lang">
package foo;
import java.util.Iterator;
/**
* the fibonacci series implemented as an Iterable.
*/
public final class Fibonacci implements Iterable<Integer> {
/** the next and previous members of the series. */
private int a = 1, b = 1;
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
/** the series is infinite. */
public boolean hasNext() { return true; }
public Integer next() {
int tmp = a;
a += b;
b = tmp;
return a;
}
public void remove() { throw new UnsupportedOperationException(); }
};
}
/**
* the n<sup>th</sup> element of the given series.
* @throws NoSuchElementException if there are less than n elements in the
* given Iterable's {@link Iterable#iterator iterator}.
*/
public static <T>
T nth(int n, Iterable<T> iterable) {
Iterator<? extends T> in = iterable.iterator();
while (--n > 0) {
in.next();
}
return in.next();
}
public static void main(String[] args) {
System.out.print(nth(10, new Fibonacci()));
}
}
# not a java comment
# not keywords: static_cast and namespace
</pre>
<h1>JavaScript</h1>
<pre class="prettyprint" id="javascript">
/**
* nth element in the fibonacci series.
* @param n >= 0
* @return the nth element, >= 0.
*/
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.write(fib(10));
</pre>
<h1>JavaScript Regular Expressions</h1>
<p><a href="https://github.com/google/code-prettify/issues/12">Issue #12</a></p>
<pre class="prettyprint" id="js_regexp">
/foo/; // a slash starting a line treated as a regexp beginning
"foo".match(/fo+$/);
// this line comment not treated as a regular expressions
"foo /bar/".test(/"baz"/); // test string and regexp boundaries
var division = /\b\d+\/\d+/g; // test char sets and escaping of specials
var allSpecials = /([^\(\)\[\]\{\}\-\?\+\*\.\^\$\/]+)\\/;
var slashInCharset = /[^/]/g, notCloseSq = /[^\]]/;
// test that slash used in numeric context treated as an operator
1 / 2;
1. / x;
x / y;
(x) / y;
1 /* foo */ / 2;
1 /* foo *// 2;
1/2;
1./x;
x/y;
(x)/y;
// test split over two lines. line comment should not fool it
1//
/2;
x++/y;
x--/y;
x[y] / z;
f() / n;
// test that slash after non postfix operator is start of regexp
log('matches = ' + /foo/.test(foo));
// test keyword preceders
return /a regexp/;
division = notreturn / not_a_regexp / 2; // keyword suffix does not match
// & not used as prefix operator in javascript but this should still work
&/foo/;
extends = /extends/;
</pre>
<h1>JavaScript Regular Expressions w/ language specified</h1>
<p><a href="https://github.com/google/code-prettify/issues/12">Issue #12</a></p>
<pre class="prettyprint lang-js" id="js_regexp_lang">
/foo/; // a slash starting a line treated as a regexp beginning
"foo".match(/fo+$/);
// this line comment not treated as a regular expressions
"foo /bar/".test(/"baz"/); // test string and regexp boundaries
var division = /\b\d+\/\d+/g; // test char sets and escaping of specials
var allSpecials = /([^\(\)\[\]\{\}\-\?\+\*\.\^\$\/]+)\\/;
var slashInCharset = /[^/]/g, notCloseSq = /[^\]]/;
// test that slash used in numeric context treated as an operator
1 / 2;
1. / x;
x / y;
(x) / y;
1 /* foo */ / 2;
1 /* foo *// 2;
1/2;
1./x;
x/y;
(x)/y;
// test split over two lines. line comment should not fool it
1//
/2;
x++/y;
x--/y;
x[y] / z;
f() / n;
// test that slash after non postfix operator is start of regexp
log('matches = ' + /foo/.test(foo));
// test keyword preceders
return /a regexp/;
division = notreturn / not_a_regexp / 2; // keyword suffix does not match
// & not used as prefix operator in javascript but this should still work
&/foo/;
extends = /extends/;
</pre>
<h1>CoffeeScript</h1>
<pre class="prettyprint lang-coffee" id="coffee">
class Animal
constructor: (@name) ->
move: (meters, loc) ->
alert @name + " moved " + meters + "m."
travel: (path...) ->
for place in path
@move place.distance, place.location
class Horse extends Animal
###
@param name Horse name
@param jumper Jumping ability
###
constructor: (name, jumper) ->
super name
@capable = jumper
step: ->
alert '''
Step,
step...
'''
jump: ->
@capable
move: (meters, where) ->
switch where
when "ground"
@step()
super meters
when "hurdle"
super meters if @jump()
# Create horse
tom = new Horse "Tommy", yes
street =
location: "ground"
distance: 12
car =
location: "hurdle"
distance: 2
###
Tell him to travel:
1. through the street
2. over the car
###
tom.travel street, car
</pre>
<h1>Perl</h1>
<pre class="prettyprint" id="perl">
#!/usr/bin/perl
use strict;
use integer;
# the nth element of the fibonacci series
# param n - an int >= 0
# return an int >= 0
sub fib($) {
my $n = shift, $a = 1, $b = 1;
($a, $b) = ($a + $b, $a) until (--$n < 0);
return $a;
}
print fib(10);
</pre>
<h1>Python</h1>
<pre class="prettyprint" id="python">
#!/usr/bin/python2.4
def fib():
'''
a generator that produces the elements of the fibonacci series
'''
a = 1
b = 1
while True:
a, b = a + b, a
yield a
def nth(series, n):
'''
returns the nth element of a series,
consuming the earlier elements of the series
'''
for x in series:
n = n - 1
if n <= 0: return x
print nth(fib(), 10)
</pre>
<h1>Python w/ language specified</h1>
<pre class="prettyprint lang-py" id="python_lang">
#!/usr/bin/python2.4
def fib():
'''
a generator that produces the fibonacci series's elements
'''
a = 1
b = 1
while True:
a, b = a + b, a
yield a
def nth(series, n):
'''
returns the nth element of a series,
consuming the series' earlier elements.
'''
for x in series:
n -= 1
if n <= 0: return x
print nth(fib(), 10)
/* not a comment and not keywords: null char true */
</pre>
<h1>SQL</h1>
<pre class="prettyprint lang-sql" id="sql_lang">
/* A multi-line
* comment */
'Another string /* Isn\'t a comment',
"A string */"
-- A line comment
SELECT * FROM users WHERE id IN (1, 2.0, +30e-1);
-- keywords are case-insensitive.
-- Note: user-table is a single identifier, not a pair of keywords
select * from user-table where id in (x, y, z);
</pre>
<h1>XML</h1>
<pre class="prettyprint" id="xml">
<!DOCTYPE series PUBLIC "fibonacci numbers">
<series.root base="1" step="s(n-2) + s(n-1)">
<element i="0">1</element>
<element i="1">1</element>
<element i="2">2</element>
<element i="3">3</element>
<element i="4">5</element>
<element i="5">8</element>
...
</series.root>
</pre>
<h1>HTML</h1>
<pre class="prettyprint" id="html">
<html>
<head>
<title>Fibonacci number</title>
<style><!-- BODY { text-decoration: blink } --></style>
<script src="foo.js"></script>
<script src="bar.js"></script>
</head>
<body>
<noscript>
<dl>
<dt>Fibonacci numbers</dt>
<dd>1</dd>
<dd>1</dd>
<dd>2</dd>
<dd>3</dd>
<dd>5</dd>
<dd>8</dd>
&hellip;
</dl>
</noscript>
<script type="text/javascript"><!--
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.writeln(fib(10));
// -->
</script>
</body>
</html>
</pre>
<h1>HTML w/ language specified</h1>
<pre class="prettyprint lang-html" id="html_lang">
Fibonacci Numbers
<noscript>
<dl style="list-style: disc">
<dt>Fibonacci numbers</dt>
<dd>1</dd>
<dd>1</dd>
<dd>2</dd>
<dd>3</dd>
<dd>5</dd>
<dd>8</dd>
&hellip;
</dl>
</noscript>
<script type="text/javascript"><!--
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.writeln(fib(10));
// -->
</script>
</pre>
<h1>HTML using <XMP></h1>
<xmp class="prettyprint" id="html_xmp"
><html>
<head>
<title>Fibonacci number</title>
</head>
<body>
<noscript>
<dl>
<dt>Fibonacci numbers</dt>
<dd>1</dd>
<dd>1</dd>
<dd>2</dd>
<dd>3</dd>
<dd>5</dd>
<dd>8</dd>
…
</dl>
</noscript>
<script type="text/javascript"><!--
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.writeln(fib(10));
// -->
</script>
</body>
</html>
</xmp>
<h1>XHTML</h1>
<pre class="prettyprint" id="xhtml"
><xhtml>
<head>
<title>Fibonacci number</title>
</head>
<body onload="alert(fib(10))">
<script type="text/javascript"><![CDATA[
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
]]>
</script>
</body>
</xhtml>
</pre>
<h1>PHP</h1>
<pre class="prettyprint" id="php">
<html>
<head>
<title><?= 'Fibonacci numbers' ?></title>
<?php
// PHP has a plethora of comment types
/* What is a
"plethora"? */
function fib($n) {
# I don't know.
$a = 1;
$b = 1;
while (--$n >= 0) {
echo "$a\n";
$tmp = $a;
$a += $b;
$b = $tmp;
}
}
?>
</head>
<body>
<?= fib(10) ?>
</body>
</html>
</pre>
<h1>XSL</h1>
<p><a href="https://github.com/google/code-prettify/issues/19">Issue #19</a></p>
<pre class="prettyprint" id="xsl">
<!-- Test elements and attributes with namespaces -->
<xsl:stylesheet xml:lang="en">
<xsl:template match=".">
<xsl:text>Hello World</xsl:text>
</xsl:template>
</xsl:stylesheet>
</pre>
<h1>Whitespace</h1>
<pre class="prettyprint" id="whitespace"></pre>
<h1>Misc</h1>
<pre class="prettyprint" id="misc1">// ends with line comment token
//</pre>
<h1>JavaScript inside HTML <SCRIPT></h1>
<p>
<a href="https://github.com/google/code-prettify/issues/4">Issue #4</a>:
JavaScript Snippets wrapped in HTML SCRIPT tags hides/destroys inner content
</p>
<p>The fact that the script tag was not closed properly was causing
<em>PR_splitSourceNodes</em> to end without emitting the script contents.</p>
<pre class="prettyprint" id="js_script">
<script type="text/javascript">
var savedTarget=null; // The target layer (effectively vidPane)
var orgCursor=null; // The original mouse style so we can restore it
var dragOK=false; // True if we're allowed to move the element under mouse
var dragXoffset=0; // How much we've moved the element on the horozontal
var dragYoffset=0; // How much we've moved the element on the verticle
vidPaneID = document.getElementById('vidPane'); // Our movable layer
vidPaneID.style.top='75px'; // Starting location horozontal
vidPaneID.style.left='75px'; // Starting location verticle
<script>
</pre>
<h1>Tabs mangled</h1>
<p><a href="https://github.com/google/code-prettify/issues/8">Issue #8</a>:
If tabs are used to indent code inside <pre>, IE6 and 7 won't honor them
after the script runs.</p>
<p>Code indented with tabs will be shown aligned to the left margin instead of
the proper indenting shown in Firefox.</p>
<p>I'm using Revision 20 of prettify.js, IE 6.0.29.00 in English and IE
7.0.5730.11 in Spanish.</p>
<pre class="prettyprint" id="issue8">
<b>one</b>	<b>Two</b>	<b>three</b>	Four	<b>five</b>	|
Six	<b>seven</b>	Eight	nine	Ten	|
<b>eleven</b>	Twelve	<b>thirteen</b>	Fourteen	fifteen	|
</pre>
<h1>Does not recognize <code><br></code> as newline</h1>
<p><a href="https://github.com/google/code-prettify/issues/14">Issue #14</a></p>
<pre class="prettyprint" id="issue14a"
>//comment<br />int main(int argc, char **argv)
{}</pre>
<h1>Comments not ignored</h1>
<p><a href="https://github.com/google/code-prettify/issues/14">Issue #14</a></p>
<pre class="prettyprint" id="issue14b"
><!-- There's an <!-- BOO!! --><acronym title="tag soup">HTML</acronym> comment in my comment -->
<p>And another one inside the end tag</p<!-- GOTCHA!! -->>
</pre>
<h1>Missing blank lines</h1>
<p><a href="https://github.com/google/code-prettify/issues/20">Issue #20</a></p>
<pre class="prettyprint" id="issue20"
><html>
<head></pre>
<h1>Code doesn't copy and paste well in IE</h1>
<p><a href="https://github.com/google/code-prettify/issues/21">Issue #21</a>:
To test this bug, disable overriding of <em>_pr_isIE6</em> in test_base.js
by putting <em>#testcopypaste</em> on the end of the URL and reloading the
page, then copy and paste the above into Notepad.</p>
<pre class="prettyprint" id="issue21"
><html>
<head>
<title>Test</title>
</head>
</html></pre>
<h1>Line numbers and other non-code spans in code</h1>
<p><a href="https://github.com/google/code-prettify/issues/22">Issue #22</a></p>
<pre class="prettyprint lang-java" id="issue22"
><span class="nocode">01: </span>// This is a line of code
<span class="nocode">02: </span>/* Multiline comments can
<span class="nocode">03: </span> * span over and around
<span class="nocode">04: </span> * line markers
<span class="nocode annot">And can even be interrupted</span>
<span class="nocode annot">by inline code annotations</span>
<span class="nocode">05: </span> */
<span class="nocode">06: </span>class MyClass extends Foo {
<span class="nocode">07: </span> public static void main(String... argv) {
<span class="nocode">08: </span> System.out.print("Hello World");
<span class="nocode">09: </span> }
<span class="nocode">10: </span>}</pre>
<h1>Lua</h1>
<p><a href="https://github.com/google/code-prettify/issues/24">Issue #24</a></p>
<pre class="prettyprint lang-lua" id="lua">
os=require("os")
math=require("math")
-- Examples from the language reference
a = 'alo\n123"'
a = "alo\n123\""
a = '\97lo\10\04923"'
a = [[alo
123"]]
a = [==[
alo
123"]==]
3 3.0 3.1416 314.16e-2 0.31416E1 0xff 0x56
-- Some comments that demonstrate long brackets
double_quoted = "Not a long bracket [=["
--[=[ quoting out
[[ foo ]]
[==[does not end comment either]==]
]=]
past_end_of_comment
--]=]
-- Example code courtesy Joseph Harmbruster
#
do
local function ssgeneral(t, n, before)
for _, h in ipairs(incs) do
for i = h + 1, n do
local v = t[i]
for j = i - h, 1, -h do
local testval = t[j]
if not before(v, testval) then break end
t[i] = testval; i = j
end
t[i] = v
end
end
return t
end
function shellsort(t, before, n)
n = n or #t
if not before or before == "<" then return ssup(t, n)
elseif before == ">" then return ssdown(t, n)
else return ssgeneral(t, n, before)
end
end
return shellsort
end</pre>
<h1>VBScript</h1>
<p><a href="https://github.com/google/code-prettify/issues/27">Issue #27</a></p>
<pre class="prettyprint lang-vb" id="vbs">
Imports System
Class [class]
Shared Sub [shared](ByVal [boolean] As Boolean)
If [boolean] Then
Console.WriteLine("true")
Else
Console.WriteLine("false")
End If
End Sub
End Class
' Comment
‘ Second Line comment with a smart quote _
continued line using VB6 syntax.
Module [module]
Sub Main()
[class].[shared](True)
' This prints out: ".
Console.WriteLine("""")
' This prints out: a"b.
Console.WriteLine("a""b")
' This prints out: a.
Console.WriteLine("a"c)
' This prints out: ".
Console.WriteLine(""""c)
REM an old-style comment
REMOVE(not_a_comment)
End Sub
End Module
Dim d As Date
d = # 8/23/1970 3:45:39AM #
d = # 8/23/1970 #
d = # 3:45:39AM #
d = # 3:45:39 #
d = # 13:45:39 #
d = # 13:45:39PM #
Dim n As Float
n = (0.0, .99F, 1.0E-2D, 1.0E+3D, .5E4, 1E3R, 4D)
Dim i As Integer
i = (0, 123, 45L, &HA0I, &O177S)
</pre>
<h1>Haskell</h1>
<p><a href="https://github.com/google/code-prettify/issues/30">Issue #30</a></p>
<pre class="prettyprint lang-hs" id="haskell">
-- A comment
Not(--"a comment")
Also.not(--(A.comment))
module Foo(bar) where
import Blah
import BlahBlah(blah)
import Monads(Exception(..), FIO(..),unFIO,handle,runFIO,fixFIO,fio,
write,writeln,HasNext(..),HasOutput(..))
{- nested comments
- don't work {-yet-} -}
instance Thingy Foo where
a = b
data Foo :: (* -> * -> *) -> * > * -> * where
Nil :: Foo a b c
Cons :: a b c -> Foo abc -> Foo a b c
str = "Foo\\Bar"
char = 'x'
Not.A.Char = 'too long' -- Don't barf. Show that 't is a lexical error.
(ident, ident', Fo''o.b'ar)
(0, 12, 0x45, 0xA7, 0o177, 0O377, 0.1, 1.0, 1e3, 0.5E-3, 1.0E+45)
</pre>
<h1>OCaml and F#</h1>
<p><a href="https://github.com/google/code-prettify/issues/33">Issue #33</a></p>
<p>TODO: handle nested <code>(* (* comments *) *)</code> properly.</p>