From b78fd0c13088ce2c19d939a26a26e247ca5047ea Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 5 Sep 2012 16:49:59 -0400 Subject: [PATCH 1/3] Add github-markup gem --- Gemfile | 1 + Gemfile.lock | 2 ++ app/controllers/refs_controller.rb | 2 ++ 3 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index b0724fadf5b..34f7c2747d7 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,7 @@ gem "seed-fu" # Markdown to HTML gem "redcarpet", "~> 2.1.1" +gem 'github-markup' # Servers gem "thin" diff --git a/Gemfile.lock b/Gemfile.lock index f350b3fcc0e..fc730802fa5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -178,6 +178,7 @@ GEM gherkin (2.11.0) json (>= 1.4.6) git (1.2.5) + github-markup (0.7.4) gitlab_meta (2.9) grape (0.2.1) hashie (~> 1.2) @@ -396,6 +397,7 @@ DEPENDENCIES ffaker foreman git + github-markup gitlab_meta (= 2.9) gitolite! grack! diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb index 3f81a2ca1a3..9036143779c 100644 --- a/app/controllers/refs_controller.rb +++ b/app/controllers/refs_controller.rb @@ -1,3 +1,5 @@ +require 'github/markup' + class RefsController < ApplicationController include Gitlab::Encode before_filter :project From 52c521ffe84dac5dc72a299ee1ecf4736a10f07f Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 5 Sep 2012 16:52:49 -0400 Subject: [PATCH 2/3] Use GitHub::Markup to parse markup files Closes #1382 --- app/helpers/tree_helper.rb | 10 ++++++++++ app/views/refs/_tree.html.haml | 6 +----- app/views/refs/_tree_file.html.haml | 5 ++--- spec/helpers/tree_helper_spec.rb | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 spec/helpers/tree_helper_spec.rb diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index ed3053d8af5..c51ee84a25e 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -24,4 +24,14 @@ module TreeHelper content.name end end + + # Public: Determines if a given filename is compatible with GitHub::Markup. + # + # filename - Filename string to check + # + # Returns boolean + def markup?(filename) + filename.end_with?(*%w(.mdown .md .markdown .textile .rdoc .org .creole + .mediawiki .rst .asciidoc .pod)) + end end diff --git a/app/views/refs/_tree.html.haml b/app/views/refs/_tree.html.haml index a4765c1087a..297a3b5f60a 100644 --- a/app/views/refs/_tree.html.haml +++ b/app/views/refs/_tree.html.haml @@ -43,11 +43,7 @@ %i.icon-file = content.name .file_content.wiki - - if content.name =~ /\.(md|markdown)$/i - = preserve do - = markdown(content.data) - - else - = simple_format(content.data) + = raw GitHub::Markup.render(content.name, content.data) :javascript $(function(){ diff --git a/app/views/refs/_tree_file.html.haml b/app/views/refs/_tree_file.html.haml index b5ed61bb45a..765f271a1bf 100644 --- a/app/views/refs/_tree_file.html.haml +++ b/app/views/refs/_tree_file.html.haml @@ -9,10 +9,9 @@ = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small" = link_to "blame", blame_file_project_ref_path(@project, @ref, path: params[:path]), class: "btn very_small" - if file.text? - - if name =~ /\.(md|markdown)$/i + - if markup?(name) .file_content.wiki - = preserve do - = markdown(file.data) + = raw GitHub::Markup.render(name, file.data) - else .file_content.code - unless file.empty? diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb new file mode 100644 index 00000000000..bb124d8b303 --- /dev/null +++ b/spec/helpers/tree_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe TreeHelper do + describe '#markup?' do + %w(mdown md markdown textile rdoc org creole mediawiki rst asciidoc pod).each do |type| + it "returns true for #{type} files" do + markup?("README.#{type}").should be_true + end + end + + it "returns false when given a non-markup filename" do + markup?('README.rb').should_not be_true + end + end +end From 1814ee0ced59aa3203ce265410ae5a7c83e096aa Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 5 Sep 2012 17:02:23 -0400 Subject: [PATCH 3/3] Give github-markup gem a version requirement --- Gemfile | 4 ++-- Gemfile.lock | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 34f7c2747d7..c8d3821f61a 100644 --- a/Gemfile +++ b/Gemfile @@ -44,8 +44,8 @@ gem "ffaker" gem "seed-fu" # Markdown to HTML -gem "redcarpet", "~> 2.1.1" -gem 'github-markup' +gem "redcarpet", "~> 2.1.1" +gem "github-markup", "~> 0.7.4" # Servers gem "thin" diff --git a/Gemfile.lock b/Gemfile.lock index fc730802fa5..830e28b53e3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -397,7 +397,7 @@ DEPENDENCIES ffaker foreman git - github-markup + github-markup (~> 0.7.4) gitlab_meta (= 2.9) gitolite! grack!