From 184a9ecaf6cf25e429fe5653380e356b25a15a90 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Tue, 27 Nov 2012 22:49:22 +0100 Subject: [PATCH 1/3] Add user_color_scheme_class helper --- app/helpers/application_helper.rb | 4 ++++ app/views/snippets/_blob.html.haml | 5 ++--- app/views/tree/blob/_text.html.haml | 5 ++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8f4d908d..a689213b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -126,6 +126,10 @@ module ApplicationHelper Gitlab::Theme.css_class_by_id(current_user.try(:theme_id)) end + def user_color_scheme_class + current_user.dark_scheme ? :black : :white + end + def show_last_push_widget?(event) event && event.last_push_to_non_root? && diff --git a/app/views/snippets/_blob.html.haml b/app/views/snippets/_blob.html.haml index 68a5f2bc..ed518300 100644 --- a/app/views/snippets/_blob.html.haml +++ b/app/views/snippets/_blob.html.haml @@ -6,8 +6,7 @@ = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn very_small", target: "_blank" .file_content.code - unless @snippet.content.empty? - %div{class: current_user.dark_scheme ? "black" : "white"} - :preserve - #{raw @snippet.colorize(formatter: :gitlab)} + %div{class: user_color_scheme_class} + = raw @snippet.colorize(formatter: :gitlab) - else %p.nothing_here_message Empty file diff --git a/app/views/tree/blob/_text.html.haml b/app/views/tree/blob/_text.html.haml index 37b0ff87..122e2752 100644 --- a/app/views/tree/blob/_text.html.haml +++ b/app/views/tree/blob/_text.html.haml @@ -8,8 +8,7 @@ - else .file_content.code - unless blob.empty? - %div{class: current_user.dark_scheme ? "black" : "white"} - = preserve do - = raw blob.colorize(formatter: :gitlab) + %div{class: user_color_scheme_class} + = raw blob.colorize(formatter: :gitlab) - else %p.nothing_here_message Empty file From d2767221a5b566a7c476dba55d958d6062ea0733 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Tue, 27 Nov 2012 22:49:52 +0100 Subject: [PATCH 2/3] Fix code blocks in Markdown not knowing about the user's color scheme --- lib/redcarpet/render/gitlab_html.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb index 48b4da9d..bd590f92 100644 --- a/lib/redcarpet/render/gitlab_html.rb +++ b/lib/redcarpet/render/gitlab_html.rb @@ -12,10 +12,12 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML def block_code(code, language) options = { options: {encoding: 'utf-8'} } - if Pygments::Lexer.find(language) - Pygments.highlight(code, options.merge(lexer: language.downcase)) - else - Pygments.highlight(code, options) + h.content_tag :div, class: h.user_color_scheme_class do + if Pygments::Lexer.find(language) + Pygments.highlight(code, options.merge(lexer: language.downcase)) + else + Pygments.highlight(code, options) + end.html_safe end end From dc99b19af7d56644784bcf5edc4bd09112dd45a5 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Tue, 27 Nov 2012 22:50:24 +0100 Subject: [PATCH 3/3] Fix CSS for code highlighting --- app/assets/stylesheets/gitlab_bootstrap/files.scss | 4 ++-- app/assets/stylesheets/highlight/dark.scss | 8 +++++--- app/assets/stylesheets/highlight/white.scss | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/gitlab_bootstrap/files.scss b/app/assets/stylesheets/gitlab_bootstrap/files.scss index 4887d1c9..e4a36148 100644 --- a/app/assets/stylesheets/gitlab_bootstrap/files.scss +++ b/app/assets/stylesheets/gitlab_bootstrap/files.scss @@ -95,8 +95,8 @@ pre { padding:0; margin:0; - background:none; border:none; + border-radius: 0; } } } @@ -142,8 +142,8 @@ table-layout: fixed; pre { - background: none; border: none; + border-radius: 0; font-family: 'Menlo', 'Liberation Mono', 'Consolas', 'Courier New', 'andale mono','lucida console',monospace; font-size: 12px !important; line-height: 16px !important; diff --git a/app/assets/stylesheets/highlight/dark.scss b/app/assets/stylesheets/highlight/dark.scss index 0996cc77..398d8145 100644 --- a/app/assets/stylesheets/highlight/dark.scss +++ b/app/assets/stylesheets/highlight/dark.scss @@ -1,6 +1,8 @@ -.black .lines .highlight { - background: #333; - pre { color: #eee; } +.black .highlight { + pre { + background-color: #333; + color: #eee; + } .hll { display: block; background-color: darken($hover, 65%) } .c { color: #888888; font-style: italic } /* Comment */ diff --git a/app/assets/stylesheets/highlight/white.scss b/app/assets/stylesheets/highlight/white.scss index d6792b37..2a43e9f6 100644 --- a/app/assets/stylesheets/highlight/white.scss +++ b/app/assets/stylesheets/highlight/white.scss @@ -1,6 +1,8 @@ -.white .lines .highlight { - background: white; - pre { color: #333; } +.white .highlight { + pre { + background-color: #fff; + color: #333; + } .hll { display: block; background-color: $hover } .c { color: #888888; font-style: italic } /* Comment */