Feature #2985 » syntax_highlighting.diff
| app/helpers/application_helper.rb (working copy) | ||
|---|---|---|
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require 'coderay'
|
||
|
require 'coderay/helpers/file_type'
|
||
|
require 'forwardable'
|
||
|
require 'cgi'
|
||
| ... | ... | |
|
end
|
||
|
def syntax_highlight(name, content)
|
||
|
type = CodeRay::FileType[name]
|
||
|
type ? CodeRay.scan(content, type).html : h(content)
|
||
|
Redmine::SyntaxHighlighting.colorize_file(name, content)
|
||
|
end
|
||
|
def to_path_param(path)
|
||
| app/views/settings/_general.rhtml (working copy) | ||
|---|---|---|
|
<p><label><%= l(:setting_text_formatting) %></label>
|
||
|
<%= select_tag 'settings[text_formatting]', options_for_select([[l(:label_none), "0"], *Redmine::WikiFormatting.format_names.collect{|name| [name, name]} ], Setting.text_formatting.to_sym) %></p>
|
||
|
<p><label><%= l(:label_syntax_highlighter) %></label>
|
||
|
<%= select_tag 'settings[syntax_highlighter]', options_for_select( (Redmine::SyntaxHighlighting.available_highlighters.collect{|h| [h, h]}), Setting.syntax_highlighter) %></p>
|
||
|
<p><label><%= l(:setting_wiki_compression) %></label>
|
||
|
<%= select_tag 'settings[wiki_compression]', options_for_select( [[l(:label_none), 0], ["gzip", "gzip"]], Setting.wiki_compression) %></p>
|
||
| app/views/attachments/file.rhtml (working copy) | ||
|---|---|---|
|
</div>
|
||
|
|
||
|
<%= render :partial => 'common/file', :locals => {:content => @content, :filename => @attachment.filename} %>
|
||
|
<%= render :partial => 'common/file', :locals => {:content => @content, :filename => @attachment.disk_filename} %>
|
||
|
<% content_for :header_tags do -%>
|
||
|
<%= stylesheet_link_tag "scm" -%>
|
||
| app/views/common/_file.rhtml (working copy) | ||
|---|---|---|
|
<div class="autoscroll">
|
||
|
<table class="filecontent CodeRay">
|
||
|
<table class="filecontent">
|
||
|
<tbody>
|
||
|
<% line_num = 1 %>
|
||
|
<% syntax_highlight(filename, to_utf8(content)).each_line do |line| %>
|
||
|
<tr><th class="line-num" id="L<%= line_num %>"><a href="#L<%= line_num %>"><%= line_num %></a></th><td class="line-code"><pre><%= line %></pre></td></tr>
|
||
|
<tr><th class="line-num" id="L<%= line_num %>"><a href="#L<%= line_num %>"><%= line_num %></a></th><td class="line-code"><%= line %></td></tr>
|
||
|
<% line_num += 1 %>
|
||
|
<% end %>
|
||
|
</tbody>
|
||
| config/settings.yml (working copy) | ||
|---|---|---|
|
default: 0
|
||
|
openid:
|
||
|
default: 0
|
||
|
syntax_highlighter:
|
||
|
default: 'DefaultCodeRay'
|
||
| config/locales/en.yml (working copy) | ||
|---|---|---|
|
label_ascending: Ascending
|
||
|
label_descending: Descending
|
||
|
label_date_from_to: From {{start}} to {{end}}
|
||
|
label_syntax_highlighter: Syntax highlighter
|
||
|
|
||
|
button_login: Login
|
||
|
button_submit: Submit
|
||
| config/locales/fr.yml (working copy) | ||
|---|---|---|
|
label_ascending: Croissant
|
||
|
label_descending: Décroissant
|
||
|
label_date_from_to: Du {{start}} au {{end}}
|
||
|
label_syntax_highlighter: Colorateur syntaxique
|
||
|
|
||
|
button_login: Connexion
|
||
|
button_submit: Soumettre
|
||
| lib/redmine/wiki_formatting/textile/formatter.rb (working copy) | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require 'redcloth3'
|
||
|
require 'coderay'
|
||
|
module Redmine
|
||
|
module WikiFormatting
|
||
| ... | ... | |
|
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)
|
||
|
content = Redmine::SyntaxHighlighting.colorize($2, $1)
|
||
|
end
|
||
|
content
|
||
|
end
|
||
| lib/redmine/syntax_highlighting.rb (revision 0) | ||
|---|---|---|
|
# Redmine - project management software
|
||
|
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
module Redmine
|
||
|
module SyntaxHighlighting
|
||
|
|
||
|
class << self
|
||
|
# get highlighter class object
|
||
|
def highlighter
|
||
|
const_get(Setting.syntax_highlighter)
|
||
|
end
|
||
|
# get all available highlighters
|
||
|
def available_highlighters
|
||
|
constants.sort - ["SyntaxAssets"]
|
||
|
end
|
||
|
|
||
|
# used in the wiki to colorize text
|
||
|
def colorize(text, format="")
|
||
|
raise "#{highlighter} should implement 'colorize' method !" unless highlighter.respond_to?(:colorize)
|
||
|
highlighter.colorize(text, format)
|
||
|
end
|
||
|
|
||
|
# used in attachments/repository to colorize files
|
||
|
def colorize_file(filename, content)
|
||
|
raise "#{highlighter} should implement 'colorize_file' method !" unless highlighter.respond_to?(:colorize_file)
|
||
|
highlighter.colorize_file(filename, content)
|
||
|
end
|
||
|
|
||
|
end
|
||
|
#hook to add chosen highlighter specific js and css tags in layout header
|
||
|
class SyntaxAssets < Redmine::Hook::ViewListener
|
||
|
def view_layouts_base_html_head(context)
|
||
|
res = []
|
||
|
h = Redmine::SyntaxHighlighting.highlighter
|
||
|
# specific stylesheets ; just define a "stylesheets" method returning an array
|
||
|
h.stylesheets.each do |args|
|
||
|
res << stylesheet_link_tag(*args)
|
||
|
end if h.respond_to?(:stylesheets)
|
||
|
# specific javascripts ; just define a "javascripts" method returning an array
|
||
|
h.javascripts.each do |args|
|
||
|
res << javascript_include_tag(*args)
|
||
|
end if h.respond_to?(:javascripts)
|
||
|
res.join
|
||
|
end
|
||
|
end
|
||
|
Redmine::Hook.add_listener(SyntaxAssets)
|
||
|
|
||
|
#default highlighter
|
||
|
module DefaultCodeRay
|
||
|
require 'coderay'
|
||
|
require 'coderay/helpers/file_type'
|
||
|
|
||
|
class << self
|
||
|
def colorize(text, format)
|
||
|
"<code class=\"#{format} CodeRay\">" +
|
||
|
CodeRay.scan(text, format.downcase).html(:escape => false, :line_numbers => :inline)
|
||
|
end
|
||
|
|
||
|
def colorize_file(filename, content)
|
||
|
type = CodeRay::FileType[filename]
|
||
|
result = type ? CodeRay.scan(content, type).html : ERB::Util.h(content)
|
||
|
# to keep old behaviour (<pre> tags were in common/_file.rhtml template, disturbing eventual other highlighter)
|
||
|
result.split(/\n/).map{|l| "<pre>#{l}</pre>"}.join("\n")
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
end
|
||
| lib/redmine.rb (working copy) | ||
|---|---|---|
|
require 'redmine/hook'
|
||
|
require 'redmine/plugin'
|
||
|
require 'redmine/wiki_formatting'
|
||
|
require 'redmine/syntax_highlighting'
|
||
|
begin
|
||
|
require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
|
||
| public/stylesheets/scm.css (working copy) | ||
|---|---|---|
|
color: inherit;
|
||
|
}
|
||
|
table.filecontent td.line-code pre {
|
||
|
margin: 0px;
|
||
|
white-space: pre-wrap; /* CSS2.1 compliant */
|
||
|
white-space: -moz-pre-wrap; /* Mozilla-based browsers */
|
||
|
white-space: -o-pre-wrap; /* Opera 7+ */
|
||