diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 385f3b8a4..ed0323562 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -86,4 +86,14 @@ module AttachmentsHelper
end
api.created_on attachment.created_on
end
+
+ def render_file_content(attachment, content)
+ if attachment.is_markdown?
+ render :partial => 'common/markup', :locals => {:markup_text_formatting => 'markdown', :markup_text => content}
+ elsif attachment.is_textile?
+ render :partial => 'common/markup', :locals => {:markup_text_formatting => 'textile', :markup_text => content}
+ else
+ render :partial => 'common/file', :locals => {:content => content, :filename => attachment.filename}
+ end
+ end
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index cc9b5f930..34c89e161 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -238,6 +238,14 @@ class Attachment < ActiveRecord::Base
Redmine::MimeType.is_type?('text', filename)
end
+ def is_markdown?
+ Redmine::MimeType.of(filename) == "text/markdown"
+ end
+
+ def is_textile?
+ self.filename =~ /\.(textile)$/i
+ end
+
def is_image?
Redmine::MimeType.is_type?('image', filename)
end
diff --git a/app/views/attachments/file.html.erb b/app/views/attachments/file.html.erb
index af5ea78dc..e19b9127e 100644
--- a/app/views/attachments/file.html.erb
+++ b/app/views/attachments/file.html.erb
@@ -1,4 +1,4 @@
<%= render :layout => 'layouts/file' do %>
- <%= render :partial => 'common/file', :locals => {:content => @content, :filename => @attachment.filename} %>
+ <%= render_file_content(@attachment, @content) %>
<% end %>
diff --git a/app/views/common/_markup.html.erb b/app/views/common/_markup.html.erb
new file mode 100644
index 000000000..dc6c7f474
--- /dev/null
+++ b/app/views/common/_markup.html.erb
@@ -0,0 +1,3 @@
+
+ <%= Redmine::WikiFormatting.to_html(markup_text_formatting, Redmine::CodesetUtil.to_utf8_by_setting(markup_text)).html_safe %>
+
diff --git a/test/fixtures/files/testfile.md b/test/fixtures/files/testfile.md
new file mode 100644
index 000000000..3606a410e
--- /dev/null
+++ b/test/fixtures/files/testfile.md
@@ -0,0 +1,3 @@
+# Header 1
+## Header 2
+### Header 3
diff --git a/test/fixtures/files/testfile.textile b/test/fixtures/files/testfile.textile
new file mode 100644
index 000000000..6339de56b
--- /dev/null
+++ b/test/fixtures/files/testfile.textile
@@ -0,0 +1,5 @@
+h1. Header 1
+
+h2. Header 2
+
+h3. Header 3
diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb
index a5d4c1705..4c9a18202 100644
--- a/test/functional/attachments_controller_test.rb
+++ b/test/functional/attachments_controller_test.rb
@@ -212,6 +212,38 @@ class AttachmentsControllerTest < Redmine::ControllerTest
set_tmp_attachments_directory
end
+ def test_show_text_file_formated_markdown
+ set_tmp_attachments_directory
+ a = Attachment.new(:container => Issue.find(1),
+ :file => uploaded_test_file("testfile.md", "text/plain"),
+ :author => User.find(1))
+ assert a.save
+ assert_equal 'testfile.md', a.filename
+
+ get :show, :params => {
+ :id => a.id
+ }
+ assert_response :success
+ assert_equal 'text/html', @response.content_type
+ assert_select 'div.wiki', :html => "Header 1
\n\nHeader 2
\n\nHeader 3
"
+ end
+
+ def test_show_text_file_fromated_textile
+ set_tmp_attachments_directory
+ a = Attachment.new(:container => Issue.find(1),
+ :file => uploaded_test_file("testfile.textile", "text/plain"),
+ :author => User.find(1))
+ assert a.save
+ assert_equal 'testfile.textile', a.filename
+
+ get :show, :params => {
+ :id => a.id
+ }
+ assert_response :success
+ assert_equal 'text/html', @response.content_type
+ assert_select 'div.wiki', :html => "Header 1
\n\n\n\tHeader 2
\n\n\n\tHeader 3
"
+ end
+
def test_show_image
@request.session[:user_id] = 2
get :show, :params => {