プロジェクト

全般

プロフィール

Vote #80015

完了

Syntax highlighting does not work for attachments with .pl extension

Admin Redmine さんが約2年前に追加. 約2年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Text formatting_26
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
26
version_id:
151
issue_org_id:
31285
author_id:
332
assigned_to_id:
332
comments:
8
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
99
ステータス-->[Closed]

説明

The new syntax highlighter Rouge that was introduced in Redmine 4.0.0 supports many languages including Perl and Prolog.

However, Redmine 4.0.3 does not highlight attachments with ".pl" extension. It is because the extension is used for both Perl and Prolog source codes and Rouge cannot determine the language only with a filename. As a result, Rouge raises Rouge::Guesser::Ambiguous exception (Ambiguous guess: can't decide between ["prolog", "perl"]).

irb(main):001:0> Rouge::Lexer.guess_by_filename('hello.pl')
Traceback (most recent call last):
Rouge::Guesser::Ambiguous (Rouge::Guesser::Ambiguous)

The problem can be easily fixed by replacing @Rouge::Lexer::guess_by_filename@ with @Rouge::Lexer::guess@.


Index: lib/redmine/syntax_highlighting.rb
===================================================================
--- lib/redmine/syntax_highlighting.rb  (リビジョン 18114)
+++ lib/redmine/syntax_highlighting.rb  (作業コピー)
@@ -85,7 +85,7 @@
           # See also: https://github.com/jneen/rouge/pull/1078
           text = text.gsub(/\r\n?/, "\n")

-          lexer =::Rouge::Lexer.guess_by_filename(filename)
+          lexer =::Rouge::Lexer.guess(:source => text, :filename => filename)
           formatter = ::Rouge::Formatters::HTML.new
           ::Rouge.highlight(text, lexer, CustomHTMLLinewise.new(formatter))
         end

[Before]
!{border: 1px solid #ccc;}.pl-highlight-before.png!

[After]
!{border: 1px solid #ccc;}.pl-highlight-after.png!


journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Updated the test code.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Committed the patch.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

blocks,Closed,29259,Attachment preview does not work for some source files such as JavaScript and Go

Admin Redmine さんが約2年前に更新

  • カテゴリText formatting_26 にセット
  • 対象バージョン4.0.4_151 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0