Project

General

Profile

Actions

Defect #25634

closed

Highlight language aliases are no more supported

Added by Benoît Zugmeyer about 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
High
Category:
Text formatting
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Following r16501 (released in Redmine 3.3.3), highlight language aliases (the "map" property declared in coderay-1.1.1/lib/coderay/scanners/_map.rb ) are not taken into account when checking if a language is supported.

We used to write code snippets with code class="javascript" , but since the true JavaScript coderay scanner is called java_script.rb, all our JS snippets aren't highlighted anymore.


Files

25634-r16501.png (42.9 KB) 25634-r16501.png Go MAEDA, 2017-04-24 04:30
25634-r16502.png (38.9 KB) 25634-r16502.png Go MAEDA, 2017-04-24 04:30
fix-defect-25634.diff (1.64 KB) fix-defect-25634.diff patch Go MAEDA, 2017-05-20 09:14

Related issues

Related to Redmine - Defect #26055: Three issues with Redmine::SyntaxHighlighting::CodeRay.language_supported?ClosedJean-Philippe Lang

Actions
Actions #1

Updated by Go MAEDA almost 7 years ago

Confirmed in trunk. r16502 have broken syntax highlighting.

r16501 (good):

r16502 (bad):

Actions #2

Updated by Go MAEDA almost 7 years ago

This problem is due to Redmine::SyntaxHighlighting::CodeRay::language_supported?.

def language_supported?(language)
  ::CodeRay::Scanners.list.include?(language.to_s.downcase.to_sym)
rescue
  false
end
p language
# => "javascript" 

p ::CodeRay::Scanners.list
# => [:c, :clojure, ... :java_script, ... :xml, :yaml]

p ::CodeRay::Scanners.list.include?(language.to_s.downcase.to_sym)
# => false
Actions #3

Updated by Mischa The Evil almost 7 years ago

Here is a quick and dirty workaround (which I haven't actually tested yet) for users who are suffering from this regression and cannot wait for a released fix:

Index: lib/redmine/syntax_highlighting.rb
===================================================================
--- lib/redmine/syntax_highlighting.rb    (revision 16543)
+++ lib/redmine/syntax_highlighting.rb    (working copy)
@@ -70,7 +70,8 @@
         end

         def language_supported?(language)
-          ::CodeRay::Scanners.list.include?(language.to_s.downcase.to_sym)
+          coderay_aliases = [:'c++', :cplusplus, :ecmascript, :ecma_script, :rhtml, :eruby, :irb, :javascript, :js, :pascal, :patch, :plain, :plaintext, :xhtml, :yml]
+          ::CodeRay::Scanners.list.include?(language.to_s.downcase.to_sym) || coderay_aliases.include?(language.to_s.downcase.to_sym)
         rescue
           false
         end

Actions #4

Updated by Go MAEDA almost 7 years ago

  • File fix-defect-25634.diff added

This is a patch to fix this issue.

Actions #5

Updated by Go MAEDA almost 7 years ago

  • File deleted (fix-defect-25634.diff)
Actions #6

Updated by Go MAEDA almost 7 years ago

Slightly improved the patch.

Actions #7

Updated by Holger Just almost 7 years ago

Thanks for the patch. I had indeed missed the alias names for Coderay.

Looks good to me!

Actions #8

Updated by Jean-Philippe Lang almost 7 years ago

  • Status changed from Confirmed to Resolved
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Fixed

Patch committed, thanks.

Actions #9

Updated by Jean-Philippe Lang almost 7 years ago

  • Status changed from Resolved to Closed
Actions #10

Updated by Mischa The Evil almost 7 years ago

  • Related to Defect #26055: Three issues with Redmine::SyntaxHighlighting::CodeRay.language_supported? added
Actions #11

Updated by Mischa The Evil almost 7 years ago

  • Status changed from Closed to Reopened

Reopened in light of #26055.

Actions #12

Updated by Jean-Philippe Lang almost 7 years ago

  • Status changed from Reopened to Closed
Actions

Also available in: Atom PDF