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)
+<% diff.each do |table_file| -%>
<div class="autoscroll">
<% if diff_type == 'sbs' -%>
<table class="filecontent CodeRay">
<table class="filecontent Pygments">
@@ -62,3 +63,5 @@
</div>
app/helpers/application_helper.rb (working copy)
l(:actionview_datehelper_select_month_names).split(',')[month-1]
end
# def syntax_highlight(name, content)
# type = CodeRay::FileType[name]
# type ? CodeRay.scan(content, type).html : h(content)
# end
def syntax_highlight(name, content)
type = CodeRay::FileType[name]
type ? CodeRay.scan(content, type).html : h(content)
f = IO.popen("pygmentize -N " + name, 'r')
lexer = f.read[0...-1] # removes trailing newline
f = IO.popen("pygmentize -f html -l " + lexer, 'w+')
f.write(content)
f.close_write
return f.read[28...-13]# removes surrounding div and pre as well as trailing newline
end
def to_path_param(path)
app/views/repositories/diff.rhtml (working copy)
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
<% end -%>
<p class="other-formats">
#<table class="filecontent Pygments">
#<p class="other-formats">
<p class="filecontent Pygments">
<%= l(:label_export_to) %>
<span><%= link_to 'Unified diff', params.merge(:format => 'diff') %></span>
</p>
app/views/repositories/annotate.rhtml (working copy)
<% colors = Hash.new {|k,v| k[v] = (k.size % 12) } %>
<div class="autoscroll">
<table class="filecontent annotate CodeRay">
<table class="filecontent annotate Pygments">
<tbody>
<% line_num = 1 %>
<% syntax_highlight(@path, to_utf8(@annotate.content)).each_line do |line| %>
app/views/common/_file.rhtml (working copy)
<div class="autoscroll">
<table class="filecontent CodeRay">
<table class="filecontent Pygments">
<tbody>
<% line_num = 1 %>
<% syntax_highlight(filename, to_utf8(content)).each_line do |line| %>
app/views/common/_diff.rhtml (working copy)
<% diff.each do |table_file| -%>
<div class="autoscroll">
<% if diff_type == 'sbs' -%>
<table class="filecontent CodeRay">
<table class="filecontent Pygments">
<thead>
<tr><th colspan="4" class="filename"><%= table_file.file_name %></th></tr>
</thead>
......
</table>
<% else -%>
<table class="filecontent CodeRay">
<table class="filecontent Pygments">
<thead>
<tr><th colspan="3" class="filename"><%= table_file.file_name %></th></tr>
</thead>
app/views/wiki/annotate.rhtml (working copy)
<% colors = Hash.new {|k,v| k[v] = (k.size % 12) } %>
<table class="filecontent annotate CodeRay ">
<table class="filecontent annotate Pygments ">
<tbody>
<% line_num = 1 %>
<% @annotate.lines.each do |line| -%>
config/environment.rb (working copy)
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION
......
# Define your email configuration in email.yml instead.
# It will automatically turn deliveries on
config.action_mailer.perform_deliveries = false
config.action_mailer.raise_delivery_errors = true
end
lib/redmine/wiki_formatting/textile/formatter.rb (working copy)
require 'redcloth3'
require 'coderay'
require 'cgi'
module Redmine
module WikiFormatting
......
super
self.hard_breaks=true
self.no_span_caps=true
self.filter_styles=true
self.filter_styles=false
end
def to_html(*rules, &block)
......
def hard_break( text )
text.gsub!( /(.)\n(?!\n|\Z|>| *(>? *[#*=]+(\s|$)|[{|]))/, "\\1<br />\n" ) if hard_breaks
end
def syntax_highlight(name, content)
#f = IO.popen("pygmentize -N " + name, 'r')
#lexer = f.read[0...-1] # removes trailing newline
#name = "text"
content.gsub!("x%x%", "&")
content = CGI.unescapeHTML(content)
#content = "nglString& rString;"
ff = File.new("/var/www/redmine/log/bleh.log", 'w+')
ff.write(content)
ff.close
f = IO.popen("pygmentize -f html -l " + name , 'w+')
f.write(content)
f.close_write
return f.read[28...-13]# removes surrounding div and pre as well as trailing newline
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.downcase).html(:escape => false, :line_numbers => :inline)
#end
if content.match(/<code\s+class="(\w+)">\s?(.+)/m)
content = "<code class=\"#{$1} CodeRay\">" +
CodeRay.scan($2, $1.downcase).html(:escape => false, :line_numbers => :inline)
content = "<code class=\"#{$1} Pygments\">" +
syntax_highlight($1.downcase, $2)
#content = $2
end
content
end
public/stylesheets/scm.css (working copy)
.CodeRay .ty { color:#339; font-weight:bold }
.CodeRay .v { color:#036 }
.CodeRay .xt { color:#444 }
.Pygments .hll { background-color: #ffffcc }
.Pygments { background: #ffffff; }
.Pygments .c { color: #808080 } /* Comment */
.Pygments .err { color: #F00000; background-color: #F0A0A0 } /* Error */
.Pygments .k { color: #008000; font-weight: bold } /* Keyword */
.Pygments .o { color: #303030 } /* Operator */
.Pygments .cm { color: #e08080 } /* Comment.Multiline */
.Pygments .cp { color: #507090 } /* Comment.Preproc */
.Pygments .c1 { color: #e08080 } /* Comment.Single */
.Pygments .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
.Pygments .gd { color: #A00000 } /* Generic.Deleted */
.Pygments .ge { font-style: italic } /* Generic.Emph */
.Pygments .gr { color: #FF0000 } /* Generic.Error */
.Pygments .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.Pygments .gi { color: #00A000 } /* Generic.Inserted */
.Pygments .go { color: #808080 } /* Generic.Output */
.Pygments .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.Pygments .gs { font-weight: bold } /* Generic.Strong */
.Pygments .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.Pygments .gt { color: #0040D0 } /* Generic.Traceback */
.Pygments .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.Pygments .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.Pygments .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.Pygments .kp { color: #003080; font-weight: bold } /* Keyword.Pseudo */
.Pygments .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.Pygments .kt { color: #303090; font-weight: bold } /* Keyword.Type */
.Pygments .m { color: #6000E0; font-weight: bold } /* Literal.Number */
.Pygments .s { background-color: #fff0f0 } /* Literal.String */
.Pygments .na { color: #0000C0 } /* Name.Attribute */
.Pygments .nb { color: #007020 } /* Name.Builtin */
.Pygments .nc { color: #B00060; font-weight: bold } /* Name.Class */
.Pygments .no { color: #003060; font-weight: bold } /* Name.Constant */
.Pygments .nd { color: #505050; font-weight: bold } /* Name.Decorator */
.Pygments .ni { color: #800000; font-weight: bold } /* Name.Entity */
.Pygments .ne { color: #F00000; font-weight: bold } /* Name.Exception */
.Pygments .nf { color: #0060B0; font-weight: bold } /* Name.Function */
.Pygments .nl { color: #907000; font-weight: bold } /* Name.Label */
.Pygments .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.Pygments .nt { color: #007000 } /* Name.Tag */
.Pygments .nv { color: #906030 } /* Name.Variable */
.Pygments .ow { color: #000000; font-weight: bold } /* Operator.Word */
.Pygments .w { color: #bbbbbb } /* Text.Whitespace */
.Pygments .mf { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
.Pygments .mh { color: #005080; font-weight: bold } /* Literal.Number.Hex */
.Pygments .mi { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
.Pygments .mo { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
.Pygments .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
.Pygments .sc { color: #0040D0 } /* Literal.String.Char */
.Pygments .sd { color: #D04020 } /* Literal.String.Doc */
.Pygments .s2 { background-color: #fff0f0 } /* Literal.String.Double */
.Pygments .se { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
.Pygments .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
.Pygments .si { background-color: #e0e0e0 } /* Literal.String.Interpol */
.Pygments .sx { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
.Pygments .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
.Pygments .s1 { background-color: #fff0f0 } /* Literal.String.Single */
.Pygments .ss { color: #A06000 } /* Literal.String.Symbol */
.Pygments .bp { color: #007020 } /* Name.Builtin.Pseudo */
.Pygments .vc { color: #306090 } /* Name.Variable.Class */
.Pygments .vg { color: #d07000; font-weight: bold } /* Name.Variable.Global */
.Pygments .vi { color: #3030B0 } /* Name.Variable.Instance */
.Pygments .il { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */
.Pygments pre { margin: 0px; }
public/stylesheets/application.css (working copy)
overflow-x: auto;
}
div.wiki pre.nui
{
border: none;
overflow-x: auto;
//color: rgb(36,90,175);
color: #666666;
width: 95%;
background-color: #ffffff;
margin-left: 20pt;
margin-bottom: -22pt;
}
div.wiki pre.nuiSimple
{
border: none;
overflow-x: auto;
//color: rgb(36,90,175);
color: #666666;
width: 95%;
background-color: #ffffff;
margin-left: 20pt;
}
div.wiki pre.nuiComment
{
border: none;
overflow-x: auto;
color: rgb(179,65,65);
width: 95%;
background-color: #ffffff;
margin-bottom:-23pt;
margin-left: 20pt;
}
div.wiki ul.toc {
background-color: #ffffdd;
border: 1px solid #e4e4e4;
......
#main { background: #fff; }
#content { width: 99%; margin: 0; padding: 0; border: 0; background: #fff; overflow: visible !important;}
}
/***** Pygments ***********/
.Pygments .hll { background-color: #ffffcc }
.Pygments { background: #ffffff; }
.Pygments .c { color: #808080 } /* Comment */
.Pygments .err { color: #F00000; background-color: #F0A0A0 } /* Error */
.Pygments .k { color: #008000; font-weight: bold } /* Keyword */
.Pygments .o { color: #303030 } /* Operator */
.Pygments .cm { color: #e08080 } /* Comment.Multiline */
.Pygments .cp { color: #507090 } /* Comment.Preproc */
.Pygments .c1 { color: #e08080 } /* Comment.Single */
.Pygments .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
.Pygments .gd { color: #A00000 } /* Generic.Deleted */
.Pygments .ge { font-style: italic } /* Generic.Emph */
.Pygments .gr { color: #FF0000 } /* Generic.Error */
.Pygments .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.Pygments .gi { color: #00A000 } /* Generic.Inserted */
.Pygments .go { color: #808080 } /* Generic.Output */
.Pygments .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.Pygments .gs { font-weight: bold } /* Generic.Strong */
.Pygments .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.Pygments .gt { color: #0040D0 } /* Generic.Traceback */
.Pygments .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.Pygments .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.Pygments .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.Pygments .kp { color: #003080; font-weight: bold } /* Keyword.Pseudo */
.Pygments .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.Pygments .kt { color: #303090; font-weight: bold } /* Keyword.Type */
.Pygments .m { color: #6000E0; font-weight: bold } /* Literal.Number */
.Pygments .s { background-color: #fff0f0 } /* Literal.String */
.Pygments .na { color: #0000C0 } /* Name.Attribute */
.Pygments .nb { color: #007020 } /* Name.Builtin */
.Pygments .nc { color: #B00060; font-weight: bold } /* Name.Class */
.Pygments .no { color: #003060; font-weight: bold } /* Name.Constant */
.Pygments .nd { color: #505050; font-weight: bold } /* Name.Decorator */
.Pygments .ni { color: #800000; font-weight: bold } /* Name.Entity */
.Pygments .ne { color: #F00000; font-weight: bold } /* Name.Exception */
.Pygments .nf { color: #0060B0; font-weight: bold } /* Name.Function */
.Pygments .nl { color: #907000; font-weight: bold } /* Name.Label */
.Pygments .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.Pygments .nt { color: #007000 } /* Name.Tag */
.Pygments .nv { color: #906030 } /* Name.Variable */
.Pygments .ow { color: #000000; font-weight: bold } /* Operator.Word */
.Pygments .w { color: #bbbbbb } /* Text.Whitespace */
.Pygments .mf { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
.Pygments .mh { color: #005080; font-weight: bold } /* Literal.Number.Hex */
.Pygments .mi { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
.Pygments .mo { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
.Pygments .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
.Pygments .sc { color: #0040D0 } /* Literal.String.Char */
.Pygments .sd { color: #D04020 } /* Literal.String.Doc */
.Pygments .s2 { background-color: #fff0f0 } /* Literal.String.Double */
.Pygments .se { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
.Pygments .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
.Pygments .si { background-color: #e0e0e0 } /* Literal.String.Interpol */
.Pygments .sx { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
.Pygments .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
.Pygments .s1 { background-color: #fff0f0 } /* Literal.String.Single */
.Pygments .ss { color: #A06000 } /* Literal.String.Symbol */
.Pygments .bp { color: #007020 } /* Name.Builtin.Pseudo */
.Pygments .vc { color: #306090 } /* Name.Variable.Class */
.Pygments .vg { color: #d07000; font-weight: bold } /* Name.Variable.Global */
.Pygments .vi { color: #3030B0 } /* Name.Variable.Instance */
.Pygments .il { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */
.Pygments pre { margin: 0px; }
(5-5/6)