Skip to content

Commit a8fde08

Browse files
Use classes for syntax highlighting
1 parent a52d063 commit a8fde08

File tree

4 files changed

+143
-2
lines changed

4 files changed

+143
-2
lines changed

lib/better_errors/code_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def each_line_of(lines, &blk)
4242
end
4343

4444
def highlighted_lines
45-
CodeRay.scan(context_lines.join, coderay_scanner).div(wrap: nil).lines
45+
CodeRay.scan(context_lines.join, coderay_scanner).html(css: :class).lines
4646
end
4747

4848
def context_lines

lib/better_errors/code_formatter/html.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def source_unavailable
88
def formatted_lines
99
each_line_of(highlighted_lines) { |highlight, current_line, str|
1010
class_name = highlight ? "highlight" : ""
11-
sprintf '<pre class="%s">%s</pre>', class_name, str
11+
sprintf '<pre class="CodeRay %s">%s</pre>', class_name, str
1212
}
1313
end
1414

lib/better_errors/style/main.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,3 +719,5 @@ nav.sidebar:hover::-webkit-scrollbar-thumb {
719719
.code:hover::-webkit-scrollbar-thumb {
720720
background: #888;
721721
}
722+
723+
@import "syntax_highlighting";
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
.CodeRay {
2+
// background-color: #FFF;
3+
// border: 1px solid #CCC;
4+
// font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
5+
color: #000;
6+
// padding: 1em 0px 1em 1em;
7+
8+
&span { white-space: pre; border: 0px; padding: 2px }
9+
10+
&table {
11+
border-collapse: collapse;
12+
width: 100%;
13+
padding: 2px
14+
td {
15+
padding: 1em 0.5em;
16+
vertical-align: top;
17+
}
18+
}
19+
20+
pre {
21+
margin: 0px;
22+
}
23+
24+
.line-numbers, .no {
25+
background-color: #ECECEC;
26+
color: #AAA;
27+
text-align: right;
28+
}
29+
30+
.line-numbers a {
31+
color: #AAA;
32+
}
33+
34+
.line-numbers tt { font-weight: bold }
35+
.line-numbers .highlighted { color: red }
36+
.line { display: block; float: left; width: 100%; }
37+
span.line-numbers { padding: 0px 4px }
38+
.code { width: 100% }
39+
40+
&ol {
41+
font-size: 10pt;
42+
li {
43+
white-space: pre
44+
}
45+
}
46+
47+
.code pre { overflow: auto }
48+
.debug { color:white ! important; background:blue ! important; }
49+
50+
.annotation { color:#007 }
51+
.attribute-name { color:#f08 }
52+
.attribute-value { color:#700 }
53+
.binary { color:#509; font-weight:bold }
54+
.comment { color:#998; font-style: italic;}
55+
.char { color:#04D }
56+
.char .content { color:#04D }
57+
.char .delimiter { color:#039 }
58+
.class { color:#458; font-weight:bold }
59+
.complex { color:#A08; font-weight:bold }
60+
.constant { color:teal; }
61+
.color { color:#0A0 }
62+
.class-variable { color:#369 }
63+
.decorator { color:#B0B; }
64+
.definition { color:#099; font-weight:bold }
65+
.directive { color:#088; font-weight:bold }
66+
.delimiter { color:black }
67+
.doc { color:#970 }
68+
.doctype { color:#34b }
69+
.doc-string { color:#D42; font-weight:bold }
70+
.escape { color:#666; font-weight:bold }
71+
.entity { color:#800; font-weight:bold }
72+
.error { color:#F00; background-color:#FAA }
73+
.exception { color:#C00; font-weight:bold }
74+
.filename { color:#099; }
75+
.function { color:#900; font-weight:bold }
76+
.global-variable { color:teal; font-weight:bold }
77+
.hex { color:#058; font-weight:bold }
78+
.integer { color:#099; }
79+
.include { color:#B44; font-weight:bold }
80+
.inline { color: black }
81+
.inline .inline { background: #ccc }
82+
.inline .inline .inline { background: #bbb }
83+
.inline .inline-delimiter { color: #D14; }
84+
.inline-delimiter { color: #D14; }
85+
.important { color:#f00; }
86+
.interpreted { color:#B2B; font-weight:bold }
87+
.instance-variable { color:teal }
88+
.label { color:#970; font-weight:bold }
89+
.local-variable { color:#963 }
90+
.octal { color:#40E; font-weight:bold }
91+
.operator { }
92+
.predefined-constant { font-weight:bold }
93+
.predefined { color:#369; font-weight:bold }
94+
.preprocessor { color:#579; }
95+
.pseudo-class { color:#00C; font-weight:bold }
96+
.predefined-type { color:#074; font-weight:bold }
97+
.reserved, .keyword { color:#000; font-weight:bold }
98+
99+
.key { color: #808; }
100+
.key .delimiter { color: #606; }
101+
.key .char { color: #80f; }
102+
.value { color: #088; }
103+
104+
.regexp { background-color:#fff0ff }
105+
.regexp .content { color:#808 }
106+
.regexp .delimiter { color:#404 }
107+
.regexp .modifier { color:#C2C }
108+
.regexp .function { color:#404; font-weight: bold }
109+
110+
.string { color: #D20; }
111+
.string .string { }
112+
.string .string .string { background-color:#ffd0d0 }
113+
.string .content { color: #D14; }
114+
.string .char { color: #D14; }
115+
.string .delimiter { color: #D14; }
116+
117+
.shell { color:#D14 }
118+
.shell .content { }
119+
.shell .delimiter { color:#D14 }
120+
121+
.symbol { color:#990073 }
122+
.symbol .content { color:#A60 }
123+
.symbol .delimiter { color:#630 }
124+
125+
.tag { color:#070 }
126+
.tag-special { color:#D70; font-weight:bold }
127+
.type { color:#339; font-weight:bold }
128+
.variable { color:#036 }
129+
130+
.insert { background: #afa; }
131+
.delete { background: #faa; }
132+
.change { color: #aaf; background: #007; }
133+
.head { color: #f8f; background: #505 }
134+
135+
.insert .insert { color: #080; font-weight:bold }
136+
.delete .delete { color: #800; font-weight:bold }
137+
.change .change { color: #66f; }
138+
.head .head { color: #f4f; }
139+
}

0 commit comments

Comments
 (0)