Commit c437e2d7d416dae73efdea248a34b452d912986e

Authored by Arthur Schreiber
1 parent 9ee34575

Switch to Redcarpet for Markdown Rendering.

This gives us Github Flavored Markdown, which is awesome.
@@ -18,12 +18,12 @@ gem "six" @@ -18,12 +18,12 @@ gem "six"
18 gem "therubyracer" 18 gem "therubyracer"
19 gem "faker" 19 gem "faker"
20 gem "seed-fu" 20 gem "seed-fu"
21 -gem "pygments.rb", "0.2.7" 21 +gem "pygments.rb", "~> 0.2.11"
  22 +gem "redcarpet", "~> 2.1.1"
22 gem "thin" 23 gem "thin"
23 gem "unicorn" 24 gem "unicorn"
24 gem "git" 25 gem "git"
25 gem "acts_as_list" 26 gem "acts_as_list"
26 -gem "rdiscount"  
27 gem "acts-as-taggable-on", "~> 2.1.0" 27 gem "acts-as-taggable-on", "~> 2.1.0"
28 gem "drapper" 28 gem "drapper"
29 gem "resque", "~> 1.20.0" 29 gem "resque", "~> 1.20.0"
@@ -169,7 +169,7 @@ GEM @@ -169,7 +169,7 @@ GEM
169 coderay (~> 1.0.5) 169 coderay (~> 1.0.5)
170 method_source (~> 0.7) 170 method_source (~> 0.7)
171 slop (>= 2.4.4, < 3) 171 slop (>= 2.4.4, < 3)
172 - pygments.rb (0.2.7) 172 + pygments.rb (0.2.11)
173 rubypython (~> 0.5.3) 173 rubypython (~> 0.5.3)
174 pyu-ruby-sasl (0.0.3.3) 174 pyu-ruby-sasl (0.0.3.3)
175 rack (1.4.1) 175 rack (1.4.1)
@@ -200,9 +200,9 @@ GEM @@ -200,9 +200,9 @@ GEM
200 thor (~> 0.14.6) 200 thor (~> 0.14.6)
201 raindrops (0.8.0) 201 raindrops (0.8.0)
202 rake (0.9.2.2) 202 rake (0.9.2.2)
203 - rdiscount (1.6.8)  
204 rdoc (3.12) 203 rdoc (3.12)
205 json (~> 1.4) 204 json (~> 1.4)
  205 + redcarpet (2.1.1)
206 redis (2.2.2) 206 redis (2.2.2)
207 redis-namespace (1.0.3) 207 redis-namespace (1.0.3)
208 redis (< 3.0.0) 208 redis (< 3.0.0)
@@ -330,11 +330,11 @@ DEPENDENCIES @@ -330,11 +330,11 @@ DEPENDENCIES
330 mysql2 330 mysql2
331 omniauth-ldap 331 omniauth-ldap
332 pry 332 pry
333 - pygments.rb (= 0.2.7) 333 + pygments.rb (~> 0.2.11)
334 rails (= 3.2.1) 334 rails (= 3.2.1)
335 rails-footnotes 335 rails-footnotes
336 rake 336 rake
337 - rdiscount 337 + redcarpet (~> 2.1.1)
338 resque (~> 1.20.0) 338 resque (~> 1.20.0)
339 rspec-rails 339 rspec-rails
340 sass-rails (= 3.2.3) 340 sass-rails (= 3.2.3)
app/assets/stylesheets/highlight.scss
@@ -22,7 +22,7 @@ td.linenos{ @@ -22,7 +22,7 @@ td.linenos{
22 vertical-align:top; 22 vertical-align:top;
23 } 23 }
24 24
25 -.highlight{ 25 +.highlighttable .highlight{
26 background:none; 26 background:none;
27 padding:10px 0px 0px 10px; 27 padding:10px 0px 0px 10px;
28 margin-left:0px; 28 margin-left:0px;
@@ -31,7 +31,7 @@ td.linenos{ @@ -31,7 +31,7 @@ td.linenos{
31 } 31 }
32 32
33 .linenodiv pre, 33 .linenodiv pre,
34 -.highlight pre{ 34 +.highlighttable .highlight pre{
35 margin:0; 35 margin:0;
36 padding:0; 36 padding:0;
37 background:none; 37 background:none;
app/helpers/application_helper.rb
@@ -72,7 +72,18 @@ module ApplicationHelper @@ -72,7 +72,18 @@ module ApplicationHelper
72 end 72 end
73 73
74 def markdown(text) 74 def markdown(text)
75 - RDiscount.new(text, :autolink, :no_pseudo_protocols, :safelink, :smart, :filter_html).to_html.html_safe 75 + @__renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::GitlabHTML.new(filter_html: true), {
  76 + no_intra_emphasis: true,
  77 + tables: true,
  78 + fenced_code_blocks: true,
  79 + autolink: true,
  80 + strikethrough: true,
  81 + lax_html_blocks: true,
  82 + space_after_headers: true,
  83 + superscript: true
  84 + })
  85 +
  86 + @__renderer.render(text).html_safe
76 end 87 end
77 88
78 def search_autocomplete_source 89 def search_autocomplete_source
app/helpers/wikis_helper.rb
1 module WikisHelper 1 module WikisHelper
2 - def markdown_to_html(text)  
3 - RDiscount.new(text).to_html.html_safe  
4 - end  
5 end 2 end
app/views/wikis/show.html.haml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 %hr 9 %hr
10 .wiki_content 10 .wiki_content
11 = preserve do 11 = preserve do
12 - = markdown_to_html @wiki.content 12 + = markdown @wiki.content
13 13
14 %p.time Last edited by #{@wiki.user.name}, in #{time_ago_in_words @wiki.created_at} 14 %p.time Last edited by #{@wiki.user.name}, in #{time_ago_in_words @wiki.created_at}
15 - if can? current_user, :admin_wiki, @project 15 - if can? current_user, :admin_wiki, @project
lib/redcarpet/render/gitlab_html.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
  2 + def block_code(code, language)
  3 + if Pygments::Lexer.find(language)
  4 + Pygments.highlight(code, :lexer => language)
  5 + else
  6 + Pygments.highlight(code)
  7 + end
  8 + end
  9 +end
0 \ No newline at end of file 10 \ No newline at end of file