Project

General

Profile

Feature #8959 » 0001-Add-Microsoft-Office-and-LibreOffice-documents-previ-B.patch

Florian Walchshofer, 2026-03-01 16:28

View differences:

config/configuration.yml.example
# Absolute path (e.g. /usr/local/bin/pandoc) to the Pandoc command
# used to convert supported attachments to Markdown for preview.
#pandoc_command:
#pandoc_extensions: .docx .xlsx .pptx .odt
# specific configuration options for production environment
# that overrides the default ones
lib/redmine/markdownizer.rb
COMMAND = (Redmine::Configuration['pandoc_command'] || 'pandoc').freeze
MAX_PREVIEW_SIZE = 100.kilobytes
SUPPORTED_EXTENSIONS = %w(.doc .docx .xls .xlsx .ppt .pptx .odt .ods .odp).freeze
SUPPORTED_EXTENSIONS = (Redmine::Configuration['pandoc_extensions'] || %w(.docx .xlsx .pptx .odt)).freeze
def self.supports?(filename)
SUPPORTED_EXTENSIONS.include?(File.extname(filename.to_s).downcase)
......
directory = File.dirname(target)
FileUtils.mkdir_p(directory)
cmd = "#{shell_quote COMMAND} #{shell_quote source} -t gfm"
args = [COMMAND, source, "-t", "gfm"]
pid = nil
output = Tempfile.new('markdownized-preview')
begin
Timeout.timeout(Redmine::Configuration['thumbnails_generation_timeout'].to_i) do
pid = Process.spawn(cmd, out: output.path)
pid = Process.spawn(*args, out: output.path)
_, status = Process.wait2(pid)
unless status.success?
logger.error("Markdown conversion failed (#{status.exitstatus}):\nCommand: #{cmd}")
logger.error("Markdown conversion failed (#{status.exitstatus}):\nCommand: #{args.shelljoin}")
return nil
end
end
rescue Timeout::Error
Process.kill('KILL', pid) if pid
logger.error("Markdown conversion timed out:\nCommand: #{cmd}")
logger.error("Markdown conversion timed out:\nCommand: #{args.shelljoin}")
return nil
rescue => e
logger.error("Markdown conversion failed:\nCommand: #{cmd}\nException was: #{e.message}")
logger.error("Markdown conversion failed:\nCommand: #{args.shelljoin}\nException was: #{e.message}")
return nil
ensure
output.close
Process.detach(pid)
end
preview = File.binread(output.path, MAX_PREVIEW_SIZE + 1) || +""
......
return @available if defined?(@available)
begin
`#{shell_quote COMMAND} --version`
@available = $?.success?
version = `#{shell_quote COMMAND} --version`[/pandoc\s+([\d.]+)/, 1].split('.').map(&:to_i)
@available = ($?.success? && (version <=> [3, 9]) >= 0) # Pandoc.version >= 3.9
rescue
@available = false
end
(5-5/11)