diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 8f4d908d5a74ee311dbe738f01515eb58db53e1b..a689213bcee2e14ca52c29c9d95a4690e4a613f9 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 68a5f2bc5ece9d908130988bf66946f468d10a56..ed518300ac05615a7464406189c090c843df3101 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 37b0ff871b27e20f68ec6169a4a362d16e660288..122e275219d2f10a1c41ec6ff65851d6bf3e2d0e 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