Skip to content

Commit 7edd3a2

Browse files
Fix syntax highlighting of console commands
1 parent 24e9eca commit 7edd3a2

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/better_errors/error_page.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "cgi"
22
require "json"
33
require "securerandom"
4+
require "rouge"
45
require "better_errors/error_page_style"
56

67
module BetterErrors
@@ -158,7 +159,7 @@ def eval_and_respond(index, code)
158159
result, prompt, prefilled_input = @repls[index].send_input(code)
159160

160161
{
161-
highlighted_input: CodeRay.scan(code, :ruby).div(wrap: nil),
162+
highlighted_input: Rouge::Formatters::HTML.new.format(Rouge::Lexers::Ruby.lex(code)),
162163
prefilled_input: prefilled_input,
163164
prompt: prompt,
164165
result: result

lib/better_errors/style/main.scss

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,20 @@ p.no-javascript-notice {
507507
padding:0 12px;
508508
}
509509

510-
.code {
511-
@import "syntax_highlighting";
510+
.code, .be-console .syntax-highlighted {
511+
text-shadow: none;
512512

513+
@import "syntax_highlighting";
514+
}
515+
.code {
516+
// For now, the syntax-highlighted console only supports light mode.
517+
// Once the entire page has a dark theme, this should change.
513518
@media (prefers-color-scheme: dark) {
514519
@import "syntax_highlighting_dark";
515520
}
521+
}
516522

523+
.code {
517524
margin-bottom: -1px;
518525
border-top-left-radius:2px;
519526
padding: 10px 0;

lib/better_errors/templates/main.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
self.writeOutput(response.error + "\n");
250250
}
251251
self.writeOutput(self._prompt + " ");
252-
self.writeRawOutput(response.highlighted_input + "\n");
252+
self.writeRawOutput("<span class='syntax-highlighted'>" + response.highlighted_input + "</span>\n");
253253
self.writeOutput(response.result);
254254
self.setPrompt(response.prompt);
255255
self.setInput(response.prefilled_input);

0 commit comments

Comments
 (0)