Commit 7acd0604007da3ac8c56bbe3a07d8ee1692e6908
Exists in
master
and in
4 other branches
Merge pull request #2095 from riyad/fix-code-highlighting
Fix code highlighting
Showing
7 changed files
with
26 additions
and
18 deletions
Show diff stats
app/assets/stylesheets/gitlab_bootstrap/files.scss
| ... | ... | @@ -95,8 +95,8 @@ |
| 95 | 95 | pre { |
| 96 | 96 | padding:0; |
| 97 | 97 | margin:0; |
| 98 | - background:none; | |
| 99 | 98 | border:none; |
| 99 | + border-radius: 0; | |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | } |
| ... | ... | @@ -142,8 +142,8 @@ |
| 142 | 142 | table-layout: fixed; |
| 143 | 143 | |
| 144 | 144 | pre { |
| 145 | - background: none; | |
| 146 | 145 | border: none; |
| 146 | + border-radius: 0; | |
| 147 | 147 | font-family: 'Menlo', 'Liberation Mono', 'Consolas', 'Courier New', 'andale mono','lucida console',monospace; |
| 148 | 148 | font-size: 12px !important; |
| 149 | 149 | line-height: 16px !important; | ... | ... |
app/assets/stylesheets/highlight/dark.scss
app/assets/stylesheets/highlight/white.scss
app/helpers/application_helper.rb
| ... | ... | @@ -126,6 +126,10 @@ module ApplicationHelper |
| 126 | 126 | Gitlab::Theme.css_class_by_id(current_user.try(:theme_id)) |
| 127 | 127 | end |
| 128 | 128 | |
| 129 | + def user_color_scheme_class | |
| 130 | + current_user.dark_scheme ? :black : :white | |
| 131 | + end | |
| 132 | + | |
| 129 | 133 | def show_last_push_widget?(event) |
| 130 | 134 | event && |
| 131 | 135 | event.last_push_to_non_root? && | ... | ... |
app/views/snippets/_blob.html.haml
| ... | ... | @@ -6,8 +6,7 @@ |
| 6 | 6 | = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn very_small", target: "_blank" |
| 7 | 7 | .file_content.code |
| 8 | 8 | - unless @snippet.content.empty? |
| 9 | - %div{class: current_user.dark_scheme ? "black" : "white"} | |
| 10 | - :preserve | |
| 11 | - #{raw @snippet.colorize(formatter: :gitlab)} | |
| 9 | + %div{class: user_color_scheme_class} | |
| 10 | + = raw @snippet.colorize(formatter: :gitlab) | |
| 12 | 11 | - else |
| 13 | 12 | %p.nothing_here_message Empty file | ... | ... |
app/views/tree/blob/_text.html.haml
| ... | ... | @@ -8,8 +8,7 @@ |
| 8 | 8 | - else |
| 9 | 9 | .file_content.code |
| 10 | 10 | - unless blob.empty? |
| 11 | - %div{class: current_user.dark_scheme ? "black" : "white"} | |
| 12 | - = preserve do | |
| 13 | - = raw blob.colorize(formatter: :gitlab) | |
| 11 | + %div{class: user_color_scheme_class} | |
| 12 | + = raw blob.colorize(formatter: :gitlab) | |
| 14 | 13 | - else |
| 15 | 14 | %p.nothing_here_message Empty file | ... | ... |
lib/redcarpet/render/gitlab_html.rb
| ... | ... | @@ -12,10 +12,12 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML |
| 12 | 12 | def block_code(code, language) |
| 13 | 13 | options = { options: {encoding: 'utf-8'} } |
| 14 | 14 | |
| 15 | - if Pygments::Lexer.find(language) | |
| 16 | - Pygments.highlight(code, options.merge(lexer: language.downcase)) | |
| 17 | - else | |
| 18 | - Pygments.highlight(code, options) | |
| 15 | + h.content_tag :div, class: h.user_color_scheme_class do | |
| 16 | + if Pygments::Lexer.find(language) | |
| 17 | + Pygments.highlight(code, options.merge(lexer: language.downcase)) | |
| 18 | + else | |
| 19 | + Pygments.highlight(code, options) | |
| 20 | + end.html_safe | |
| 19 | 21 | end |
| 20 | 22 | end |
| 21 | 23 | ... | ... |