Defect #25634

Highlight language aliases are no more supported

Added by BenoƮt Zugmeyer 5 months ago. Updated 4 months ago.

Status:ClosedStart date:
Priority:HighDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Text formatting
Target version:3.2.7
Resolution:Fixed Affected version:3.2.6

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.

25634-r16501.png (42.9 KB) Go MAEDA, 2017-04-24 04:30

25634-r16502.png (38.9 KB) Go MAEDA, 2017-04-24 04:30

fix-defect-25634.diff Magnifier - patch (1.64 KB) Go MAEDA, 2017-05-20 09:14


Related issues

Related to Redmine - Defect #26055: Three issues with Redmine::SyntaxHighlighting::CodeRay.la... Closed

Associated revisions

Revision 16568
Added by Jean-Philippe Lang 4 months ago

Highlight language aliases are no more supported (#25634).

Patch by Go MAEDA.

History

#1 Updated by Go MAEDA 5 months ago

  • File 25634-r16501.png added
  • File 25634-r16502.png added
  • Category changed from Wiki to Text formatting
  • Status changed from New to Confirmed
  • Priority changed from Normal to High
  • Target version set to 3.2.7
  • Affected version changed from 3.3.3 to 3.2.6

Confirmed in trunk. r16502 have broken syntax highlighting.

r16501 (good):

r16502 (bad):

#2 Updated by Go MAEDA 5 months 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

#3 Updated by Mischa The Evil 5 months 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

#4 Updated by Go MAEDA 4 months ago

  • File fix-defect-25634.diff added

This is a patch to fix this issue.

#5 Updated by Go MAEDA 4 months ago

  • File deleted (fix-defect-25634.diff)

#6 Updated by Go MAEDA 4 months ago

Slightly improved the patch.

#7 Updated by Holger Just 4 months ago

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

Looks good to me!

#8 Updated by Jean-Philippe Lang 4 months ago

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

Patch committed, thanks.

#9 Updated by Jean-Philippe Lang 4 months ago

  • Status changed from Resolved to Closed

#10 Updated by Mischa The Evil 4 months ago

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

#11 Updated by Mischa The Evil 4 months ago

  • Status changed from Closed to Reopened

Reopened in light of #26055.

#12 Updated by Jean-Philippe Lang 4 months ago

  • Status changed from Reopened to Closed

Also available in: Atom PDF