##// 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 25 <% end %>
26 26
27 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 37 <%= submit_tag l(:button_add) %>
38 38 <% end %>
39 39 <% end %>
40
41 <% content_for :header_tags do %>
42 <%= stylesheet_link_tag 'scm' %>
43 <% end %>
@@ -1,4 +1,5
1 1 require 'redcloth'
2 require 'coderay'
2 3
3 4 module Redmine
4 5 module WikiFormatting
@@ -25,6 +26,21 module Redmine
25 26 text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
26 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 44 AUTO_LINK_RE = %r{
29 45 ( # leading text
30 46 <\w+.*?>| # leading HTML tag, or
@@ -29,7 +29,7 table.list thead th.list-filename {
29 29
30 30 /************* Coderay styles *************/
31 31
32 .CodeRay {
32 table.CodeRay {
33 33 background-color: #fafafa;
34 34 }
35 35 .CodeRay pre { margin: 0px }
@@ -25,6 +25,10 module Encoders
25 25 #
26 26 # == Options
27 27 #
28 # === :escape
29 # Escape html entities
30 # Default: true
31 #
28 32 # === :tab_width
29 33 # Convert \t characters to +n+ spaces (a number.)
30 34 # Default: 8
@@ -70,6 +74,7 module Encoders
70 74 FILE_EXTENSION = 'html'
71 75
72 76 DEFAULT_OPTIONS = {
77 :escape => true,
73 78 :tab_width => 8,
74 79
75 80 :level => :xhtml,
@@ -145,6 +150,7 module Encoders
145 150 @HTML_ESCAPE = HTML_ESCAPE.dup
146 151 @HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
147 152
153 @escape = options[:escape]
148 154 @opened = [nil]
149 155 @css = CSS.new options[:style]
150 156
@@ -222,7 +228,7 module Encoders
222 228
223 229 def token text, type
224 230 if text.is_a? ::String
225 if text =~ /#{HTML_ESCAPE_PATTERN}/o
231 if @escape && (text =~ /#{HTML_ESCAPE_PATTERN}/o)
226 232 text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
227 233 end
228 234 @opened[0] = type
General Comments 0
You need to be logged in to leave comments. Login now