Skip to content

Commit 4ffc0af

Browse files
committed
Merge branch 'master' into bash-scanner
2 parents 02e1bf3 + 2de5dab commit 4ffc0af

27 files changed

+292
-96
lines changed

.gitignore

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
.DS_Store
2-
*.gem
3-
*.rbc
4-
.bundle
5-
.config
2+
.*~
63
coverage
7-
InstalledFiles
8-
lib/bundler/man
94
pkg
10-
rdoc
115
spec/reports
12-
test/tmp
13-
test/version_tmp
14-
tmp
156
doc
167
Gemfile.lock
178
.rvmrc
9+
.ruby-gemset
10+
.ruby-version
1811
test/executable/source.rb.html
1912
test/executable/source.rb.json
2013
test/scanners
2114
bench/test.div.html
22-
diff.html
23-
etc/CodeRay.tmproj
24-
*.swp
2515
old-stuff

.travis.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
rvm:
22
- 1.8.7
3-
- 1.9.2
3+
- ree
44
- 1.9.3
5+
- 2.0.0
6+
- ruby-head
57
- jruby-18mode
68
- jruby-19mode
9+
- jruby-head
710
- rbx-18mode
811
- rbx-19mode
9-
- ruby-head # test again later: RedCloth not compiling
10-
- jruby-head
11-
- ree
1212
branches:
1313
only:
1414
- master
15+
matrix:
16+
allow_failures:
17+
- rvm: rbx-18mode
18+
- rvm: rbx-19mode
1519
script: "rake test" # test:scanners"

Changes.textile

+5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ p=. _This files lists all changes in the CodeRay library since the 0.9.8 release
44

55
h2. Changes in 1.1
66

