Commit b80b789c authored by Jean-Philippe Lang's avatar Jean-Philippe Lang Committed by Eric Davis

Coderay upgraded to 0.9.7 (#5344).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4739 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent e5c8513d
......@@ -51,6 +51,7 @@ Rails::Initializer.run do |config|
config.action_mailer.perform_deliveries = false
config.gem 'rubytree', :lib => 'tree'
config.gem 'coderay', :version => '~>0.9.7'
# Load any local configuration that is kept out of source control
# (e.g. gems, patches).
......
--- !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>.
require 'rake/rdoctask'
ROOT = '.'
LIB_ROOT = File.join ROOT, 'lib'
EXTRA_RDOC_FILES = %w(lib/README FOLDERS)
task :default => :test
if File.directory? 'rake_tasks'
# load rake tasks from subfolder
for task_file in Dir['rake_tasks/*.rake'].sort
load task_file
end
else
# fallback tasks when rake_tasks folder is not present
desc 'Run CodeRay tests (basic)'
task :test do
ruby './test/functional/suite.rb'
ruby './test/functional/for_redcloth.rb'
end
desc 'Generate documentation for CodeRay'
Rake::RDocTask.new :doc do |rd|
rd.title = 'CodeRay Documentation'
rd.main = 'lib/README'
rd.rdoc_files.add Dir['lib']
rd.rdoc_files.add 'lib/README'
rd.rdoc_files.add 'FOLDERS'
rd.rdoc_dir = 'doc'
end
end
\ No newline at end of file
#!/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
......@@ -18,7 +18,7 @@ And with line numbers.
* is what everybody should have on their website
* solves all your problems and makes the girls run after you
Version: 0.9.2
Version: 0.9.7
Author:: murphy (Kornelius Kalnbach)
Contact:: murphy rubychan de
Website:: coderay.rubychan.de[http://coderay.rubychan.de]
......@@ -94,6 +94,7 @@ Please report errors in this documentation to <murphy rubychan de>.
* Rob Aldred for the terminal encoder
* Trans for pointing out $DEBUG dependencies
* Flameeyes for finding that Term::ANSIColor was obsolete
* Etienne Massip for reporting a serious bug in JavaScript scanner
* matz and all Ruby gods and gurus
* The inventors of: the computer, the internet, the true color display, HTML &
CSS, VIM, Ruby, pizza, microwaves, guitars, scouting, programming, anime,
......
......@@ -134,7 +134,7 @@ module CodeRay
# Minor: feature milestone
# Teeny: development state, 0 for pre-release
# Revision: Subversion Revision number (generated on rake gem:make)
VERSION = '0.9.2'
VERSION = '0.9.7'
require 'coderay/tokens'
require 'coderay/token_classes'
......
......@@ -276,9 +276,13 @@ module Encoders
when :begin_line
@opened[0] = type
if style = @css_style[@opened]
@out << style.sub('<span', '<div')
if style['class="']
@out << style.sub('class="', 'class="line ')
else
@out << style.sub('>', ' class="line">')
end
else
@out << '<div>'
@out << '<span class="line">'
end
@opened << type
when :end_line
......@@ -289,7 +293,7 @@ module Encoders
raise 'Malformed token stream: Trying to close a line (%p) \
that is not open. Open are: %p.' % [type, @opened[1..-1]]
end
@out << '</div>'
@out << '</span>'
@opened.pop
end
......
......@@ -80,8 +80,8 @@ module Encoders
line_numbers.gsub!(/\n/) { "<tt>\n</tt>" }
line_numbers_table_tpl = TABLE.apply('LINE_NUMBERS', line_numbers)
gsub!(/<\/div>\n/) { '</div>' }
gsub!(/\n/) { "<tt>\n</tt>" }
gsub!("</div>\n", '</div>')
gsub!("\n", "<tt>\n</tt>")
wrap_in! line_numbers_table_tpl
@wrapped_in = :div
......
......@@ -68,15 +68,16 @@ module CodeRay
def normify code
code = code.to_s
if code.respond_to? :force_encoding
debug, $DEBUG = $DEBUG, false
begin
code.force_encoding 'utf-8'
code[/\z/] # raises an ArgumentError when code contains a non-UTF-8 char
rescue ArgumentError
code.force_encoding 'binary'
ensure
$DEBUG = debug
if code.respond_to?(:encoding) && (code.encoding.name != 'UTF-8' || !code.valid_encoding?)
code = code.dup
original_encoding = code.encoding
code.force_encoding 'Windows-1252'
unless code.valid_encoding?
code.force_encoding original_encoding
if code.encoding.name == 'UTF-8'
code.encode! 'UTF-16BE', :invalid => :replace, :undef => :replace, :replace => '?'
end
code.encode! 'UTF-8', :invalid => :replace, :undef => :replace, :replace => '?'
end
end
code.to_unix
......@@ -147,7 +148,12 @@ module CodeRay
def string= code
code = Scanner.normify(code)
super code
if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION['rubinius 1.0.1']
reset_state
@string = code
else
super code
end
reset_instance
end
......
......@@ -14,12 +14,11 @@ module Scanners
]
module RE
NonASCII = /[\x80-\xFF]/
Hex = /[0-9a-fA-F]/
Unicode = /\\#{Hex}{1,6}(?:\r\n|\s)?/ # differs from standard because it allows uppercase hex too
Escape = /#{Unicode}|\\[^\r\n\f0-9a-fA-F]/
NMChar = /[-_a-zA-Z0-9]|#{NonASCII}|#{Escape}/
NMStart = /[_a-zA-Z]|#{NonASCII}|#{Escape}/
NMChar = /[-_a-zA-Z0-9]|#{Escape}/
NMStart = /[_a-zA-Z]|#{Escape}/
NL = /\r\n|\r|\n|\f/
String1 = /"(?:[^\n\r\f\\"]|\\#{NL}|#{Escape})*"?/ # FIXME: buggy regexp
String2 = /'(?:[^\n\r\f\\']|\\#{NL}|#{Escape})*'?/ # FIXME: buggy regexp
......
......@@ -47,11 +47,16 @@ module Scanners
tokens << [match, :change]
next unless match = scan(/.+/)
kind = :plain
elsif scan(/(@@)((?>[^@\n]*))(@@)/)
tokens << [:begin_line, line_kind = :change]
tokens << [self[1], :change]
tokens << [self[2], :plain]
tokens << [self[3], :change]
elsif match = scan(/@@(?>[^@\n]*)@@/)
if check(/\n|$/)
tokens << [:begin_line, line_kind = :change]
else
tokens << [:open, :change]
end
tokens << [match[0,2], :change]
tokens << [match[2...-2], :plain]
tokens << [match[-2,2], :change]
tokens << [:close, :change] unless line_kind
next unless match = scan(/.+/)
kind = :plain
elsif match = scan(/\+/)
......@@ -67,7 +72,7 @@ module Scanners
elsif scan(/ .*/)
kind = :comment
elsif scan(/.+/)
tokens << [:begin_line, line_kind = :head]
tokens << [:begin_line, line_kind = :comment]
kind = :plain
else
raise_inspect 'else case rached'
......
......@@ -91,7 +91,7 @@ module Scanners
end
when :attribute
if scan(/#{TAG_END}/)
if scan(/#{TAG_END}/o)
kind = :tag
state = :initial
elsif scan(/#{ATTR_NAME}/o)
......
......@@ -138,7 +138,7 @@ module Scanners
elsif scan(/\\./m)
kind = :content
elsif scan(/ \\ | $ /x)
tokens << [:close, :delimiter]
tokens << [:close, state]
kind = :error
state = :initial
else
......
......@@ -215,7 +215,7 @@ module Scanners
end
def xml_scanner
@xml_scanner ||= CodeRay.scanner :xml, :tokens => @tokens, :keep_tokens => true, :keep_state => true
@xml_scanner ||= CodeRay.scanner :xml, :tokens => @tokens, :keep_tokens => true, :keep_state => false
end
end
......
module CodeRay
module Scanners
class JavaScript < Scanner
include Streamable
register_for :java_script
file_extension 'js'
# The actual JavaScript keywords.
KEYWORDS = %w[
break case catch continue default delete do else
finally for function if in instanceof new
return switch throw try typeof var void while with
]
PREDEFINED_CONSTANTS = %w[
false null true undefined
]
MAGIC_VARIABLES = %w[ this arguments ] # arguments was introduced in JavaScript 1.4
KEYWORDS_EXPECTING_VALUE = WordList.new.add %w[
case delete in instanceof new return throw typeof with
]
# Reserved for future use.
RESERVED_WORDS = %w[
abstract boolean byte char class debugger double enum export extends
final float goto implements import int interface long native package
private protected public short static super synchronized throws transient
volatile
]
IDENT_KIND = WordList.new(:ident).
add(RESERVED_WORDS, :reserved).
add(PREDEFINED_CONSTANTS, :pre_constant).
add(MAGIC_VARIABLES, :local_variable).
add(KEYWORDS, :keyword)
ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
REGEXP_ESCAPE = / [bBdDsSwW] /x
STRING_CONTENT_PATTERN = {
"'" => /[^\\']+/,
'"' => /[^\\"]+/,
'/' => /[^\\\/]+/,
}
KEY_CHECK_PATTERN = {
"'" => / (?> [^\\']* (?: \\. [^\\']* )* ) ' \s* : /mx,
'"' => / (?> [^\\"]* (?: \\. [^\\"]* )* ) " \s* : /mx,
}
def scan_tokens tokens, options
state = :initial
string_delimiter = nil
value_expected = true
key_expected = false
function_expected = false
until eos?
kind = nil
match = nil
case state
when :initial
if match = scan(/ \s+ | \\\n /x)
value_expected = true if !value_expected && match.index(?\n)
tokens << [match, :space]
next
elsif scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
value_expected = true
kind = :comment
elsif check(/\.?\d/)
key_expected = value_expected = false
if scan(/0[xX][0-9A-Fa-f]+/)
kind = :hex
elsif scan(/(?>0[0-7]+)(?![89.eEfF])/)
kind = :oct
elsif scan(/\d+[fF]|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
kind = :float
elsif scan(/\d+/)
kind = :integer
end
elsif value_expected && match = scan(/<([[:alpha:]]\w*) (?: [^\/>]*\/> | .*?<\/\1>)/xim)
# FIXME: scan over nested tags
xml_scanner.tokenize match
value_expected = false
next
elsif match = scan(/ [-+*=<>?:;,!&^|(\[{~%]+ | \.(?!\d) /x)
value_expected = true
last_operator = match[-1]
key_expected = (last_operator == ?{) || (last_operator == ?,)
function_expected = false
kind = :operator
elsif scan(/ [)\]}]+ /x)