Commit 4748bb90 authored by emassip's avatar emassip

Update CodeRay version to 1.0 final (#4264).

git-svn-id: https://svn.redmine.org/redmine/trunk@7618 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent ac1cd385
......@@ -55,7 +55,7 @@ Rails::Initializer.run do |config|
config.action_mailer.perform_deliveries = false
config.gem 'rubytree', :lib => 'tree'
config.gem 'coderay', :version => '~>0.9.7'
config.gem 'coderay', :version => '~>1.0.0'
# Load any local configuration that is kept out of source control
# (e.g. gems, patches).
......
......@@ -46,7 +46,7 @@ module Redmine
# Highlights +text+ using +language+ syntax
# Should not return outer pre tag
def highlight_by_language(text, language)
::CodeRay.scan(text, language).html(:line_numbers => :inline, :wrap => :span)
::CodeRay.scan(text, language).html(:line_numbers => :inline, :line_number_anchors => false, :wrap => :span)
end
end
end
......
......@@ -18,20 +18,22 @@
}
a.new { color: #b73535; }
.CodeRay .c { color:#666; }
.CodeRay .cl { color:#B06; font-weight:bold }
.CodeRay .dl { color:black }
.CodeRay .fu { color:#06B; font-weight:bold }
.CodeRay .il { background: #eee }
.CodeRay .il .idl { font-weight: bold; color: #888 }
.CodeRay .iv { color:#33B }
.CodeRay .r { color:#080; font-weight:bold }
.CodeRay .s { background-color:#fff0f0 }
.CodeRay .s .dl { color:#710 }
.syntaxhl .line-numbers { padding: 2px 4px 2px 4px; background-color: #eee; margin:0 }
.syntaxhl .comment { color:#666; }
.syntaxhl .class { color:#B06; font-weight:bold }
.syntaxhl .delimiter { color:black }
.syntaxhl .function { color:#06B; font-weight:bold }
.syntaxhl .inline { background: #eee }
.syntaxhl .inline .inline-delimiter { font-weight: bold; color: #888 }
.syntaxhl .instance-variable { color:#33B }
.syntaxhl .reserved { color:#080; font-weight:bold }
.syntaxhl .string { background-color:#fff0f0; color: #D20; }
.syntaxhl .string .delimiter { color:#710 }
</style>
</head>
......@@ -242,7 +244,7 @@ To go live, all you need to add is a database and a web server.
<h2><a name="13" class="wiki-page"></a>Code highlighting</h2>
<p>Code highlightment relies on <a href="http://coderay.rubychan.de/" class="external">CodeRay</a>, a fast syntax highlighting library written completely in Ruby. It currently supports c, cpp, css, delphi, groovy, html, java, javascript, json, php, python, rhtml, ruby, scheme, sql, xml and yaml languages.</p>
<p>Default code highlightment relies on <a href="http://coderay.rubychan.de/" class="external">CodeRay</a>, a fast syntax highlighting library written completely in Ruby. It currently supports c, cpp, css, delphi, groovy, html, java, javascript, json, php, python, rhtml, ruby, scheme, sql, xml and yaml languages.</p>
<p>You can highlight code in your wiki page using this syntax:</p>
......@@ -254,17 +256,16 @@ To go live, all you need to add is a database and a web server.
<p>Example:</p>
<pre><code class="ruby CodeRay"><span class="no"> 1</span> <span class="c"># The Greeter class</span>
<span class="no"> 2</span> <span class="r">class</span> <span class="cl">Greeter</span>
<span class="no"> 3</span> <span class="r">def</span> <span class="fu">initialize</span>(name)
<span class="no"> 4</span> <span class="iv">@name</span> = name.capitalize
<span class="no"> 5</span> <span class="r">end</span>
<span class="no"> 6</span>
<span class="no"> 7</span> <span class="r">def</span> <span class="fu">salute</span>
<span class="no"> 8</span> puts <span class="s"><span class="dl">"</span><span class="k">Hello </span><span class="il"><span class="idl">#{</span><span class="iv">@name</span><span class="idl">}</span></span><span class="k">!</span><span class="dl">"</span></span>
<span class="no"> 9</span> <span class="r">end</span>
<span class="no"><strong>10</strong></span> <span class="r">end</span>
</code>
<pre><code class="ruby syntaxhl"><span class="line-numbers"> 1</span> <span class="comment"># The Greeter class</span>
<span class="line-numbers"> 2</span> <span class="reserved">class</span> <span class="class">Greeter</span>
<span class="line-numbers"> 3</span> <span class="reserved">def</span> <span class="function">initialize</span>(name)
<span class="line-numbers"> 4</span> <span class="instance-variable">@name</span> = name.capitalize
<span class="line-numbers"> 5</span> <span class="reserved">end</span>
<span class="line-numbers"> 6</span>
<span class="line-numbers"> 7</span> <span class="reserved">def</span> <span class="function">salute</span>
<span class="line-numbers"> 8</span> puts <span class="string"><span class="delimiter">"</span><span class="content">Hello </span><span class="inline"><span class="inline-delimiter">#{</span><span class="instance-variable">@name</span><span class="inline-delimiter">}</span></span><span class="content">!</span><span class="delimiter">"</span></span>
<span class="line-numbers"> 9</span> <span class="reserved">end</span>
<span class="line-numbers"><strong>10</strong></span> <span class="reserved">end</span></code>
</pre>
</body>
</html>
......@@ -91,105 +91,97 @@ div.action_A { background: #bfb }
/************* CodeRay styles *************/
.syntaxhl div {display: inline;}
.syntaxhl .no { padding: 2px 4px 2px 4px; background-color: #eee; margin:0 }
.syntaxhl .line-numbers { padding: 2px 4px 2px 4px; background-color: #eee; margin:0px 5px 0px 0px; }
.syntaxhl .code pre { overflow: auto }
.syntaxhl .debug { color:white ! important; background:blue ! important; }
.syntaxhl .af { color:#00C }
.syntaxhl .an { color:#007 }
.syntaxhl .at { color:#f08 }
.syntaxhl .av { color:#700 }
.syntaxhl .aw { color:#C00 }
.syntaxhl .bi { color:#509; font-weight:bold }
.syntaxhl .c { color:#888; }
.syntaxhl .ch { color:#04D }
.syntaxhl .ch .k { color:#04D }
.syntaxhl .ch .dl { color:#039 }
.syntaxhl .cl { color:#B06; font-weight:bold }
.syntaxhl .cm { color:#A08; font-weight:bold }
.syntaxhl .co { color:#036; font-weight:bold }
.syntaxhl .cr { color:#0A0 }
.syntaxhl .cv { color:#369 }
.syntaxhl .de { color:#B0B; }
.syntaxhl .df { color:#099; font-weight:bold }
.syntaxhl .di { color:#088; font-weight:bold }
.syntaxhl .dl { color:black }
.syntaxhl .do { color:#970 }
.syntaxhl .dt { color:#34b }
.syntaxhl .ds { color:#D42; font-weight:bold }
.syntaxhl .e { color:#666; font-weight:bold }
.syntaxhl .en { color:#800; font-weight:bold }
.syntaxhl .er { color:#F00; background-color:#FAA }
.syntaxhl .ex { color:#C00; font-weight:bold }
.syntaxhl .fl { color:#60E; font-weight:bold }
.syntaxhl .fu { color:#06B; font-weight:bold }
.syntaxhl .gv { color:#d70; font-weight:bold }
.syntaxhl .hx { color:#058; font-weight:bold }
.syntaxhl .i { color:#00D; font-weight:bold }
.syntaxhl .ic { color:#B44; font-weight:bold }
.syntaxhl .il { background: #ddd; color: black }
.syntaxhl .il .il { background: #ccc }
.syntaxhl .il .il .il { background: #bbb }
.syntaxhl .il .idl { background: #ddd; font-weight: bold; color: #666 }
.syntaxhl .idl { background-color: #bbb; font-weight: bold; color: #666; }
.syntaxhl .im { color:#f00; }
.syntaxhl .in { color:#B2B; font-weight:bold }
.syntaxhl .iv { color:#33B }
.syntaxhl .la { color:#970; font-weight:bold }
.syntaxhl .lv { color:#963 }
.syntaxhl .oc { color:#40E; font-weight:bold }
.syntaxhl .of { color:#000; font-weight:bold }
.syntaxhl .op { }
.syntaxhl .pc { color:#038; font-weight:bold }
.syntaxhl .pd { color:#369; font-weight:bold }
.syntaxhl .pp { color:#579; }
.syntaxhl .ps { color:#00C; font-weight:bold }
.syntaxhl .pt { color:#074; font-weight:bold }
.syntaxhl .r, .kw { color:#080; font-weight:bold }
.syntaxhl .ke { color: #808; }
.syntaxhl .ke .dl { color: #606; }
.syntaxhl .ke .ch { color: #80f; }
.syntaxhl .vl { color: #088; }
.syntaxhl .rx { background-color:#fff0ff }
.syntaxhl .rx .k { color:#808 }
.syntaxhl .rx .dl { color:#404 }
.syntaxhl .rx .mod { color:#C2C }
.syntaxhl .rx .fu { color:#404; font-weight: bold }
.syntaxhl .s { background-color:#fff0f0; color: #D20; }
.syntaxhl .s .s { background-color:#ffe0e0 }
.syntaxhl .s .s .s { background-color:#ffd0d0 }
.syntaxhl .s .k { }
.syntaxhl .s .ch { color: #b0b; }
.syntaxhl .s .dl { color: #710; }
.syntaxhl .sh { background-color:#f0fff0; color:#2B2 }
.syntaxhl .sh .k { }
.syntaxhl .sh .dl { color:#161 }
.syntaxhl .sy { color:#A60 }
.syntaxhl .sy .k { color:#A60 }
.syntaxhl .sy .dl { color:#630 }
.syntaxhl .ta { color:#070 }
.syntaxhl .tf { color:#070; font-weight:bold }
.syntaxhl .ts { color:#D70; font-weight:bold }
.syntaxhl .ty { color:#339; font-weight:bold }
.syntaxhl .v { color:#036 }
.syntaxhl .xt { color:#444 }
.syntaxhl .ins { background: #cfc; }
.syntaxhl .del { background: #fcc; }
.syntaxhl .chg { color: #aaf; background: #007; }
.syntaxhl .attribute-name { color:#007 }
.syntaxhl .annotation { color:#f08 }
.syntaxhl .attribute-value { color:#700 }
.syntaxhl .bin { color:#509; font-weight:bold }
.syntaxhl .comment { color:#888; }
.syntaxhl .char { color:#04D }
.syntaxhl .char .content { color:#04D }
.syntaxhl .char .delimiter { color:#039 }
.syntaxhl .class { color:#B06; font-weight:bold }
.syntaxhl .complex { color:#A08; font-weight:bold }
.syntaxhl .constant { color:#036; font-weight:bold }
.syntaxhl .color { color:#0A0 }
.syntaxhl .class-variable { color:#369 }
.syntaxhl .decorator { color:#B0B; }
.syntaxhl .definition { color:#099; font-weight:bold }
.syntaxhl .directive { color:#088; font-weight:bold }
.syntaxhl .delimiter { color:black }
.syntaxhl .doc { color:#970 }
.syntaxhl .doctype { color:#34b }
.syntaxhl .doc-string { color:#D42; font-weight:bold }
.syntaxhl .escape { color:#666; font-weight:bold }
.syntaxhl .entity { color:#800; font-weight:bold }
.syntaxhl .error { color:#F00; background-color:#FAA }
.syntaxhl .exception { color:#C00; font-weight:bold }
.syntaxhl .float { color:#60E; font-weight:bold }
.syntaxhl .function { color:#06B; font-weight:bold }
.syntaxhl .global-variable { color:#d70; font-weight:bold }
.syntaxhl .hex { color:#058; font-weight:bold }
.syntaxhl .integer { color:#00D; font-weight:bold }
.syntaxhl .include { color:#B44; font-weight:bold }
.syntaxhl .inline { background: #ddd; color: black }
.syntaxhl .inline .inline { background: #ccc }
.syntaxhl .inline .inline .inline { background: #bbb }
.syntaxhl .inline .inline-delimiter { background: #ddd; font-weight: bold; color: #666 }
.syntaxhl .inline-delimiter { background-color: #bbb; font-weight: bold; color: #666; }
.syntaxhl .important { color:#f00; }
.syntaxhl .instance-variable { color:#33B }
.syntaxhl .label { color:#970; font-weight:bold }
.syntaxhl .local-variable { color:#963 }
.syntaxhl .octal { color:#40E; font-weight:bold }
.syntaxhl .predefined-constant { color:#038; font-weight:bold }
.syntaxhl .predefined { color:#369; font-weight:bold }
.syntaxhl .preprocessor { color:#579; }
.syntaxhl .pseudo-class { color:#00C; font-weight:bold }
.syntaxhl .predefined-type { color:#074; font-weight:bold }
.syntaxhl .reserved, .keyword { color:#080; font-weight:bold }
.syntaxhl .key { color: #808; }
.syntaxhl .key .delimiter { color: #606; }
.syntaxhl .key .char { color: #80f; }
.syntaxhl .value { color: #088; }
.syntaxhl .regexp { background-color:#fff0ff }
.syntaxhl .regexp .content { color:#808 }
.syntaxhl .regexp .delimiter { color:#404 }
.syntaxhl .regexp .modifier { color:#C2C }
.syntaxhl .regexp .function { color:#404; font-weight: bold }
.syntaxhl .string { background-color:#fff0f0; color: #D20; }
.syntaxhl .string .string { background-color:#ffe0e0 }
.syntaxhl .string .string .string { background-color:#ffd0d0 }
.syntaxhl .string .content { }
.syntaxhl .string .char { color: #b0b; }
.syntaxhl .string .delimiter { color: #710; }
.syntaxhl .shell { background-color:#f0fff0; color:#2B2 }
.syntaxhl .shell .content { }
.syntaxhl .shell .delimiter { color:#161 }
.syntaxhl .symbol { color:#A60 }
.syntaxhl .symbol .content { color:#A60 }
.syntaxhl .symbol .delimiter { color:#630 }
.syntaxhl .tag { color:#070 }
.syntaxhl .type { color:#339; font-weight:bold }
.syntaxhl .variable { color:#036 }
.syntaxhl .insert { background: #cfc; }
.syntaxhl .delete { background: #fcc; }
.syntaxhl .change { color: #aaf; background: #007; }
.syntaxhl .head { color: #f8f; background: #505 }
.syntaxhl .ins .ins { color: #080; font-weight:bold }
.syntaxhl .del .del { color: #800; font-weight:bold }
.syntaxhl .chg .chg { color: #66f; }
.syntaxhl .insert .insert { color: #080; font-weight:bold }
.syntaxhl .delete .delete { color: #800; font-weight:bold }
.syntaxhl .change .change { color: #66f; }
.syntaxhl .head .head { color: #f4f; }
......@@ -22,7 +22,7 @@ Index: app/views/common/_diff.rhtml
+<% diff.each do |table_file| -%>
<div class="autoscroll">
<% if diff_type == 'sbs' -%>
<table class="filecontent CodeRay">
<table class="filecontent syntaxhl">
@@ -62,3 +63,5 @@
</div>
......
......@@ -499,7 +499,7 @@ EXPECTED
RAW
expected = <<-EXPECTED
<pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="no">1</span> <span class="c"># Some ruby code here</span></span>
<pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="line-numbers">1</span> <span class="comment"># Some ruby code here</span></span>
</code></pre>
EXPECTED
......
--- !ruby/object:Gem::Specification
name: coderay
version: !ruby/object:Gem::Version
hash: 53
prerelease: false
segments:
- 0
- 9
- 7
version: 0.9.7
platform: ruby
authors:
- murphy
autorequire:
bindir: bin
cert_chain: []
date: 2011-01-15 00:00:00 +01:00
default_executable:
dependencies: []
description: |
Fast and easy syntax highlighting for selected languages, written in Ruby.
Comes with RedCloth integration and LOC counter.
email: murphy@rubychan.de
executables:
- coderay
- coderay_stylesheet
extensions: []
extra_rdoc_files:
- lib/README
- FOLDERS
files:
- ./lib/coderay/duo.rb
- ./lib/coderay/encoder.rb
- ./lib/coderay/encoders/_map.rb
- ./lib/coderay/encoders/comment_filter.rb
- ./lib/coderay/encoders/count.rb
- ./lib/coderay/encoders/debug.rb
- ./lib/coderay/encoders/div.rb
- ./lib/coderay/encoders/filter.rb
- ./lib/coderay/encoders/html/css.rb
- ./lib/coderay/encoders/html/numerization.rb
- ./lib/coderay/encoders/html/output.rb
- ./lib/coderay/encoders/html.rb
- ./lib/coderay/encoders/json.rb
- ./lib/coderay/encoders/lines_of_code.rb
- ./lib/coderay/encoders/null.rb
- ./lib/coderay/encoders/page.rb
- ./lib/coderay/encoders/span.rb
- ./lib/coderay/encoders/statistic.rb
- ./lib/coderay/encoders/term.rb
- ./lib/coderay/encoders/text.rb
- ./lib/coderay/encoders/token_class_filter.rb
- ./lib/coderay/encoders/xml.rb
- ./lib/coderay/encoders/yaml.rb
- ./lib/coderay/for_redcloth.rb
- ./lib/coderay/helpers/file_type.rb
- ./lib/coderay/helpers/gzip_simple.rb
- ./lib/coderay/helpers/plugin.rb
- ./lib/coderay/helpers/word_list.rb
- ./lib/coderay/scanner.rb
- ./lib/coderay/scanners/_map.rb
- ./lib/coderay/scanners/c.rb
- ./lib/coderay/scanners/cpp.rb
- ./lib/coderay/scanners/css.rb
- ./lib/coderay/scanners/debug.rb
- ./lib/coderay/scanners/delphi.rb
- ./lib/coderay/scanners/diff.rb
- ./lib/coderay/scanners/groovy.rb
- ./lib/coderay/scanners/html.rb
- ./lib/coderay/scanners/java/builtin_types.rb
- ./lib/coderay/scanners/java.rb
- ./lib/coderay/scanners/java_script-0.9.6.rb
- ./lib/coderay/scanners/java_script.rb
- ./lib/coderay/scanners/json.rb
- ./lib/coderay/scanners/nitro_xhtml.rb
- ./lib/coderay/scanners/php.rb
- ./lib/coderay/scanners/plaintext.rb
- ./lib/coderay/scanners/python.rb
- ./lib/coderay/scanners/rhtml.rb
- ./lib/coderay/scanners/ruby/patterns.rb
- ./lib/coderay/scanners/ruby.rb
- ./lib/coderay/scanners/scheme.rb
- ./lib/coderay/scanners/sql.rb
- ./lib/coderay/scanners/xml.rb
- ./lib/coderay/scanners/yaml.rb
- ./lib/coderay/style.rb
- ./lib/coderay/styles/_map.rb
- ./lib/coderay/styles/cycnus.rb
- ./lib/coderay/styles/murphy.rb
- ./lib/coderay/token_classes.rb
- ./lib/coderay/tokens.rb
- ./lib/coderay.rb
- ./Rakefile
- ./test/functional/basic.rb
- ./test/functional/basic.rbc
- ./test/functional/for_redcloth.rb
- ./test/functional/for_redcloth.rbc
- ./test/functional/load_plugin_scanner.rb
- ./test/functional/load_plugin_scanner.rbc
- ./test/functional/suite.rb
- ./test/functional/suite.rbc
- ./test/functional/vhdl.rb
- ./test/functional/vhdl.rbc
- ./test/functional/word_list.rb
- ./test/functional/word_list.rbc
- ./lib/README
- ./LICENSE
- lib/README
- FOLDERS
- bin/coderay
- bin/coderay_stylesheet
has_rdoc: true
homepage: http://coderay.rubychan.de
licenses: []
post_install_message:
rdoc_options:
- -SNw2
- -mlib/README
- -t CodeRay Documentation
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
hash: 51
segments:
- 1
- 8
- 2
version: 1.8.2
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
hash: 3
segments:
- 0
version: "0"
requirements: []
rubyforge_project: coderay
rubygems_version: 1.3.7
signing_key:
specification_version: 3
summary: Fast syntax highlighting for selected languages.
test_files:
- ./test/functional/suite.rb
= CodeRay - Trunk folder structure
== bench - Benchmarking system
All benchmarking stuff goes here.
Test inputs are stored in files named <code>example.<lang></code>.
Test outputs go to <code>bench/test.<encoder-default-file-extension></code>.
Run <code>bench/bench.rb</code> to get a usage description.
Run <code>rake bench</code> to perform an example benchmark.
== bin - Scripts
Executional files for CodeRay.
== demo - Demos and functional tests
Demonstrational scripts to show of CodeRay's features.
Run them as functional tests with <code>rake test:demos</code>.
== etc - Lots of stuff
Some addidtional files for CodeRay, mainly graphics and Vim scripts.
== gem_server - Gem output folder
For <code>rake gem</code>.
== lib - CodeRay library code
This is the base directory for the CodeRay library.
== rake_helpers - Rake helper libraries
Some files to enhance Rake, including the Autumnal Rdoc template and some scripts.
== test - Tests
Tests for the scanners.
Each language has its own subfolder and sub-suite.
Run with <code>rake test</code>.
#!/usr/bin/env ruby
# CodeRay Executable
#
# Version: 0.2
# Author: murphy
require 'coderay'
if ARGV.empty?
$stderr.puts <<-USAGE
CodeRay #{CodeRay::VERSION} (http://coderay.rubychan.de)
Usage:
coderay file [-<format>]
coderay -<lang> [-<format>] [< file] [> output]
Defaults:
lang: based on file extension
format: ANSI colorized output for terminal, HTML page for files
Examples:
coderay foo.rb # colorized output to terminal, based on file extension
coderay foo.rb -loc # print LOC count, based on file extension and format
coderay foo.rb > foo.html # HTML page output to file, based on extension
coderay -ruby < foo.rb # colorized output to terminal, based on lang
coderay -ruby -loc < foo.rb # print LOC count, based on lang
coderay -ruby -page foo.rb # HTML page output to terminal, based on lang and format
coderay -ruby -page foo.rb > foo.html # HTML page output to file, based on lang and format
USAGE
end
first, second = ARGV
def read
file = ARGV.grep(/^(?!-)/).last
if file
if File.exist?(file)
File.read file
else
$stderr.puts "No such file: #{file}"
end
else
$stdin.read
end
end
if first
if first[/-(\w+)/] == first
lang = $1
input = read
tokens = :scan
else
file = first
unless File.exist? file
$stderr.puts "No such file: #{file}"
exit 2
end
tokens = CodeRay.scan_file file
end
else
$stderr.puts 'No lang/file given.'
exit 1
end
if second
if second[/-(\w+)/] == second
format = $1.to_sym
else
raise 'invalid format (must be -xxx)'
end
else
if $stdout.tty?
format = :term
else
$stderr.puts 'No format given; setting to default (HTML Page).'
format = :page
end
end
if tokens == :scan
output = CodeRay::Duo[lang => format].highlight input
else
output = tokens.encode format
end
out = $stdout
out.puts output
#!/usr/bin/env ruby
require 'coderay'
puts CodeRay::Encoders[:html]::CSS.new.stylesheet
This diff is collapsed.
module CodeRay
module Encoders
map \
:loc => :lines_of_code,
:plain => :text,
:stats => :statistic,
:terminal => :term,
:tex => :latex
end
end
($:.unshift '../..'; require 'coderay') unless defined? CodeRay
module CodeRay
module Encoders
load :token_class_filter
class CommentFilter < TokenClassFilter
register_for :comment_filter
DEFAULT_OPTIONS = superclass::DEFAULT_OPTIONS.merge \
:exclude => [:comment]
end
end
end
if $0 == __FILE__
$VERBOSE = true
$: << File.join(File.dirname(__FILE__), '..')
eval DATA.read, nil, $0, __LINE__ + 4
end
__END__
require 'test/unit'
class CommentFilterTest < Test::Unit::TestCase
def test_filtering_comments
tokens = CodeRay.scan <<-RUBY, :ruby
#!/usr/bin/env ruby
# a minimal Ruby program
puts "Hello world!"
RUBY
assert_equal <<-RUBY_FILTERED, tokens.comment_filter.text
#!/usr/bin/env ruby
puts "Hello world!"
RUBY_FILTERED
end
end
\ No newline at end of file
module CodeRay
module Encoders
class Count < Encoder