7+
* New scanner: Sass [#93]
78
* Diff scanner: Highlight inline changes in multi-line changes [#99]
89
* Remove double-click toggle handler from HTML table output
10+
* Fixes to CSS scanner (floats, pseudoclasses)
11+
* Plugin does not warn about fallback when default is defined
912
* Display line numbers in HTML @:table@ mode even for single-line code (remove special case) [#41, thanks to Ariejan de Vroom]
13+
* Add .xaml file type [#121, thanks to Kozman Bálint]
14+
* @CodeRay::TokenKinds@ should not be frozen [#130, thanks to Gavin Kistner]
1015

1116
h2. Changes in 1.0.9
1217

Gemfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source "http://rubygems.org"
1+
source 'https://rubygems.org'
22

33
# Specify your gem's dependencies in coderay.gemspec
44
gemspec
@@ -7,10 +7,10 @@ gemspec
77
# Include everything needed to run rake, tests, features, etc.
88
group :development do
99
gem "bundler", ">= 1.0.0"
10-
gem "rake", "~> 0.9.2"
10+
gem "rake"
1111
gem "RedCloth", RUBY_PLATFORM == 'java' ? ">= 4.2.7" : ">= 4.0.3"
12-
gem "term-ansicolor"
13-
gem "shoulda-context", "~> 1.0.0" if RUBY_VERSION >= '1.8.7'
14-
gem "json" unless RUBY_VERSION >= '1.9.1'
15-
gem "rdoc" if RUBY_VERSION >= '1.8.7'
12+
gem "term-ansicolor", '~> 1.2.2'
13+
gem "shoulda-context", "~> 1.1.2"
14+
gem "json" if RUBY_VERSION < '1.9'
15+
gem "rdoc"
1616
end

README.markdown

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# CodeRay [![Build Status](https://travis-ci.org/rubychan/coderay.png)](https://travis-ci.org/rubychan/coderay)
1+
# CodeRay
2+
3+
[![Build Status](https://travis-ci.org/rubychan/coderay.png)](https://travis-ci.org/rubychan/coderay)
4+
[![Gem Version](https://badge.fury.io/rb/coderay.png)](http://badge.fury.io/rb/coderay)
5+
[![Dependency Status](https://gemnasium.com/rubychan/coderay.png)](https://gemnasium.com/rubychan/coderay)
26

37
## About
48

@@ -12,7 +16,7 @@ You put your code in, and you get it back colored; Keywords, strings, floats, co
1216

1317
### Dependencies
1418

15-
CodeRay needs Ruby 1.8.7+ or 1.9.2+. It also runs on Rubinius and JRuby.
19+
CodeRay needs Ruby 1.8.7, 1.9.3 or 2.0. It also runs on JRuby.
1620

1721
## Example Usage
1822

lib/coderay/encoders/debug.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ def initialize options = {}
2424
end
2525

2626
def text_token text, kind
27+
raise 'empty token' if $CODERAY_DEBUG && text.empty?
2728
if kind == :space
2829
@out << text
2930
else
3031
# TODO: Escape (
31-
text = text.gsub(/[)\\]/, '\\\\\0') # escape ) and \
32+
text = text.gsub(/[)\\]/, '\\\\\0') if text.index(/[)\\]/)
3233
@out << kind.to_s << '(' << text << ')'
3334
end
3435
end

lib/coderay/encoders/html.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ def begin_group kind
286286

287287
def end_group kind
288288
if $CODERAY_DEBUG && (@opened.empty? || @opened.last != kind)
289-
warn 'Malformed token stream: Trying to close a token (%p) ' \
290-
'that is not open. Open are: %p.' % [kind, @opened[1..-1]]
289+
warn 'Malformed token stream: Trying to close a token group (%p) that is not open. Open are: %p.' % [kind, @opened[1..-1]]
291290
end
292291
if @opened.pop
293292
@out << '</span>'
@@ -312,8 +311,7 @@ def begin_line kind
312311

313312
def end_line kind
314313
if $CODERAY_DEBUG && (@opened.empty? || @opened.last != kind)
315-
warn 'Malformed token stream: Trying to close a line (%p) ' \
316-
'that is not open. Open are: %p.' % [kind, @opened[1..-1]]
314+
warn 'Malformed token stream: Trying to close a line (%p) that is not open. Open are: %p.' % [kind, @opened[1..-1]]
317315
end
318316
if @opened.pop
319317
@out << '</span>'

lib/coderay/helpers/file_type.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def shebang filename
9999
'mab' => :ruby,
100100
'pas' => :delphi,
101101
'patch' => :diff,
102+
'phtml' => :php,
102103
'php' => :php,
103104
'php3' => :php,
104105
'php4' => :php,
@@ -116,10 +117,10 @@ def shebang filename
116117
'rpdf' => :ruby,
117118
'ru' => :ruby,
118119
'rxml' => :ruby,
119-
# 'sch' => :scheme,
120+
'sass' => :sass,
120121
'sql' => :sql,
121-
# 'ss' => :scheme,
122122
'tmproj' => :xml,
123+
'xaml' => :xml,
123124
'xhtml' => :html,
124125
'xml' => :xml,
125126
'yaml' => :yaml,

lib/coderay/helpers/plugin.rb

-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ def make_plugin_hash
180180
rescue LoadError => boom
181181
if @plugin_map_loaded
182182
if h.has_key?(:default)
183-
warn '%p could not load plugin %p; falling back to %p' % [self, id, h[:default]]
184183
h[:default]
185184
else
186185
raise PluginNotFound, '%p could not load plugin %p: %s' % [self, id, boom]

lib/coderay/scanners/c.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def scan_tokens encoder, options
148148
encoder.text_token match, :char
149149
elsif match = scan(/ \\ | $ /x)
150150
encoder.end_group :string
151-
encoder.text_token match, :error
151+
encoder.text_token match, :error unless match.empty?
152152
state = :initial
153153
label_expected = false
154154
else

lib/coderay/scanners/cpp.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def scan_tokens encoder, options
160160
encoder.text_token match, :char
161161
elsif match = scan(/ \\ | $ /x)
162162
encoder.end_group :string
163-
encoder.text_token match, :error
163+
encoder.text_token match, :error unless match.empty?
164164
state = :initial
165165
label_expected = false
166166
else

lib/coderay/scanners/css.rb

+14-17
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,41 @@ class CSS < Scanner
1515

1616
module RE # :nodoc:
1717
Hex = /[0-9a-fA-F]/
18-
Unicode = /\\#{Hex}{1,6}(?:\r\n|\s)?/ # differs from standard because it allows uppercase hex too
19-
Escape = /#{Unicode}|\\[^\r\n\f0-9a-fA-F]/
20-
NMChar = /[-_a-zA-Z0-9]|#{Escape}/
21-
NMStart = /[_a-zA-Z]|#{Escape}/
22-
NL = /\r\n|\r|\n|\f/
23-
String1 = /"(?:[^\n\r\f\\"]|\\#{NL}|#{Escape})*"?/ # TODO: buggy regexp
24-
String2 = /'(?:[^\n\r\f\\']|\\#{NL}|#{Escape})*'?/ # TODO: buggy regexp
18+
Unicode = /\\#{Hex}{1,6}\b/ # differs from standard because it allows uppercase hex too
19+
Escape = /#{Unicode}|\\[^\n0-9a-fA-F]/
20+
NMChar = /[-_a-zA-Z0-9]/
21+
NMStart = /[_a-zA-Z]/
22+
String1 = /"(?:[^\n\\"]+|\\\n|#{Escape})*"?/ # TODO: buggy regexp
23+
String2 = /'(?:[^\n\\']+|\\\n|#{Escape})*'?/ # TODO: buggy regexp
2524
String = /#{String1}|#{String2}/
2625

2726
HexColor = /#(?:#{Hex}{6}|#{Hex}{3})/
28-
Color = /#{HexColor}/
2927

30-
Num = /-?(?:[0-9]+|[0-9]*\.[0-9]+)/
28+
Num = /-?(?:[0-9]*\.[0-9]+|[0-9]+)/
3129
Name = /#{NMChar}+/
3230
Ident = /-?#{NMStart}#{NMChar}*/
3331
AtKeyword = /@#{Ident}/
3432
Percentage = /#{Num}%/
3533

3634
reldimensions = %w[em ex px]
3735
absdimensions = %w[in cm mm pt pc]
38-
Unit = Regexp.union(*(reldimensions + absdimensions + %w[s]))
36+
Unit = Regexp.union(*(reldimensions + absdimensions + %w[s dpi dppx deg]))
3937

4038
Dimension = /#{Num}#{Unit}/
4139

42-
Comment = %r! /\* (?: .*? \*/ | .* ) !mx
43-
Function = /(?:url|alpha|attr|counters?)\((?:[^)\n\r\f]|\\\))*\)?/
40+
Function = /(?:url|alpha|attr|counters?)\((?:[^)\n]|\\\))*\)?/
4441

