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,8 +95,8 @@ | ||
| 95 | pre { | 95 | pre { |
| 96 | padding:0; | 96 | padding:0; |
| 97 | margin:0; | 97 | margin:0; |
| 98 | - background:none; | ||
| 99 | border:none; | 98 | border:none; |
| 99 | + border-radius: 0; | ||
| 100 | } | 100 | } |
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| @@ -142,8 +142,8 @@ | @@ -142,8 +142,8 @@ | ||
| 142 | table-layout: fixed; | 142 | table-layout: fixed; |
| 143 | 143 | ||
| 144 | pre { | 144 | pre { |
| 145 | - background: none; | ||
| 146 | border: none; | 145 | border: none; |
| 146 | + border-radius: 0; | ||
| 147 | font-family: 'Menlo', 'Liberation Mono', 'Consolas', 'Courier New', 'andale mono','lucida console',monospace; | 147 | font-family: 'Menlo', 'Liberation Mono', 'Consolas', 'Courier New', 'andale mono','lucida console',monospace; |
| 148 | font-size: 12px !important; | 148 | font-size: 12px !important; |
| 149 | line-height: 16px !important; | 149 | line-height: 16px !important; |
app/assets/stylesheets/highlight/dark.scss
| 1 | -.black .lines .highlight { | ||
| 2 | - background: #333; | ||
| 3 | - pre { color: #eee; } | 1 | +.black .highlight { |
| 2 | + pre { | ||
| 3 | + background-color: #333; | ||
| 4 | + color: #eee; | ||
| 5 | + } | ||
| 4 | 6 | ||
| 5 | .hll { display: block; background-color: darken($hover, 65%) } | 7 | .hll { display: block; background-color: darken($hover, 65%) } |
| 6 | .c { color: #888888; font-style: italic } /* Comment */ | 8 | .c { color: #888888; font-style: italic } /* Comment */ |
app/assets/stylesheets/highlight/white.scss
| 1 | -.white .lines .highlight { | ||
| 2 | - background: white; | ||
| 3 | - pre { color: #333; } | 1 | +.white .highlight { |
| 2 | + pre { | ||
| 3 | + background-color: #fff; | ||
| 4 | + color: #333; | ||
| 5 | + } | ||
| 4 | 6 | ||
| 5 | .hll { display: block; background-color: $hover } | 7 | .hll { display: block; background-color: $hover } |
| 6 | .c { color: #888888; font-style: italic } /* Comment */ | 8 | .c { color: #888888; font-style: italic } /* Comment */ |
app/helpers/application_helper.rb
| @@ -126,6 +126,10 @@ module ApplicationHelper | @@ -126,6 +126,10 @@ module ApplicationHelper | ||
| 126 | Gitlab::Theme.css_class_by_id(current_user.try(:theme_id)) | 126 | Gitlab::Theme.css_class_by_id(current_user.try(:theme_id)) |
| 127 | end | 127 | end |
| 128 | 128 | ||
| 129 | + def user_color_scheme_class | ||
| 130 | + current_user.dark_scheme ? :black : :white | ||
| 131 | + end | ||
| 132 | + | ||
| 129 | def show_last_push_widget?(event) | 133 | def show_last_push_widget?(event) |
| 130 | event && | 134 | event && |
| 131 | event.last_push_to_non_root? && | 135 | event.last_push_to_non_root? && |
app/views/snippets/_blob.html.haml
| @@ -6,8 +6,7 @@ | @@ -6,8 +6,7 @@ | ||
| 6 | = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn very_small", target: "_blank" | 6 | = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn very_small", target: "_blank" |
| 7 | .file_content.code | 7 | .file_content.code |
| 8 | - unless @snippet.content.empty? | 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 | - else | 11 | - else |
| 13 | %p.nothing_here_message Empty file | 12 | %p.nothing_here_message Empty file |
app/views/tree/blob/_text.html.haml
| @@ -8,8 +8,7 @@ | @@ -8,8 +8,7 @@ | ||
| 8 | - else | 8 | - else |
| 9 | .file_content.code | 9 | .file_content.code |
| 10 | - unless blob.empty? | 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 | - else | 13 | - else |
| 15 | %p.nothing_here_message Empty file | 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,10 +12,12 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML | ||
| 12 | def block_code(code, language) | 12 | def block_code(code, language) |
| 13 | options = { options: {encoding: 'utf-8'} } | 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 | end | 21 | end |
| 20 | end | 22 | end |
| 21 | 23 |