Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 819298e

Browse files
Applied Nicholas Curry's patch for IE7 newlines to fix issue 104
1 parent 25f6d69 commit 819298e

File tree

3 files changed

+175
-5
lines changed

3 files changed

+175
-5
lines changed

src/lang-scala.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2010 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
/**
17+
* @fileoverview
18+
* Registers a language handler for Scala.
19+
*
20+
* Derived from http://lampsvn.epfl.ch/svn-repos/scala/scala-documentation/trunk/src/reference/SyntaxSummary.tex
21+
*
22+
23+
*/
24+
25+
PR.registerLangHandler(
26+
PR.createSimpleLexer(
27+
[
28+
// Whitespace
29+
[PR.PR_PLAIN, /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
30+
// A double or single quoted string
31+
// or a triple double-quoted multi-line string.
32+
[PR.PR_STRING,
33+
/^(?:"(?:(?:""(?:""?(?!")|[^\\"]|\\.)*"{0,3})|(?:[^"\r\n\\]|\\.)*"?))/,
34+
null, '"'],
35+
[PR.PR_LITERAL, /^`(?:[^\r\n\\`]|\\.)*`?/, null, '`'],
36+
[PR.PR_PUNCTUATION, /^[!#%&()*+,\-:;<=>?@\[\\\]^{|}~]+/, null,
37+
'!#%&()*+,-:;<=>?@[\\]^{|}~']
38+
],
39+
[
40+
// A symbol literal is a single quote followed by an identifier with no
41+
// single quote following
42+
// A character literal has single quotes on either side
43+
[PR.PR_STRING, /^'(?:[^\r\n\\']|\\(?:'|[^\r\n']+))'/],
44+
[PR.PR_LITERAL, /^'[a-zA-Z_$][\w$]*(?!['$\w])/],
45+
[PR.PR_KEYWORD, /^(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|object|override|package|private|protected|requires|return|sealed|super|throw|trait|try|type|val|var|while|with|yield)\b/],
46+
[PR.PR_LITERAL, /^(?:true|false|null|this)\b/],
47+
[PR.PR_LITERAL, /^(?:(?:0(?:[0-7]+|X[0-9A-F]+))L?|(?:(?:0|[1-9][0-9]*)(?:(?:\.[0-9]+)?(?:E[+\-]?[0-9]+)?F?|L?))|\\.[0-9]+(?:E[+\-]?[0-9]+)?F?)/i],
48+
// Treat upper camel case identifiers as types.
49+
[PR.PR_TYPE, /^[$_]*[A-Z][_$A-Z0-9]*[a-z][\w$]*/],
50+
[PR.PR_PLAIN, /^[$a-zA-Z_][\w$]*/],
51+
[PR.PR_COMMENT, /^\/(?:\/.*|\*(?:\/|\**[^*/])*(?:\*+\/?)?)/],
52+
[PR.PR_PUNCTUATION, /^(?:\.+|\/)/]
53+
]),
54+
['scala']);

src/prettify.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,8 @@ window['_pr_isIE6'] = function () {
10961096
// on IE.
10971097
// Doing this on other browsers breaks lots of stuff since \r\n is
10981098
// treated as two newlines on Firefox.
1099-
? (isIE678 === 6 ? '&#160;\r\n' : '&#160;\r')
1099+
? (isIE678 === 6 ? '&#160;\r\n' :
1100+
isIE678 === 7 ? '&#160;<br>\r' : '&#160;\r')
11001101
// IE collapses multiple adjacent <br>s into 1 line break.
11011102
// Prefix every newline with '&#160;' to prevent such behavior.
11021103
// &nbsp; is the same as &#160; but works in XML as well as HTML.
@@ -1360,8 +1361,7 @@ window['_pr_isIE6'] = function () {
13601361
recombineTagsAndDecorations(job);
13611362
} catch (e) {
13621363
if ('console' in window) {
1363-
console['log'](e);
1364-
console['trace']();
1364+
console['log'](e && e['stack'] ? e['stack'] : e);
13651365
}
13661366
}
13671367
}