45-
Id = /##{Name}/
42+
Id = /(?!#{HexColor}\b(?!-))##{Name}/
4643
Class = /\.#{Name}/
47-
PseudoClass = /:#{Name}/
44+
PseudoClass = /::?#{Ident}/
4845
AttributeSelector = /\[[^\]]*\]?/
4946
end
5047

5148
protected
5249

5350
def setup
5451
@state = :initial
55-
@value_expected = nil
52+
@value_expected = false
5653
end
5754

5855
def scan_tokens encoder, options
@@ -158,7 +155,7 @@ def scan_tokens encoder, options
158155
elsif match = scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox)
159156
encoder.text_token match, :float
160157

161-
elsif match = scan(/#{RE::Color}/o)
158+
elsif match = scan(/#{RE::HexColor}/o)
162159
encoder.text_token match, :color
163160

164161
elsif match = scan(/! *important/)
@@ -170,7 +167,7 @@ def scan_tokens encoder, options
170167
elsif match = scan(RE::AtKeyword)
171168
encoder.text_token match, :directive
172169

173-
elsif match = scan(/ [+>:;,.=()\/] /x)
170+
elsif match = scan(/ [+>~:;,.=()\/] /x)
174171
if match == ':'
175172
value_expected = true
176173
elsif match == ';'

lib/coderay/scanners/diff.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def scan_tokens encoder, options
4545
if match = scan(/--- |\+\+\+ |=+|_+/)
4646
encoder.begin_line line_kind = :head
4747
encoder.text_token match, :head
48-
if match = scan(/.*?(?=$|[\t\n\x00]| \(revision)/)
48+
if match = scan(/[^\x00\n]+?(?=$|[\t\n]| \(revision)/)
4949
encoder.text_token match, :filename
5050
if options[:highlight_code] && match != '/dev/null'
5151
file_type = CodeRay::FileType.fetch(match, :text)

lib/coderay/scanners/java.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def scan_tokens encoder, options
147147
elsif match = scan(/ \\ | $ /x)
148148
encoder.end_group state
149149
state = :initial
150-
encoder.text_token match, :error
150+
encoder.text_token match, :error unless match.empty?
151151
else
152152
raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
153153
end

lib/coderay/scanners/java_script.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ def scan_tokens encoder, options
175175
encoder.text_token match, :content
176176
elsif match = scan(/ \\ | $ /x)
177177
encoder.end_group state
178-
encoder.text_token match, :error
178+
encoder.text_token match, :error unless match.empty?
179179
key_expected = value_expected = false
180180
state = :initial
181181
else
182-
raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
182+
raise_inspect "else case #{string_delimiter} reached; %p not handled." % peek(1), encoder
183183
end
184184

185185
else

lib/coderay/scanners/json.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def scan_tokens encoder, options
7070
encoder.text_token match, :content
7171
elsif match = scan(/ \\ | $ /x)
7272
encoder.end_group state
73-
encoder.text_token match, :error
73+
encoder.text_token match, :error unless match.empty?
7474
state = :initial
7575
else
7676
raise_inspect "else case \" reached; %p not handled." % peek(1), encoder

lib/coderay/scanners/python.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def scan_tokens encoder, options
133133
elsif match = scan(/ \\ | $ /x)
134134
encoder.end_group string_type
135135
string_type = nil
136-
encoder.text_token match, :error
136+
encoder.text_token match, :error unless match.empty?
137137
state = :initial
138138
else
139139
raise_inspect "else case \" reached; %p not handled." % peek(1), encoder, state

0 commit comments

Comments
 (0)