Project

General

Profile

Patch #1651 » redmine_pygmentize_wiki.diff

Pygmentize syntax coloring in redmine wiki - Sebastien Metrot, 2009-04-08 16:37

View differences:

test/fixtures/diffs/subversion.diff (working copy)
22 22
+<% diff.each do |table_file| -%>
23 23
 <div class="autoscroll">
24 24
 <% if diff_type == 'sbs' -%>
25
 <table class="filecontent CodeRay">
25
 <table class="filecontent Pygments">
26 26
@@ -62,3 +63,5 @@
27 27
 
28 28
 </div>
app/helpers/application_helper.rb (working copy)
188 188
    l(:actionview_datehelper_select_month_names).split(',')[month-1]
189 189
  end
190 190

  
191
#  def syntax_highlight(name, content)
192
#    type = CodeRay::FileType[name]
193
#    type ? CodeRay.scan(content, type).html : h(content)
194
#  end
195
  
191 196
  def syntax_highlight(name, content)
192
    type = CodeRay::FileType[name]
193
    type ? CodeRay.scan(content, type).html : h(content)
197
    f = IO.popen("pygmentize -N " + name, 'r')
198
    lexer = f.read[0...-1] # removes trailing newline
199
 
200
    f = IO.popen("pygmentize -f html -l " + lexer, 'w+')
201
    f.write(content)
202
    f.close_write
203
    return f.read[28...-13]# removes surrounding div and pre as well as trailing newline
194 204
  end
195 205

  
196 206
  def to_path_param(path)
app/views/repositories/diff.rhtml (working copy)
15 15
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
16 16
<% end -%>
17 17

  
18
<p class="other-formats">
18
#<table class="filecontent Pygments">
19
#<p class="other-formats">
20
<p class="filecontent Pygments">
19 21
<%= l(:label_export_to) %>
20 22
<span><%= link_to 'Unified diff', params.merge(:format => 'diff') %></span>
21 23
</p>
app/views/repositories/annotate.rhtml (working copy)
5 5
<% colors = Hash.new {|k,v| k[v] = (k.size % 12) } %>
6 6

  
7 7
<div class="autoscroll">
8
<table class="filecontent annotate CodeRay">
8
<table class="filecontent annotate Pygments">
9 9
  <tbody>
10 10
    <% line_num = 1 %>
11 11
    <% syntax_highlight(@path, to_utf8(@annotate.content)).each_line do |line| %>
app/views/common/_file.rhtml (working copy)
1 1
<div class="autoscroll">
2
<table class="filecontent CodeRay">
2
<table class="filecontent Pygments">
3 3
<tbody>
4 4
<% line_num = 1 %>
5 5
<% syntax_highlight(filename, to_utf8(content)).each_line do |line| %>
app/views/common/_diff.rhtml (working copy)
2 2
<% diff.each do |table_file| -%>
3 3
<div class="autoscroll">
4 4
<% if diff_type == 'sbs' -%>
5
<table class="filecontent CodeRay">
5
<table class="filecontent Pygments">
6 6
<thead>
7 7
<tr><th colspan="4" class="filename"><%= table_file.file_name %></th></tr>
8 8
</thead>
......
29 29
</table>
30 30

  
31 31
<% else -%>
32
<table class="filecontent CodeRay">
32
<table class="filecontent Pygments">
33 33
<thead>
34 34
<tr><th colspan="3" class="filename"><%= table_file.file_name %></th></tr>
35 35
</thead>
app/views/wiki/annotate.rhtml (working copy)
12 12

  
13 13
<% colors = Hash.new {|k,v| k[v] = (k.size % 12) } %>
14 14

  
15
<table class="filecontent annotate CodeRay ">
15
<table class="filecontent annotate Pygments ">
16 16
<tbody>
17 17
<% line_num = 1 %>
18 18
<% @annotate.lines.each do |line| -%>
config/environment.rb (working copy)
2 2

  
3 3
# Uncomment below to force Rails into production mode when 
4 4
# you don't control web/app server and can't set it the proper way
5
# ENV['RAILS_ENV'] ||= 'production'
5
ENV['RAILS_ENV'] ||= 'production'
6 6

  
7 7
# Specifies gem version of Rails to use when vendor/rails is not present
8 8
RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION
......
54 54
  # Define your email configuration in email.yml instead.