tests/prettify_test.html

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
onerror="alert('Error: failed to load ' + this.src)"></script>
2727
<script src="../src/lang-yaml.js" type="text/javascript"
2828
onerror="alert('Error: failed to load ' + this.src)"></script>
29+
<script src="../src/lang-scala.js" type="text/javascript"
30+
onerror="alert('Error: failed to load ' + this.src)"></script>
2931
<script src="test_base.js" type="text/javascript"
3032
onerror="alert('Error: failed to load ' + this.src)"></script>
3133
<link rel="stylesheet" type="text/css" href="../src/prettify.css" />
@@ -1163,6 +1165,65 @@ <h1>YAML mode</h1>
11631165
]
11641166
: !!str "value"
11651167
}</pre>
1168+
1169+
<h1>Scala mode</h1>
1170+
<pre class="prettyprint lang-scala" id="scala">
1171+
/* comment 1 */
1172+
/*
1173+
comment 2
1174+
*/
1175+
/* comment / * comment 3 **/
1176+
// strings
1177+
"Hello, World!", "\n",
1178+
`an-identifier`, `\n`,
1179+
'A', '\n',
1180+
'aSymbol,
1181+
"""Hello,
1182+
World""", """Hello,\nWorld""",
1183+
"""Hello, "World"!""",
1184+
"""Hello, \"World\""""
1185+
1186+
// Numbers
1187+
0
1188+
0123
1189+
0xa0
1190+
0XA0L
1191+
123
1192+
123.45
1193+
1.50F
1194+
0.50
1195+
.50
1196+
123e-1
1197+
123.45e+1
1198+
1.50e2
1199+
0.50e-6
1200+
.50e+42f
1201+
1202+
// Values
1203+
false, true, null, this;
1204+
1205+
// Keywords
1206+
class MyClass;
1207+
import foo.bar;
1208+
package baz;
1209+
1210+
// From scala-lang.org/node/242
1211+
def act() {
1212+
var pongCount = 0
1213+
loop {
1214+
react {
1215+
case Ping =>
1216+
if (pongCount % 1000 == 0)
1217+
Console.println("Pong: ping "+pongCount)
1218+
sender ! Pong
1219+
pongCount = pongCount + 1
1220+
case Stop =>
1221+
Console.println("Pong: stop")
1222+
exit()
1223+
}
1224+
}
1225+
}
1226+
</pre>
11661227
</body>
11671228

