Vote #79585
完了Render Textile and Markdown attachments on the preview page
0%
説明
Currently, Textile and Markdown files are treated as plain text when previewing an attachment.
I think it is more convenient for users to render those as HTML as if they are written in a Wiki page. Raw markups such as "h1.", "h2.", and "h3." are not friendly for humans.
journals
--------------------------------------------------------------------------------
+1
I think it is very useful that the feature proposed by Go MAEDA.
I made a patch to add the feature, and attach it.
--------------------------------------------------------------------------------
LGTM. Setting the target version to 4.1.0.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
The patch looks good to me with one small observation, do you see any problem if we add @'text/textile' => 'textile'@ to @MIME_TYPES@? In this way, we can replace in the patch @self.filename =~ /\.(textile)$/i@ with @Redmine::MimeType.of(filename) == "text/textile"@.
--------------------------------------------------------------------------------
I suggest adding the following change to the patch in order to make distinguishable between the UI of Redmine and the content of the file by adding a border around the content.
<pre><code class="diff">
diff --git a/app/views/common/_markup.html.erb b/app/views/common/_markup.html.erb
index dc6c7f474..14786a87c 100644
--- a/app/views/common/_markup.html.erb
+++ b/app/views/common/_markup.html.erb
@@ -1,3 +1,3 @@
-<div class="wiki">
+<div class="filecontent wiki">
<%= Redmine::WikiFormatting.to_html(markup_text_formatting, Redmine::CodesetUtil.to_utf8_by_setting(markup_text)).html_safe %>
</div>
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 5f8ade106..8c9402142 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -1740,6 +1740,13 @@ img {
max-width: 100%;
}
+.filecontent-container > .filecontent.wiki {
+ position: relative;
+ border: 1px solid #e2e2e2;
+ padding: 8px;
+ border-radius: 3px;
+}
+
/* Fixes for IE 11 */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
select::-ms-expand {
</code></pre>
*Before:*
!{width: 918px; border: 1px solid #ccc;}.add-border-before@2x.png!
*After:*
!{width: 918px; border: 1px solid #ccc;}.add-border-after@2x.png!
--------------------------------------------------------------------------------
Committed the patch. Thank you all for contributing and reviewing the patch.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Go MAEDA wrote:
> Committed the patch. [...]
What about the note Marius made in #29752#note-5?
--------------------------------------------------------------------------------
Mischa The Evil wrote:
> What about the note Marius made in #29752#note-5?
Oh, I forgot to handle that. Thank you for pointing it out.
Marius BALTEANU wrote:
> The patch looks good to me with one small observation, do you see any problem if we add @'text/textile' => 'textile'@ to @MIME_TYPES@? In this way, we can replace in the patch @self.filename =~ /\.(textile)$/i@ with @Redmine::MimeType.of(filename) == "text/textile"@.
I like the approach but there is only one problem that "text/textile" is not a valid media type (see https://www.iana.org/assignments/media-types/media-types.xhtml). Maybe we can use "text/x-textile" instead, what do you think?
--------------------------------------------------------------------------------
Go MAEDA wrote:
> Marius BALTEANU wrote:
> > The patch looks good to me with one small observation, do you see any problem if we add @'text/textile' => 'textile'@ to @MIME_TYPES@? In this way, we can replace in the patch @self.filename =~ /\.(textile)$/i@ with @Redmine::MimeType.of(filename) == "text/textile"@.
>
> I like the approach but there is only one problem that "text/textile" is not a valid media type (see https://www.iana.org/assignments/media-types/media-types.xhtml). Maybe we can use "text/x-textile" instead, what do you think?
I like your idea to use "text/x-textile".
--------------------------------------------------------------------------------
This patch replaces the regexp that checks '.textile' extension with @Redmine::MimeType.of@.
<pre><code class="diff">
Index: app/models/attachment.rb
===================================================================
--- app/models/attachment.rb (リビジョン 18585)
+++ app/models/attachment.rb (作業コピー)
@@ -245,7 +245,7 @@
end
def is_textile?
- self.filename =~ /\.textile$/i
+ Redmine::MimeType.of(filename) == 'text/x-textile'
end
def is_image?
Index: lib/redmine/mime_type.rb
===================================================================
--- lib/redmine/mime_type.rb (リビジョン 18585)
+++ lib/redmine/mime_type.rb (作業コピー)
@@ -35,6 +35,7 @@
'text/x-ruby' => 'rb,rbw,ruby,rake,erb',
'text/x-csh' => 'csh',
'text/x-sh' => 'sh',
+ 'text/x-textile' => 'textile',
'text/xml' => 'xml,xsd,mxml',
'text/yaml' => 'yml,yaml',
'text/csv' => 'csv',
</code></pre>
--------------------------------------------------------------------------------
Committed the patch #29752#note-13 in r18586.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
related_issues
relates,Closed,13431,it would be nice to render the markup language in the "Repository" view
relates,Closed,16849,Render Textile and Markdown files in the repository browser
relates,New,35889,Textile and Markdown attachment rendering should support third-party formatters