55 55
  # It will automatically turn deliveries on
56 56
  config.action_mailer.perform_deliveries = false
57

  
58
  config.action_mailer.raise_delivery_errors = true
57 59
end
lib/redmine/wiki_formatting/textile/formatter.rb (working copy)
17 17

  
18 18
require 'redcloth3'
19 19
require 'coderay'
20
require 'cgi'
20 21

  
21 22
module Redmine
22 23
  module WikiFormatting
......
30 31
          super
31 32
          self.hard_breaks=true
32 33
          self.no_span_caps=true
33
          self.filter_styles=true
34
          self.filter_styles=false
34 35
        end
35 36
        
36 37
        def to_html(*rules, &block)
......
46 47
        def hard_break( text ) 
47 48
          text.gsub!( /(.)\n(?!\n|\Z|>| *(>? *[#*=]+(\s|$)|[{|]))/, "\\1<br />\n" ) if hard_breaks 
48 49
        end
49
        
50
       
51
        def syntax_highlight(name, content)
52
          #f = IO.popen("pygmentize -N " + name, 'r')
53
          #lexer = f.read[0...-1] # removes trailing newline
54
          #name = "text"
55
          content.gsub!("x%x%", "&")
56
          content = CGI.unescapeHTML(content)
57
          #content = "nglString& rString;"
58
          ff = File.new("/var/www/redmine/log/bleh.log", 'w+')
59
          ff.write(content)
60
          ff.close
61
          f = IO.popen("pygmentize -f html -l " + name , 'w+')
62
          f.write(content)
63
          f.close_write
64
          return f.read[28...-13]# removes surrounding div and pre as well as trailing newline
65
        end
66
 
50 67
        # Patch to add code highlighting support to RedCloth
51 68
        def smooth_offtags( text )
52 69
          unless @pre_list.empty?
53 70
            ## replace <pre> content
54 71
            text.gsub!(/<redpre#(\d+)>/) do
55 72
              content = @pre_list[$1.to_i]
73
              #if content.match(/<code\s+class="(\w+)">\s?(.+)/m)
74
              #  content = "<code class=\"#{$1} CodeRay\">" + 
75
              #    CodeRay.scan($2, $1.downcase).html(:escape => false, :line_numbers => :inline)
76
              #end
56 77
              if content.match(/<code\s+class="(\w+)">\s?(.+)/m)
57
                content = "<code class=\"#{$1} CodeRay\">" + 
58
                  CodeRay.scan($2, $1.downcase).html(:escape => false, :line_numbers => :inline)
78
                content = "<code class=\"#{$1} Pygments\">" +
79
                  syntax_highlight($1.downcase, $2)
80
                #content = $2
59 81
              end
60 82
              content
61 83
            end
public/stylesheets/scm.css (working copy)
178 178
.CodeRay .ty { color:#339; font-weight:bold }
179 179
.CodeRay .v  { color:#036 }
180 180
.CodeRay .xt { color:#444 }
181
.Pygments .hll { background-color: #ffffcc }
182
.Pygments  { background: #ffffff; }
183
.Pygments .c { color: #808080 } /* Comment */
184
.Pygments .err { color: #F00000; background-color: #F0A0A0 } /* Error */
185
.Pygments .k { color: #008000; font-weight: bold } /* Keyword */
186
.Pygments .o { color: #303030 } /* Operator */
187
.Pygments .cm { color: #e08080 } /* Comment.Multiline */
188
.Pygments .cp { color: #507090 } /* Comment.Preproc */
189
.Pygments .c1 { color: #e08080 } /* Comment.Single */
190
.Pygments .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
191
.Pygments .gd { color: #A00000 } /* Generic.Deleted */
192
.Pygments .ge { font-style: italic } /* Generic.Emph */
193
.Pygments .gr { color: #FF0000 } /* Generic.Error */
194
.Pygments .gh { color: #000080; font-weight: bold } /* Generic.Heading */
195
.Pygments .gi { color: #00A000 } /* Generic.Inserted */
196
.Pygments .go { color: #808080 } /* Generic.Output */
197
.Pygments .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
198
.Pygments .gs { font-weight: bold } /* Generic.Strong */
199
.Pygments .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
200
.Pygments .gt { color: #0040D0 } /* Generic.Traceback */
201
.Pygments .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
202
.Pygments .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
203
.Pygments .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
204
.Pygments .kp { color: #003080; font-weight: bold } /* Keyword.Pseudo */
205
.Pygments .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
206
.Pygments .kt { color: #303090; font-weight: bold } /* Keyword.Type */
207
.Pygments .m { color: #6000E0; font-weight: bold } /* Literal.Number */
208
.Pygments .s { background-color: #fff0f0 } /* Literal.String */
209
.Pygments .na { color: #0000C0 } /* Name.Attribute */
210
.Pygments .nb { color: #007020 } /* Name.Builtin */
211
.Pygments .nc { color: #B00060; font-weight: bold } /* Name.Class */
212
.Pygments .no { color: #003060; font-weight: bold } /* Name.Constant */
213
.Pygments .nd { color: #505050; font-weight: bold } /* Name.Decorator */
214
.Pygments .ni { color: #800000; font-weight: bold } /* Name.Entity */
215
.Pygments .ne { color: #F00000; font-weight: bold } /* Name.Exception */
216
.Pygments .nf { color: #0060B0; font-weight: bold } /* Name.Function */
217
.Pygments .nl { color: #907000; font-weight: bold } /* Name.Label */
218
.Pygments .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
219
.Pygments .nt { color: #007000 } /* Name.Tag */
220
.Pygments .nv { color: #906030 } /* Name.Variable */
221
.Pygments .ow { color: #000000; font-weight: bold } /* Operator.Word */
222
.Pygments .w { color: #bbbbbb } /* Text.Whitespace */
223
.Pygments .mf { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
224
.Pygments .mh { color: #005080; font-weight: bold } /* Literal.Number.Hex */
225
.Pygments .mi { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
226
.Pygments .mo { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
227
.Pygments .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
228
.Pygments .sc { color: #0040D0 } /* Literal.String.Char */
229
.Pygments .sd { color: #D04020 } /* Literal.String.Doc */
230
.Pygments .s2 { background-color: #fff0f0 } /* Literal.String.Double */
231
.Pygments .se { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
232
.Pygments .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
233
.Pygments .si { background-color: #e0e0e0 } /* Literal.String.Interpol */
234
.Pygments .sx { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
235
.Pygments .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
236
.Pygments .s1 { background-color: #fff0f0 } /* Literal.String.Single */
237
.Pygments .ss { color: #A06000 } /* Literal.String.Symbol */
238
.Pygments .bp { color: #007020 } /* Name.Builtin.Pseudo */
239
.Pygments .vc { color: #306090 } /* Name.Variable.Class */
240
.Pygments .vg { color: #d07000; font-weight: bold } /* Name.Variable.Global */
241
.Pygments .vi { color: #3030B0 } /* Name.Variable.Instance */
242
.Pygments .il { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */
243

  
244
.Pygments pre { margin: 0px; }
public/stylesheets/application.css (working copy)
477 477
    overflow-x: auto;
478 478
}
479 479

  
480
div.wiki pre.nui 
481
{
482
  border: none;
483
  overflow-x: auto;
484
  //color: rgb(36,90,175);
485
  color: #666666;
486
  width: 95%;
487
  background-color: #ffffff;
488
  margin-left: 20pt;
489
  margin-bottom: -22pt;
490
}
491

  
492
div.wiki pre.nuiSimple
493
{
494
  border: none;
495
  overflow-x: auto;
496
  //color: rgb(36,90,175);
497
  color: #666666;
498
  width: 95%;
499
  background-color: #ffffff;
500
  margin-left: 20pt;
501
}
502

  
503

  
504
div.wiki pre.nuiComment
505
{
506
  border: none;
507
  overflow-x: auto;
508
  color: rgb(179,65,65);
509
  width: 95%;
510
  background-color: #ffffff;
511
  margin-bottom:-23pt;
512
  margin-left: 20pt;
513
}
514

  
515

  
516

  
480 517
div.wiki ul.toc {
481 518
    background-color: #ffffdd;
482 519
    border: 1px solid #e4e4e4;
......
680 717
  #main { background: #fff; }
681 718
  #content { width: 99%; margin: 0; padding: 0; border: 0; background: #fff; overflow: visible !important;}
682 719
}
720

  
721

  
722
/***** Pygments ***********/
723
.Pygments .hll { background-color: #ffffcc }
724
.Pygments  { background: #ffffff; }
725
.Pygments .c { color: #808080 } /* Comment */
726
.Pygments .err { color: #F00000; background-color: #F0A0A0 } /* Error */
727
.Pygments .k { color: #008000; font-weight: bold } /* Keyword */
728
.Pygments .o { color: #303030 } /* Operator */
729
.Pygments .cm { color: #e08080 } /* Comment.Multiline */
730
.Pygments .cp { color: #507090 } /* Comment.Preproc */
731
.Pygments .c1 { color: #e08080 } /* Comment.Single */
732
.Pygments .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
733
.Pygments .gd { color: #A00000 } /* Generic.Deleted */
734
.Pygments .ge { font-style: italic } /* Generic.Emph */
735
.Pygments .gr { color: #FF0000 } /* Generic.Error */
736
.Pygments .gh { color: #000080; font-weight: bold } /* Generic.Heading */
737
.Pygments .gi { color: #00A000 } /* Generic.Inserted */
738
.Pygments .go { color: #808080 } /* Generic.Output */
739
.Pygments .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
740
.Pygments .gs { font-weight: bold } /* Generic.Strong */
741
.Pygments .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
742
.Pygments .gt { color: #0040D0 } /* Generic.Traceback */
743
.Pygments .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
744
.Pygments .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
745
.Pygments .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
746
.Pygments .kp { color: #003080; font-weight: bold } /* Keyword.Pseudo */
747
.Pygments .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
748
.Pygments .kt { color: #303090; font-weight: bold } /* Keyword.Type */
749
.Pygments .m { color: #6000E0; font-weight: bold } /* Literal.Number */
750
.Pygments .s { background-color: #fff0f0 } /* Literal.String */
751
.Pygments .na { color: #0000C0 } /* Name.Attribute */
752
.Pygments .nb { color: #007020 } /* Name.Builtin */
753
.Pygments .nc { color: #B00060; font-weight: bold } /* Name.Class */
754
.Pygments .no { color: #003060; font-weight: bold } /* Name.Constant */
755
.Pygments .nd { color: #505050; font-weight: bold } /* Name.Decorator */
756
.Pygments .ni { color: #800000; font-weight: bold } /* Name.Entity */
757
.Pygments .ne { color: #F00000; font-weight: bold } /* Name.Exception */
758
.Pygments .nf { color: #0060B0; font-weight: bold } /* Name.Function */
759
.Pygments .nl { color: #907000; font-weight: bold } /* Name.Label */
760
.Pygments .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
761
.Pygments .nt { color: #007000 } /* Name.Tag */
762
.Pygments .nv { color: #906030 } /* Name.Variable */
763
.Pygments .ow { color: #000000; font-weight: bold } /* Operator.Word */
764
.Pygments .w { color: #bbbbbb } /* Text.Whitespace */
765
.Pygments .mf { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
766
.Pygments .mh { color: #005080; font-weight: bold } /* Literal.Number.Hex */
767
.Pygments .mi { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
768
.Pygments .mo { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
769
.Pygments .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
770
.Pygments .sc { color: #0040D0 } /* Literal.String.Char */
771
.Pygments .sd { color: #D04020 } /* Literal.String.Doc */
772
.Pygments .s2 { background-color: #fff0f0 } /* Literal.String.Double */
773
.Pygments .se { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
774
.Pygments .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
775
.Pygments .si { background-color: #e0e0e0 } /* Literal.String.Interpol */
776
.Pygments .sx { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
777
.Pygments .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
778
.Pygments .s1 { background-color: #fff0f0 } /* Literal.String.Single */
779
.Pygments .ss { color: #A06000 } /* Literal.String.Symbol */
780
.Pygments .bp { color: #007020 } /* Name.Builtin.Pseudo */
781
.Pygments .vc { color: #306090 } /* Name.Variable.Class */
782
.Pygments .vg { color: #d07000; font-weight: bold } /* Name.Variable.Global */
783
.Pygments .vi { color: #3030B0 } /* Name.Variable.Instance */
784
.Pygments .il { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */
785

  
786
.Pygments pre { margin: 0px; }
787

  
(5-5/6)