diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-01-27 13:12:58 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-01-27 13:12:58 +0200 |
commit | 78b2fb5de9d96390110f469d057a2081be34a69b (patch) | |
tree | c5979da58891523b996597e475ed5a359817973f | |
parent | ffee5bb090c3723bb57e6858d32e9c34baba9912 (diff) | |
download | gitlab-ce-78b2fb5de9d96390110f469d057a2081be34a69b.tar.gz |
Add highlight.js support to markdown, snippets etc
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r-- | app/assets/stylesheets/application.scss | 1 | ||||
-rw-r--r-- | app/assets/stylesheets/generic/files.scss | 62 | ||||
-rw-r--r-- | app/assets/stylesheets/generic/highlight.scss | 61 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 10 | ||||
-rw-r--r-- | app/views/projects/blob/_text.html.haml | 12 | ||||
-rw-r--r-- | app/views/projects/snippets/_blob.html.haml | 3 | ||||
-rw-r--r-- | app/views/shared/_file_hljs.html.haml | 11 | ||||
-rw-r--r-- | app/views/snippets/_blob.html.haml | 3 | ||||
-rw-r--r-- | doc/raketasks/user_management.md | 4 | ||||
-rw-r--r-- | lib/redcarpet/render/gitlab_html.rb | 12 |
10 files changed, 93 insertions, 86 deletions
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 7d766c305d4..cc5fdf61405 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -39,6 +39,7 @@ @import "generic/lists.scss"; @import "generic/forms.scss"; @import "generic/selects.scss"; +@import "generic/highlight.scss"; /** * Page specific styles (issues, projects etc): diff --git a/app/assets/stylesheets/generic/files.scss b/app/assets/stylesheets/generic/files.scss index 8dc3932bf42..20877507c91 100644 --- a/app/assets/stylesheets/generic/files.scss +++ b/app/assets/stylesheets/generic/files.scss @@ -143,68 +143,6 @@ */ &.code { padding: 0; - - .highlighted-data { - border: none; - box-shadow: none; - margin: 0px; - padding: 0px; - table-layout: fixed; - - pre { - border: none; - border-radius: 0; - font-family: $monospace_font; - font-size: 12px !important; - line-height: 16px !important; - margin: 0; - - code { - white-space: pre; - word-wrap: normal; - } - } - - .hljs { - padding: 0; - } - - .line-numbers { - padding: 10px; - text-align: right; - float: left; - width: 60px; - - a { - font-family: $monospace_font; - display: block; - font-size: 12px !important; - line-height: 16px !important; - - i { - display: none; - } - - &:hover i { - display: inline; - } - } - } - - .highlight { - overflow: auto; - overflow-y: hidden; - - pre { - white-space: pre; - word-wrap: normal; - - .line { - padding: 0 10px; - } - } - } - } } } } diff --git a/app/assets/stylesheets/generic/highlight.scss b/app/assets/stylesheets/generic/highlight.scss new file mode 100644 index 00000000000..80b49c61209 --- /dev/null +++ b/app/assets/stylesheets/generic/highlight.scss @@ -0,0 +1,61 @@ +.highlighted-data { + border: none; + box-shadow: none; + margin: 0px; + padding: 0px; + table-layout: fixed; + + pre { + border: none; + border-radius: 0; + font-family: $monospace_font; + font-size: 12px !important; + line-height: 16px !important; + margin: 0; + + code { + white-space: pre; + word-wrap: normal; + } + } + + .hljs { + padding: 0; + } + + .line-numbers { + padding: 10px; + text-align: right; + float: left; + width: 60px; + + a { + font-family: $monospace_font; + display: block; + font-size: 12px !important; + line-height: 16px !important; + + i { + display: none; + } + + &:hover i { + display: inline; + } + } + } + + .highlight { + overflow: auto; + overflow-y: hidden; + + pre { + white-space: pre; + word-wrap: normal; + + .line { + padding: 0 10px; + } + } + } +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e60cba2bb2b..036f4a5ba28 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -203,8 +203,14 @@ module ApplicationHelper def highlight_js(&block) string = capture(&block) - content_tag :div, class: user_color_scheme_class do - Pygments::Lexer[:js].highlight(string).html_safe + content_tag :div, class: "highlighted-data #{user_color_scheme_class}" do + content_tag :div, class: 'highlight' do + content_tag :pre do + content_tag :code do + string.html_safe + end + end + end end end diff --git a/app/views/projects/blob/_text.html.haml b/app/views/projects/blob/_text.html.haml index d0c9a09dd40..080a39ab944 100644 --- a/app/views/projects/blob/_text.html.haml +++ b/app/views/projects/blob/_text.html.haml @@ -8,16 +8,6 @@ - else .file-content.code - unless blob.empty? - %div.highlighted-data{class: user_color_scheme_class} - .line-numbers - - blob.data.lines.size.times do |index| - - i = index + 1 - = link_to "#L#{i}", id: "L#{i}", rel: "#L#{i}" do - %i.icon-link - = i - .highlight - %pre - %code - = raw blob.data + = render 'shared/file_hljs', blob: blob - else %p.nothing_here_message Empty file diff --git a/app/views/projects/snippets/_blob.html.haml b/app/views/projects/snippets/_blob.html.haml index f14a2bd4ec0..088eb5c08ca 100644 --- a/app/views/projects/snippets/_blob.html.haml +++ b/app/views/projects/snippets/_blob.html.haml @@ -9,7 +9,6 @@ = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" .file-content.code - unless @snippet.content.empty? - %div{class: user_color_scheme_class} - = raw @snippet.colorize(formatter: :gitlab) + = render 'shared/file_hljs', blob: @snippet - else %p.nothing_here_message Empty file diff --git a/app/views/shared/_file_hljs.html.haml b/app/views/shared/_file_hljs.html.haml new file mode 100644 index 00000000000..f50185a5c0c --- /dev/null +++ b/app/views/shared/_file_hljs.html.haml @@ -0,0 +1,11 @@ +%div.highlighted-data{class: user_color_scheme_class} + .line-numbers + - blob.data.lines.size.times do |index| + - i = index + 1 + = link_to "#L#{i}", id: "L#{i}", rel: "#L#{i}" do + %i.icon-link + = i + .highlight + %pre + %code + = raw blob.data diff --git a/app/views/snippets/_blob.html.haml b/app/views/snippets/_blob.html.haml index e6ae33f38f3..4b571b4ba3a 100644 --- a/app/views/snippets/_blob.html.haml +++ b/app/views/snippets/_blob.html.haml @@ -18,8 +18,7 @@ = render_markup(@snippet.file_name, @snippet.data) - else .file-content.code - %div{class: user_color_scheme_class} - = raw @snippet.colorize(formatter: :gitlab) + = render 'shared/file_hljs', blob: @snippet - else .file-content.code %p.nothing_here_message Empty file diff --git a/doc/raketasks/user_management.md b/doc/raketasks/user_management.md index 8fa2ed1311c..9884c9c0fe3 100644 --- a/doc/raketasks/user_management.md +++ b/doc/raketasks/user_management.md @@ -1,6 +1,6 @@ ### Add user as a developer to all projects -``` +```bash bundle exec rake gitlab:import:user_to_projects[username@domain.tld] ``` @@ -11,6 +11,6 @@ Notes: * admin users are added as masters -``` +```bash bundle exec rake gitlab:import:all_users_to_all_projects ``` diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb index 2d1e0aec5e5..b3e8ed2ade5 100644 --- a/lib/redcarpet/render/gitlab_html.rb +++ b/lib/redcarpet/render/gitlab_html.rb @@ -12,10 +12,6 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML end def block_code(code, language) - options = { options: {encoding: 'utf-8'} } - lexer = Pygments::Lexer.find(language) # language can be an alias - options.merge!(lexer: lexer.aliases[0].downcase) if lexer # downcase is required - # New lines are placed to fix an rendering issue # with code wrapped inside <h1> tag for next case: # @@ -25,7 +21,13 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML # <<-HTML - <div class="#{h.user_color_scheme_class}">#{Pygments.highlight(code, options)}</div> +<div class="highlighted-data #{h.user_color_scheme_class}"> + <div class="highlight"> + <pre> + <code class="#{language}">#{code}</code> + </pre> + </div> +</div> HTML end |