Mercurial > hg > soundsoftware-site
comparison lib/redmine/syntax_highlighting.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 513646585e45 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2010 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 module Redmine | 18 module Redmine |
19 module SyntaxHighlighting | 19 module SyntaxHighlighting |
20 | 20 |
21 class << self | 21 class << self |
22 attr_reader :highlighter | 22 attr_reader :highlighter |
23 delegate :highlight_by_filename, :highlight_by_language, :to => :highlighter | 23 delegate :highlight_by_filename, :highlight_by_language, :to => :highlighter |
24 | 24 |
25 def highlighter=(name) | 25 def highlighter=(name) |
26 if name.is_a?(Module) | 26 if name.is_a?(Module) |
27 @highlighter = name | 27 @highlighter = name |
28 else | 28 else |
29 @highlighter = const_get(name) | 29 @highlighter = const_get(name) |
30 end | 30 end |
31 end | 31 end |
32 end | 32 end |
33 | 33 |
34 module CodeRay | 34 module CodeRay |
35 require 'coderay' | 35 require 'coderay' |
36 require 'coderay/helpers/file_type' | 36 require 'coderay/helpers/file_type' |
37 | 37 |
38 class << self | 38 class << self |
39 # Highlights +text+ as the content of +filename+ | 39 # Highlights +text+ as the content of +filename+ |
40 # Should not return line numbers nor outer pre tag | 40 # Should not return line numbers nor outer pre tag |
41 def highlight_by_filename(text, filename) | 41 def highlight_by_filename(text, filename) |
42 language = ::CodeRay::FileType[filename] | 42 language = ::CodeRay::FileType[filename] |
43 language ? ::CodeRay.scan(text, language).html : ERB::Util.h(text) | 43 language ? ::CodeRay.scan(text, language).html : ERB::Util.h(text) |
44 end | 44 end |
45 | 45 |
46 # Highlights +text+ using +language+ syntax | 46 # Highlights +text+ using +language+ syntax |
47 # Should not return outer pre tag | 47 # Should not return outer pre tag |
48 def highlight_by_language(text, language) | 48 def highlight_by_language(text, language) |
49 ::CodeRay.scan(text, language).html(:line_numbers => :inline, :wrap => :span) | 49 ::CodeRay.scan(text, language).html(:line_numbers => :inline, :line_number_anchors => false, :wrap => :span) |
50 end | 50 end |
51 end | 51 end |
52 end | 52 end |
53 end | 53 end |
54 | 54 |
55 SyntaxHighlighting.highlighter = 'CodeRay' | 55 SyntaxHighlighting.highlighter = 'CodeRay' |
56 end | 56 end |