Commit 52c521ffe84dac5dc72a299ee1ecf4736a10f07f
1 parent
b78fd0c1
Exists in
master
and in
4 other branches
Use GitHub::Markup to parse markup files
Closes #1382
Showing
4 changed files
with
28 additions
and
8 deletions
Show diff stats
app/helpers/tree_helper.rb
| @@ -24,4 +24,14 @@ module TreeHelper | @@ -24,4 +24,14 @@ module TreeHelper | ||
| 24 | content.name | 24 | content.name |
| 25 | end | 25 | end |
| 26 | end | 26 | end |
| 27 | + | ||
| 28 | + # Public: Determines if a given filename is compatible with GitHub::Markup. | ||
| 29 | + # | ||
| 30 | + # filename - Filename string to check | ||
| 31 | + # | ||
| 32 | + # Returns boolean | ||
| 33 | + def markup?(filename) | ||
| 34 | + filename.end_with?(*%w(.mdown .md .markdown .textile .rdoc .org .creole | ||
| 35 | + .mediawiki .rst .asciidoc .pod)) | ||
| 36 | + end | ||
| 27 | end | 37 | end |
app/views/refs/_tree.html.haml
| @@ -43,11 +43,7 @@ | @@ -43,11 +43,7 @@ | ||
| 43 | %i.icon-file | 43 | %i.icon-file |
| 44 | = content.name | 44 | = content.name |
| 45 | .file_content.wiki | 45 | .file_content.wiki |
| 46 | - - if content.name =~ /\.(md|markdown)$/i | ||
| 47 | - = preserve do | ||
| 48 | - = markdown(content.data) | ||
| 49 | - - else | ||
| 50 | - = simple_format(content.data) | 46 | + = raw GitHub::Markup.render(content.name, content.data) |
| 51 | 47 | ||
| 52 | :javascript | 48 | :javascript |
| 53 | $(function(){ | 49 | $(function(){ |
app/views/refs/_tree_file.html.haml
| @@ -9,10 +9,9 @@ | @@ -9,10 +9,9 @@ | ||
| 9 | = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small" | 9 | = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small" |
| 10 | = link_to "blame", blame_file_project_ref_path(@project, @ref, path: params[:path]), class: "btn very_small" | 10 | = link_to "blame", blame_file_project_ref_path(@project, @ref, path: params[:path]), class: "btn very_small" |
| 11 | - if file.text? | 11 | - if file.text? |
| 12 | - - if name =~ /\.(md|markdown)$/i | 12 | + - if markup?(name) |
| 13 | .file_content.wiki | 13 | .file_content.wiki |
| 14 | - = preserve do | ||
| 15 | - = markdown(file.data) | 14 | + = raw GitHub::Markup.render(name, file.data) |
| 16 | - else | 15 | - else |
| 17 | .file_content.code | 16 | .file_content.code |
| 18 | - unless file.empty? | 17 | - unless file.empty? |
| @@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe TreeHelper do | ||
| 4 | + describe '#markup?' do | ||
| 5 | + %w(mdown md markdown textile rdoc org creole mediawiki rst asciidoc pod).each do |type| | ||
| 6 | + it "returns true for #{type} files" do | ||
| 7 | + markup?("README.#{type}").should be_true | ||
| 8 | + end | ||
| 9 | + end | ||
| 10 | + | ||
| 11 | + it "returns false when given a non-markup filename" do | ||
| 12 | + markup?('README.rb').should_not be_true | ||
| 13 | + end | ||
| 14 | + end | ||
| 15 | +end |