Skip to content

Commit

Permalink
Fix syntax highlighting of console commands
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDaugherty committed Dec 15, 2020
1 parent 24e9eca commit 7edd3a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/better_errors/error_page.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "cgi"
require "json"
require "securerandom"
require "rouge"
require "better_errors/error_page_style"

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

{
highlighted_input: CodeRay.scan(code, :ruby).div(wrap: nil),
highlighted_input: Rouge::Formatters::HTML.new.format(Rouge::Lexers::Ruby.lex(code)),
prefilled_input: prefilled_input,
prompt: prompt,
result: result
Expand Down
11 changes: 9 additions & 2 deletions lib/better_errors/style/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,20 @@ p.no-javascript-notice {
padding:0 12px;
}

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

@import "syntax_highlighting";
}
.code {
// For now, the syntax-highlighted console only supports light mode.
// Once the entire page has a dark theme, this should change.
@media (prefers-color-scheme: dark) {
@import "syntax_highlighting_dark";
}
}

.code {
margin-bottom: -1px;
border-top-left-radius:2px;
padding: 10px 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/better_errors/templates/main.erb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
self.writeOutput(response.error + "\n");
}
self.writeOutput(self._prompt + " ");
self.writeRawOutput(response.highlighted_input + "\n");
self.writeRawOutput("<span class='syntax-highlighted'>" + response.highlighted_input + "</span>\n");
self.writeOutput(response.result);
self.setPrompt(response.prompt);
self.setInput(response.prefilled_input);
Expand Down

0 comments on commit 7edd3a2

Please sign in to comment.