Added code highlighting support in wiki, using this syntax:

<pre><code> <-- cut here

  <pre><code class="ruby">
    Place you code here.
  </code></pre>  

cut here --> </pre></code>

git-svn-id: http://redmine.rubyforge.org/svn/trunk@710 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-09-06 17:06:07 +00:00
parent 22c5e0d614
commit 42db3cac06
5 changed files with 33 additions and 3 deletions

View File

@ -25,3 +25,7 @@
<% end %> <% end %>
<div id="preview" class="wiki"></div> <div id="preview" class="wiki"></div>
<% content_for :header_tags do %>
<%= stylesheet_link_tag 'scm' %>
<% end %>

View File

@ -37,3 +37,7 @@
<%= submit_tag l(:button_add) %> <%= submit_tag l(:button_add) %>
<% end %> <% end %>
<% end %> <% end %>
<% content_for :header_tags do %>
<%= stylesheet_link_tag 'scm' %>
<% end %>

View File

@ -1,4 +1,5 @@
require 'redcloth' require 'redcloth'
require 'coderay'
module Redmine module Redmine
module WikiFormatting module WikiFormatting
@ -24,7 +25,22 @@ module Redmine
def hard_break( text ) def hard_break( text )
text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
end end
# Patch to add code highlighting support to RedCloth
def smooth_offtags( text )
unless @pre_list.empty?
## replace <pre> content
text.gsub!(/<redpre#(\d+)>/) do
content = @pre_list[$1.to_i]
if content.match(/<code\s+class="(\w+)">\s?(.+)/m)
content = "<code class=\"#{$1} CodeRay\">" +
CodeRay.scan($2, $1).html(:escape => false, :line_numbers => :inline)
end
content
end
end
end
AUTO_LINK_RE = %r{ AUTO_LINK_RE = %r{
( # leading text ( # leading text
<\w+.*?>| # leading HTML tag, or <\w+.*?>| # leading HTML tag, or

View File

@ -29,7 +29,7 @@ table.list thead th.list-filename {
/************* Coderay styles *************/ /************* Coderay styles *************/
.CodeRay { table.CodeRay {
background-color: #fafafa; background-color: #fafafa;
} }
.CodeRay pre { margin: 0px } .CodeRay pre { margin: 0px }

View File

@ -25,6 +25,10 @@ module Encoders
# #
# == Options # == Options
# #
# === :escape
# Escape html entities
# Default: true
#
# === :tab_width # === :tab_width
# Convert \t characters to +n+ spaces (a number.) # Convert \t characters to +n+ spaces (a number.)
# Default: 8 # Default: 8
@ -70,6 +74,7 @@ module Encoders
FILE_EXTENSION = 'html' FILE_EXTENSION = 'html'
DEFAULT_OPTIONS = { DEFAULT_OPTIONS = {
:escape => true,
:tab_width => 8, :tab_width => 8,
:level => :xhtml, :level => :xhtml,
@ -145,6 +150,7 @@ module Encoders
@HTML_ESCAPE = HTML_ESCAPE.dup @HTML_ESCAPE = HTML_ESCAPE.dup
@HTML_ESCAPE["\t"] = ' ' * options[:tab_width] @HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
@escape = options[:escape]
@opened = [nil] @opened = [nil]
@css = CSS.new options[:style] @css = CSS.new options[:style]
@ -222,7 +228,7 @@ module Encoders
def token text, type def token text, type
if text.is_a? ::String if text.is_a? ::String
if text =~ /#{HTML_ESCAPE_PATTERN}/o if @escape && (text =~ /#{HTML_ESCAPE_PATTERN}/o)
text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] } text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
end end
@opened[0] = type @opened[0] = type