Project

General

Profile

Actions

Defect #29259

closed

Attachment preview does not work for some source files such as JavaScript and Go

Added by Stephan Wenzel over 6 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Attachments
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Redmine squanders the capabilities of CodeRay for previewing code files in Redmine's preview pane. A very prominent squandering is the negligence of javascript files, for which Redmine only shows that no preview is available.

AttachmentsController#show method only tests: @attachment.is_text? - The function Attachment::is_text? only relies on Redmine::MimeType.is_type?('text', filename). The mime type of javascript, however, is "application/javascript". Here Redmine misses what CodeRay can do.

I propose the following patches:

Add function 'is_code?' to Attachment.rb

def is_code?
  ::CodeRay::FileType[filename].present?
end

Patch AttachmentsController.rb (Redmine 3.4.6)

- elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
+ elsif (@attachment.is_text? || @atachments.is_code?) && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte

These two patches add previews for cfc, cfm, clj, cpp, cu, cxx, c++, C, dpr, gemspec, go, groovy, gvy, haml, hpp, h++, html.erb, js, lua, mab, pas, phtml, prawn, py3, pyw, raydebug, rjs, rpdf, ru, rxml, sass, taskpaper, template, tmproj, xaml

I have provided a plugin that applies these patches as a proof of concept:

[[https://www.redmine.org/plugins/redmine_more_code]]


Files


Related issues

Related to Redmine - Feature #24681: Syntax highlighter: replace CodeRay with RougeClosedJean-Philippe Lang

Actions
Blocked by Redmine - Defect #31285: Syntax highlighting does not work for attachments with .pl extensionClosedGo MAEDA

Actions
Actions

Also available in: Atom PDF