11681229
<script type="text/javascript">
@@ -2626,7 +2687,7 @@ <h1>YAML mode</h1>
26262687
'&nbsp; &nbsp; &nbsp;`END`KWDinit_params:<br>' +
26272688
'`END`PLN&nbsp; &nbsp; &nbsp; &nbsp;`END`KWDlogType: `END`PLNspecial<br>' +
26282689
'&nbsp; `END',
2629-
yaml2: '`DEC%YAML 1.1`END`PLN<br>' +
2690+
yaml2: '`DEC%YAML 1.1`END`PLN<br>' +
26302691
'`END`DEC---<br>' +
26312692
'`END`TYP!!map`END`PLN {<br>' +
26322693
'&nbsp; `END`PUN?`END`PLN `END`TYP!!str`END`PLN `END`STR""`END`PLN<br>' +
@@ -2641,7 +2702,62 @@ <h1>YAML mode</h1>
26412702
'&nbsp; &nbsp; `END`TYP!!str`END`PLN `END`STR"key"`END`PLN<br>' +
26422703
'&nbsp; ]<br>' +
26432704
'&nbsp; `END`PUN:`END`PLN `END`TYP!!str`END`PLN `END`STR"value"`END`PLN<br>' +
2644-
'}`END'
2705+
'}`END',
2706+
scala: '`COM/* comment 1 */`END`PLN<br>' +
2707+
'`END`COM/*<br>' +
2708+
'comment 2<br>' +
2709+
'*/`END`PLN<br>' +
2710+
'`END`COM/* comment / * comment 3 **/`END`PLN<br>' +
2711+
'`END`COM// strings`END`PLN<br>' +
2712+
'`END`STR"Hello, World!"`END`PUN,`END`PLN `END`STR"\\n"`END`PUN,`END`PLN<br>' +
2713+
'`END`LIT`an-identifier``END`PUN,`END`PLN `END`LIT`\\n``END`PUN,`END`PLN<br>' +
2714+
'`END`STR\'A\'`END`PUN,`END`PLN `END`STR\'\\n\'`END`PUN,`END`PLN<br>' +
2715+
'`END`LIT\'aSymbol`END`PUN,`END`PLN<br>' +
2716+
'`END`STR"""Hello,<br>' +
2717+
'World"""`END`PUN,`END`PLN `END`STR"""Hello,\\nWorld"""`END`PUN,`END`PLN<br>' +
2718+
'`END`STR"""Hello, "World"!"""`END`PUN,`END`PLN<br>' +
2719+
'`END`STR"""Hello, \\"World\\""""`END`PLN<br>' +
2720+
'<br>' +
2721+
'`END`COM// Numbers`END`PLN<br>' +
2722+
'`END`LIT0`END`PLN<br>' +
2723+
'`END`LIT0123`END`PLN<br>' +
2724+
'`END`LIT0xa0`END`PLN<br>' +
2725+
'`END`LIT0XA0L`END`PLN<br>' +
2726+
'`END`LIT123`END`PLN<br>' +
2727+
'`END`LIT123.45`END`PLN<br>' +
2728+
'`END`LIT1.50F`END`PLN<br>' +
2729+
'`END`LIT0.50`END`PLN<br>' +
2730+
'`END`PUN.`END`LIT50`END`PLN<br>' +
2731+
'`END`LIT123e-1`END`PLN<br>' +
2732+
'`END`LIT123.45e+1`END`PLN<br>' +
2733+
'`END`LIT1.50e2`END`PLN<br>' +
2734+
'`END`LIT0.50e-6`END`PLN<br>' +
2735+
'`END`PUN.`END`LIT50e+42f`END`PLN<br>' +
2736+
'<br>' +
2737+
'`END`COM// Values`END`PLN<br>' +
2738+
'`END`LITfalse`END`PUN,`END`PLN `END`LITtrue`END`PUN,`END`PLN `END`LITnull`END`PUN,`END`PLN `END`LITthis`END`PUN;`END`PLN<br>' +
2739+
'<br>' +
2740+
'`END`COM// Keywords`END`PLN<br>' +
2741+
'`END`KWDclass`END`PLN `END`TYPMyClass`END`PUN;`END`PLN<br>' +
2742+
'`END`KWDimport`END`PLN foo`END`PUN.`END`PLNbar`END`PUN;`END`PLN<br>' +
2743+
'`END`KWDpackage`END`PLN baz`END`PUN;`END`PLN<br>' +
2744+
'<br>' +
2745+
'`END`COM// From scala-lang.org/node/242`END`PLN<br>' +
2746+
'`END`KWDdef`END`PLN act`END`PUN()`END`PLN `END`PUN{`END`PLN<br>' +
2747+
'&nbsp; `END`KWDvar`END`PLN pongCount `END`PUN=`END`PLN `END`LIT0`END`PLN<br>' +
2748+
'&nbsp; loop `END`PUN{`END`PLN<br>' +
2749+
'&nbsp; &nbsp; react `END`PUN{`END`PLN<br>' +
2750+
'&nbsp; &nbsp; &nbsp; `END`KWDcase`END`PLN `END`TYPPing`END`PLN `END`PUN=&gt;`END`PLN<br>' +
2751+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`KWDif`END`PLN `END`PUN(`END`PLNpongCount `END`PUN%`END`PLN `END`LIT1000`END`PLN `END`PUN==`END`PLN `END`LIT0`END`PUN)`END`PLN<br>' +
2752+
'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `END`TYPConsole`END`PUN.`END`PLNprintln`END`PUN(`END`STR"Pong: ping "`END`PUN+`END`PLNpongCount`END`PUN)`END`PLN<br>' +
2753+
'&nbsp; &nbsp; &nbsp; &nbsp; sender `END`PUN!`END`PLN `END`TYPPong`END`PLN<br>' +
2754+
'&nbsp; &nbsp; &nbsp; &nbsp; pongCount `END`PUN=`END`PLN pongCount `END`PUN+`END`PLN `END`LIT1`END`PLN<br>' +
2755+
'&nbsp; &nbsp; &nbsp; `END`KWDcase`END`PLN `END`TYPStop`END`PLN `END`PUN=&gt;`END`PLN<br>' +
2756+
'&nbsp; &nbsp; &nbsp; &nbsp; `END`TYPConsole`END`PUN.`END`PLNprintln`END`PUN(`END`STR"Pong: stop"`END`PUN)`END`PLN<br>' +
2757+
'&nbsp; &nbsp; &nbsp; &nbsp; exit`END`PUN()`END`PLN<br>' +
2758+
'&nbsp; &nbsp; `END`PUN}`END`PLN<br>' +
2759+
'&nbsp; `END`PUN}`END`PLN<br>' +
2760+
'`END`PUN}`END'
26452761
};
26462762
</script>
26472763

0 commit comments

Comments
 (0)