summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-10-03 00:09:28 +0000
committerGo MAEDA <maeda@farend.jp>2019-10-03 00:09:28 +0000
commit3ce678510e96fa0ce5459e6b7731878347f686b2 (patch)
tree6d556d89e83137e55f382af2377abd8bda0f61fa /app
parentdf1c54146f36e16becb4de7137074238ca496776 (diff)
downloadredmine-3ce678510e96fa0ce5459e6b7731878347f686b2.tar.gz
redmine-3ce678510e96fa0ce5459e6b7731878347f686b2.zip
Render Textile and Markdown attachments on the preview page (#29752).
Patch by Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@18584 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/helpers/attachments_helper.rb10
-rw-r--r--app/models/attachment.rb8
-rw-r--r--app/views/attachments/file.html.erb2
-rw-r--r--app/views/common/_markup.html.erb3
4 files changed, 22 insertions, 1 deletions
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 5421731ea..476b93ef3 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 29d1acc79..0cd666499 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -240,6 +240,14 @@ class Attachment < ActiveRecord::Base
Redmine::MimeType.is_type?('text', filename) || Redmine::SyntaxHighlighting.filename_supported?(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 %>
&nbsp;
- <%= 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 @@
+<div class="wiki">
+ <%= Redmine::WikiFormatting.to_html(markup_text_formatting, Redmine::CodesetUtil.to_utf8_by_setting(markup_text)).html_safe %>
+</div>