##// END OF EJS Templates
Added code highlighting support in wiki, using this syntax:...
Jean-Philippe Lang -
r699:42db3cac06ad
parent child
Show More
@@ -25,3 +25,7
25 <% end %>
25 <% end %>
26
26
27 <div id="preview" class="wiki"></div>
27 <div id="preview" class="wiki"></div>
28
29 <% content_for :header_tags do %>
30 <%= stylesheet_link_tag 'scm' %>
31 <% end %>
@@ -37,3 +37,7
37 <%= submit_tag l(:button_add) %>
37 <%= submit_tag l(:button_add) %>
38 <% end %>
38 <% end %>
39 <% end %>
39 <% end %>
40
41 <% content_for :header_tags do %>
42 <%= stylesheet_link_tag 'scm' %>
43 <% end %>
@@ -1,4 +1,5
1 require 'redcloth'
1 require 'redcloth'
2 require 'coderay'
2
3
3 module Redmine
4 module Redmine
4 module WikiFormatting
5 module WikiFormatting
@@ -24,7 +25,22 module Redmine
24 def hard_break( text )
25 def hard_break( text )
25 text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
26 text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
26 end
27 end
27
28
29 # Patch to add code highlighting support to RedCloth
30 def smooth_offtags( text )
31 unless @pre_list.empty?
32 ## replace <pre> content
33 text.gsub!(/<redpre#(\d+)>/) do
34 content = @pre_list[$1.to_i]
35 if content.match(/<code\s+class="(\w+)">\s?(.+)/m)
36 content = "<code class=\"#{$1} CodeRay\">" +
37 CodeRay.scan($2, $1).html(:escape => false, :line_numbers => :inline)
38 end
39 content
40 end
41 end
42 end
43
28 AUTO_LINK_RE = %r{
44 AUTO_LINK_RE = %r{
29 ( # leading text
45 ( # leading text
30 <\w+.*?>| # leading HTML tag, or
46 <\w+.*?>| # leading HTML tag, or
@@ -29,7 +29,7 table.list thead th.list-filename {
29
29
30 /************* Coderay styles *************/
30 /************* Coderay styles *************/
31
31
32 .CodeRay {
32 table.CodeRay {
33 background-color: #fafafa;
33 background-color: #fafafa;
34 }
34 }
35 .CodeRay pre { margin: 0px }
35 .CodeRay pre { margin: 0px }
@@ -25,6 +25,10 module Encoders
25 #
25 #
26 # == Options
26 # == Options
27 #
27 #
28 # === :escape
29 # Escape html entities
30 # Default: true
31 #
28 # === :tab_width
32 # === :tab_width
29 # Convert \t characters to +n+ spaces (a number.)
33 # Convert \t characters to +n+ spaces (a number.)
30 # Default: 8
34 # Default: 8
@@ -70,6 +74,7 module Encoders
70 FILE_EXTENSION = 'html'
74 FILE_EXTENSION = 'html'
71
75
72 DEFAULT_OPTIONS = {
76 DEFAULT_OPTIONS = {
77 :escape => true,
73 :tab_width => 8,
78 :tab_width => 8,
74
79
75 :level => :xhtml,
80 :level => :xhtml,
@@ -145,6 +150,7 module Encoders
145 @HTML_ESCAPE = HTML_ESCAPE.dup
150 @HTML_ESCAPE = HTML_ESCAPE.dup
146 @HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
151 @HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
147
152
153 @escape = options[:escape]
148 @opened = [nil]
154 @opened = [nil]
149 @css = CSS.new options[:style]
155 @css = CSS.new options[:style]
150
156
@@ -222,7 +228,7 module Encoders
222
228
223 def token text, type
229 def token text, type
224 if text.is_a? ::String
230 if text.is_a? ::String
225 if text =~ /#{HTML_ESCAPE_PATTERN}/o
231 if @escape && (text =~ /#{HTML_ESCAPE_PATTERN}/o)
226 text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
232 text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
227 end
233 end
228 @opened[0] = type
234 @opened[0] = type
General Comments 0
You need to be logged in to leave comments. Login now