From: Jean-Philippe Lang Date: Thu, 6 Apr 2017 16:37:18 +0000 (+0000) Subject: Helper methods to find out if a given language is supported (#25503). X-Git-Tag: 3.4.0~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=281b26e2f548b4f79dfd2d59c8263d6b670c3304;p=redmine.git Helper methods to find out if a given language is supported (#25503). Patch by Jan Schulz-Hofen. git-svn-id: http://svn.redmine.org/redmine/trunk@16501 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/lib/redmine/syntax_highlighting.rb b/lib/redmine/syntax_highlighting.rb index 7480ebd16..7f4334977 100644 --- a/lib/redmine/syntax_highlighting.rb +++ b/lib/redmine/syntax_highlighting.rb @@ -40,6 +40,16 @@ module Redmine rescue ERB::Util.h(text) end + + def language_supported?(language) + if highlighter.respond_to? :language_supported? + highlighter.language_supported? language + else + true + end + rescue + false + end end module CodeRay @@ -58,6 +68,12 @@ module Redmine def highlight_by_language(text, language) ::CodeRay.scan(text, language).html(:wrap => :span) end + + def language_supported?(language) + ::CodeRay::Scanners.list.include?(language.to_s.downcase.to_sym) + rescue + false + end end end end