Vote #78406
完了Highlight language aliases are no more supported
0%
説明
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.
journals
Confirmed in trunk. r16502 have broken syntax highlighting.
*r16501 (good):*
!{border: 1px solid #ddd}.25634-r16501.png!
*r16502 (bad):*
!{border: 1px solid #ddd}.25634-r16502.png!
--------------------------------------------------------------------------------
This problem is due to @Redmine::SyntaxHighlighting::CodeRay::language_supported?@.
<pre><code class="ruby">
def language_supported?(language)
::CodeRay::Scanners.list.include?(language.to_s.downcase.to_sym)
rescue
false
end
</code></pre>
<pre>
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
</pre>
--------------------------------------------------------------------------------
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:
<pre><code class="patch">
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
</code></pre>
--------------------------------------------------------------------------------
This is a patch to fix this issue.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Slightly improved the patch.
--------------------------------------------------------------------------------
Thanks for the patch. I had indeed missed the alias names for Coderay.
Looks good to me!
--------------------------------------------------------------------------------
Patch committed, thanks.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Reopened in light of #26055.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
related_issues
relates,Closed,26055,Three issues with Redmine::SyntaxHighlighting::CodeRay.language_supported?