From 4402a3344e0254b3ca1101b4126596c51a59b13a Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Tue, 8 Sep 2026 19:14:01 +0900 Subject: [PATCH] Add preview support for Rich Text Format (.rtf) files --- config/configuration.yml.example | 6 ++--- doc/INSTALL | 7 ++--- lib/redmine/markdownizer.rb | 3 ++- test/fixtures/files/richtext.rtf | 27 +++++++++++++++++++ .../functional/attachments_controller_test.rb | 19 +++++++++++++ 5 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/files/richtext.rtf diff --git a/config/configuration.yml.example b/config/configuration.yml.example index 134a9a44c..76b329371 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -240,10 +240,10 @@ default: # - example.org # - "*.example.com" - # Preview for Office documents (Microsoft Office / LibreOffice) + # Preview for Office documents (Microsoft Office / LibreOffice / RTF) # - # Redmine uses Pandoc to convert supported Microsoft Office and LibreOffice - # attachments to Markdown for preview. The settings below named + # Redmine uses Pandoc to convert supported Microsoft Office, LibreOffice and + # Rich Text Format attachments to Markdown for preview. The settings below named # `markdownized_preview_*` control that Markdown-based preview generation. # # Absolute path (e.g. /usr/local/bin/pandoc) to the Pandoc command diff --git a/doc/INSTALL b/doc/INSTALL index 0711145d3..1ead29a80 100644 --- a/doc/INSTALL +++ b/doc/INSTALL @@ -20,9 +20,10 @@ Optional: available in PATH) * ImageMagick (to enable thumbnail generation and Gantt export to PNG images) * Ghostscript (to enable thumbnail generation for PDF attachments) -* Pandoc, to enable previews for Microsoft Office (.docx, .xlsx, .pptx) and - LibreOffice Writer (.odt) documents. Version 3.8.3 or later is recommended. - Older versions of Pandoc supports only .docx and .odt documents. +* Pandoc, to enable previews for Microsoft Office (.docx, .xlsx, .pptx), + LibreOffice Writer (.odt) and Rich Text Format (.rtf) documents. + Version 3.8.3 or later is recommended. Older versions of Pandoc supports + only .docx and .odt documents (.rtf requires 2.14.2 or later). Supported browsers: The current version of Firefox, Safari, Chrome, Chromium and Microsoft Edge. diff --git a/lib/redmine/markdownizer.rb b/lib/redmine/markdownizer.rb index ac1c67203..9bca4db8a 100644 --- a/lib/redmine/markdownizer.rb +++ b/lib/redmine/markdownizer.rb @@ -103,7 +103,8 @@ module Redmine else return (@markdownizable_extensions = []) end - # Pandoc >= 3.8.3 supports Microsoft Excel and PowerPoint files + # Formats that require a newer version of Pandoc + @markdownizable_extensions += %w[.rtf] if (@pandoc_version <=> [2, 14, 2]) >= 0 @markdownizable_extensions += %w[.xlsx .pptx] if (@pandoc_version <=> [3, 8, 3]) >= 0 @markdownizable_extensions diff --git a/test/fixtures/files/richtext.rtf b/test/fixtures/files/richtext.rtf new file mode 100644 index 000000000..2acb2fff2 --- /dev/null +++ b/test/fixtures/files/richtext.rtf @@ -0,0 +1,27 @@ +{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 \fmodern Courier;}} +{\colortbl;\red255\green0\blue0;\red0\green0\blue255;} +\widowctrl\hyphauto + +{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 Redmine\par} +{\pard \ql \f0 \sa180 \li0 \fi0 \par} +{\pard \ql \f0 \sa180 \li0 \fi0 Redmine is a flexible project management web application. Written using the Ruby on Rails framework, it is cross-platform and cross-database.\par} +{\pard \ql \f0 \sa180 \li0 \fi0 Redmine is open source and released under the terms of the GNU General Public License v2 (GPL).\par} +{\pard \ql \f0 \sa180 \li0 \fi0 \outlinelevel0 \b \fs36 Features\par} +{\pard \ql \f0 \sa180 \li0 \fi0 Some of the main features of Redmine are:\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Multiple projects support\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Flexible role based access control\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Flexible issue tracking system\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Gantt chart and calendar\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab News, documents & files management\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Feeds & email notifications\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Per project wiki\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Per project forums\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Time tracking\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Custom fields for issues, time-entries, projects and users\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab SCM integration (SVN, CVS, Git, Mercurial and Bazaar)\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Issue creation via email\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Multiple LDAP authentication support\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab User self-registration support\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Multilanguage support\par} +{\pard \ql \f0 \sa180 \li360 \fi-360 \bullet \tx360\tab Multiple databases support\sa180\par} +} diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 4050dcaa9..b1125dfcb 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -311,6 +311,25 @@ class AttachmentsControllerTest < Redmine::ControllerTest assert_select '.nodata', :count => 0 end + def test_show_rtf + skip unless Redmine::Markdownizer.available? + + set_tmp_attachments_directory + a = Attachment.new( + :container => Issue.find(1), + :file => uploaded_test_file('richtext.rtf', 'application/rtf'), + :author => User.find(1) + ) + assert a.save + + get(:show, :params => {:id => a.id}) + + assert_response :success + assert_equal 'text/html', @response.media_type + assert_select 'div.filecontent.wiki', :text => /Redmine is a flexible project management web application/ + assert_select '.nodata', :count => 0 + end + def test_show_other_with_no_preview @request.session[:user_id] = 2 get(:show, :params => {:id => 6}) -- 2.55.0