Commit 78b2fb5de9d96390110f469d057a2081be34a69b
1 parent
ffee5bb0
Exists in
spb-stable
and in
3 other branches
Add highlight.js support to markdown, snippets etc
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
10 changed files
with
93 additions
and
86 deletions
Show diff stats
app/assets/stylesheets/application.scss
app/assets/stylesheets/generic/files.scss
... | ... | @@ -143,68 +143,6 @@ |
143 | 143 | */ |
144 | 144 | &.code { |
145 | 145 | padding: 0; |
146 | - | |
147 | - .highlighted-data { | |
148 | - border: none; | |
149 | - box-shadow: none; | |
150 | - margin: 0px; | |
151 | - padding: 0px; | |
152 | - table-layout: fixed; | |
153 | - | |
154 | - pre { | |
155 | - border: none; | |
156 | - border-radius: 0; | |
157 | - font-family: $monospace_font; | |
158 | - font-size: 12px !important; | |
159 | - line-height: 16px !important; | |
160 | - margin: 0; | |
161 | - | |
162 | - code { | |
163 | - white-space: pre; | |
164 | - word-wrap: normal; | |
165 | - } | |
166 | - } | |
167 | - | |
168 | - .hljs { | |
169 | - padding: 0; | |
170 | - } | |
171 | - | |
172 | - .line-numbers { | |
173 | - padding: 10px; | |
174 | - text-align: right; | |
175 | - float: left; | |
176 | - width: 60px; | |
177 | - | |
178 | - a { | |
179 | - font-family: $monospace_font; | |
180 | - display: block; | |
181 | - font-size: 12px !important; | |
182 | - line-height: 16px !important; | |
183 | - | |
184 | - i { | |
185 | - display: none; | |
186 | - } | |
187 | - | |
188 | - &:hover i { | |
189 | - display: inline; | |
190 | - } | |
191 | - } | |
192 | - } | |
193 | - | |
194 | - .highlight { | |
195 | - overflow: auto; | |
196 | - overflow-y: hidden; | |
197 | - | |
198 | - pre { | |
199 | - white-space: pre; | |
200 | - word-wrap: normal; | |
201 | - | |
202 | - .line { | |
203 | - padding: 0 10px; | |
204 | - } | |
205 | - } | |
206 | - } | |
207 | - } | |
208 | 146 | } |
209 | 147 | } |
210 | 148 | } | ... | ... |
... | ... | @@ -0,0 +1,61 @@ |
1 | +.highlighted-data { | |
2 | + border: none; | |
3 | + box-shadow: none; | |
4 | + margin: 0px; | |
5 | + padding: 0px; | |
6 | + table-layout: fixed; | |
7 | + | |
8 | + pre { | |
9 | + border: none; | |
10 | + border-radius: 0; | |
11 | + font-family: $monospace_font; | |
12 | + font-size: 12px !important; | |
13 | + line-height: 16px !important; | |
14 | + margin: 0; | |
15 | + | |
16 | + code { | |
17 | + white-space: pre; | |
18 | + word-wrap: normal; | |
19 | + } | |
20 | + } | |
21 | + | |
22 | + .hljs { | |
23 | + padding: 0; | |
24 | + } | |
25 | + | |
26 | + .line-numbers { | |
27 | + padding: 10px; | |
28 | + text-align: right; | |
29 | + float: left; | |
30 | + width: 60px; | |
31 | + | |
32 | + a { | |
33 | + font-family: $monospace_font; | |
34 | + display: block; | |
35 | + font-size: 12px !important; | |
36 | + line-height: 16px !important; | |
37 | + | |
38 | + i { | |
39 | + display: none; | |
40 | + } | |
41 | + | |
42 | + &:hover i { | |
43 | + display: inline; | |
44 | + } | |
45 | + } | |
46 | + } | |
47 | + | |
48 | + .highlight { | |
49 | + overflow: auto; | |
50 | + overflow-y: hidden; | |
51 | + | |
52 | + pre { | |
53 | + white-space: pre; | |
54 | + word-wrap: normal; | |
55 | + | |
56 | + .line { | |
57 | + padding: 0 10px; | |
58 | + } | |
59 | + } | |
60 | + } | |
61 | +} | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -203,8 +203,14 @@ module ApplicationHelper |
203 | 203 | def highlight_js(&block) |
204 | 204 | string = capture(&block) |
205 | 205 | |
206 | - content_tag :div, class: user_color_scheme_class do | |
207 | - Pygments::Lexer[:js].highlight(string).html_safe | |
206 | + content_tag :div, class: "highlighted-data #{user_color_scheme_class}" do | |
207 | + content_tag :div, class: 'highlight' do | |
208 | + content_tag :pre do | |
209 | + content_tag :code do | |
210 | + string.html_safe | |
211 | + end | |
212 | + end | |
213 | + end | |
208 | 214 | end |
209 | 215 | end |
210 | 216 | ... | ... |
app/views/projects/blob/_text.html.haml
... | ... | @@ -8,16 +8,6 @@ |
8 | 8 | - else |
9 | 9 | .file-content.code |
10 | 10 | - unless blob.empty? |
11 | - %div.highlighted-data{class: user_color_scheme_class} | |
12 | - .line-numbers | |
13 | - - blob.data.lines.size.times do |index| | |
14 | - - i = index + 1 | |
15 | - = link_to "#L#{i}", id: "L#{i}", rel: "#L#{i}" do | |
16 | - %i.icon-link | |
17 | - = i | |
18 | - .highlight | |
19 | - %pre | |
20 | - %code | |
21 | - = raw blob.data | |
11 | + = render 'shared/file_hljs', blob: blob | |
22 | 12 | - else |
23 | 13 | %p.nothing_here_message Empty file | ... | ... |
app/views/projects/snippets/_blob.html.haml
... | ... | @@ -9,7 +9,6 @@ |
9 | 9 | = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" |
10 | 10 | .file-content.code |
11 | 11 | - unless @snippet.content.empty? |
12 | - %div{class: user_color_scheme_class} | |
13 | - = raw @snippet.colorize(formatter: :gitlab) | |
12 | + = render 'shared/file_hljs', blob: @snippet | |
14 | 13 | - else |
15 | 14 | %p.nothing_here_message Empty file | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +%div.highlighted-data{class: user_color_scheme_class} | |
2 | + .line-numbers | |
3 | + - blob.data.lines.size.times do |index| | |
4 | + - i = index + 1 | |
5 | + = link_to "#L#{i}", id: "L#{i}", rel: "#L#{i}" do | |
6 | + %i.icon-link | |
7 | + = i | |
8 | + .highlight | |
9 | + %pre | |
10 | + %code | |
11 | + = raw blob.data | ... | ... |
app/views/snippets/_blob.html.haml
... | ... | @@ -18,8 +18,7 @@ |
18 | 18 | = render_markup(@snippet.file_name, @snippet.data) |
19 | 19 | - else |
20 | 20 | .file-content.code |
21 | - %div{class: user_color_scheme_class} | |
22 | - = raw @snippet.colorize(formatter: :gitlab) | |
21 | + = render 'shared/file_hljs', blob: @snippet | |
23 | 22 | - else |
24 | 23 | .file-content.code |
25 | 24 | %p.nothing_here_message Empty file | ... | ... |
doc/raketasks/user_management.md
1 | 1 | ### Add user as a developer to all projects |
2 | 2 | |
3 | -``` | |
3 | +```bash | |
4 | 4 | bundle exec rake gitlab:import:user_to_projects[username@domain.tld] |
5 | 5 | ``` |
6 | 6 | |
... | ... | @@ -11,6 +11,6 @@ Notes: |
11 | 11 | |
12 | 12 | * admin users are added as masters |
13 | 13 | |
14 | -``` | |
14 | +```bash | |
15 | 15 | bundle exec rake gitlab:import:all_users_to_all_projects |
16 | 16 | ``` | ... | ... |
lib/redcarpet/render/gitlab_html.rb
... | ... | @@ -12,10 +12,6 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML |
12 | 12 | end |
13 | 13 | |
14 | 14 | def block_code(code, language) |
15 | - options = { options: {encoding: 'utf-8'} } | |
16 | - lexer = Pygments::Lexer.find(language) # language can be an alias | |
17 | - options.merge!(lexer: lexer.aliases[0].downcase) if lexer # downcase is required | |
18 | - | |
19 | 15 | # New lines are placed to fix an rendering issue |
20 | 16 | # with code wrapped inside <h1> tag for next case: |
21 | 17 | # |
... | ... | @@ -25,7 +21,13 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML |
25 | 21 | # |
26 | 22 | <<-HTML |
27 | 23 | |
28 | - <div class="#{h.user_color_scheme_class}">#{Pygments.highlight(code, options)}</div> | |
24 | +<div class="highlighted-data #{h.user_color_scheme_class}"> | |
25 | + <div class="highlight"> | |
26 | + <pre> | |
27 | + <code class="#{language}">#{code}</code> | |
28 | + </pre> | |
29 | + </div> | |
30 | +</div> | |
29 | 31 | |
30 | 32 | HTML |
31 | 33 | end | ... | ... |