diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-06 16:37:18 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-06 16:37:18 +0000 |
commit | 281b26e2f548b4f79dfd2d59c8263d6b670c3304 (patch) | |
tree | 05b399b1133662b920c830665e4d85c24912dab6 /lib | |
parent | 99fa41011fb260938005139f1328c46fd3ee64c5 (diff) | |
download | redmine-281b26e2f548b4f79dfd2d59c8263d6b670c3304.tar.gz redmine-281b26e2f548b4f79dfd2d59c8263d6b670c3304.zip |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/syntax_highlighting.rb | 16 |
1 files changed, 16 insertions, 0 deletions
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 |