coderay 1.0.0.835rc1 → 1.0.0.846rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/coderay CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'coderay'
3
3
 
4
4
  $options, args = ARGV.partition { |arg| arg[/^-[hv]$|--\w+/] }
5
- subcommand = args.detect { |arg| arg[/^\w/] }
5
+ subcommand = args.first if /^\w/ === args.first
6
6
  subcommand = nil if subcommand && File.exist?(subcommand)
7
7
  args.delete subcommand
8
8
 
@@ -105,7 +105,7 @@ when 'highlight', nil
105
105
  if output_file
106
106
  output_filetype ||= CodeRay::FileType[output_file]
107
107
  else
108
- output_filetype ||= :term
108
+ output_filetype ||= :terminal
109
109
  end
110
110
 
111
111
  output_filetype = :page if output_filetype.to_s == 'html'
@@ -88,6 +88,7 @@ module CodeRay
88
88
  'groovy' => :groovy,
89
89
  'gvy' => :groovy,
90
90
  'h' => :c,
91
+ 'haml' => :haml,
91
92
  'htm' => :page,
92
93
  'html' => :page,
93
94
  'html.erb' => :erb,
@@ -69,11 +69,8 @@ module Scanners
69
69
  next unless match = scan(/.+/)
70
70
  encoder.text_token match, :plain
71
71
  state = :added
72
- elsif match = scan(/\\ /)
73
- encoder.begin_line line_kind = :change
74
- encoder.text_token match, :change
75
- next unless match = scan(/.+/)
76
- encoder.text_token match, :plain
72
+ elsif match = scan(/\\ .*/)
73
+ encoder.text_token match, :comment
77
74
  elsif match = scan(/@@(?>[^@\n]*)@@/)
78
75
  content_scanner.state = :initial unless match?(/\n\+/)
79
76
  content_scanner_entry_state = nil
@@ -13,15 +13,15 @@ module Scanners
13
13
  KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
14
14
 
15
15
  ERB_RUBY_BLOCK = /
16
- <%(?!%)[=-]?
17
- (?>
16
+ (<%(?!%)[-=\#]?)
17
+ ((?>
18
18
  [^\-%]* # normal*
19
19
  (?> # special
20
20
  (?: %(?!>) | -(?!%>) )
21
21
  [^\-%]* # normal*
22
22
  )*
23
- )
24
- (?: -?%> )?
23
+ ))
24
+ ((?: -?%> )?)
25
25
  /x # :nodoc:
26
26
 
27
27
  START_OF_ERB = /
@@ -48,21 +48,25 @@ module Scanners
48
48
  @html_scanner.tokenize match, :tokens => encoder
49
49
 
50
50
  elsif match = scan(/#{ERB_RUBY_BLOCK}/o)
51
- start_tag = match[/\A<%[-=#]?/]
52
- end_tag = match[/-?%?>?\z/]
51
+ start_tag = self[1]
52
+ code = self[2]
53
+ end_tag = self[3]
54
+
53
55
  encoder.begin_group :inline
54
56
  encoder.text_token start_tag, :inline_delimiter
55
- code = match[start_tag.size .. -1 - end_tag.size]
56
- if start_tag[/\A<%#/]
57
+
58
+ if start_tag == '<%#'
57
59
  encoder.text_token code, :comment
58
60
  else
59
61
  @ruby_scanner.tokenize code, :tokens => encoder
60
62
  end unless code.empty?
63
+
61
64
  encoder.text_token end_tag, :inline_delimiter unless end_tag.empty?
62
65
  encoder.end_group :inline
63
66
 
64
67
  else
65
68
  raise_inspect 'else-case reached!', encoder
69
+
66
70
  end
67
71
 
68
72
  end
@@ -0,0 +1,168 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ load :ruby
5
+ load :html
6
+ load :java_script
7
+
8
+ class HAML < Scanner
9
+
10
+ register_for :haml
11
+ title 'HAML Template'
12
+
13
+ KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
14
+
15
+ protected
16
+
17
+ def setup
18
+ super
19
+ @ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
20
+ @embedded_ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true, :state => @ruby_scanner.interpreted_string_state
21
+ @html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true
22
+ end
23
+
24
+ def scan_tokens encoder, options
25
+
26
+ match = nil
27
+ code = ''
28
+
29
+ until eos?
30
+
31
+ if bol?
32
+ if match = scan(/!!!.*/)
33
+ encoder.text_token match, :doctype
34
+ next
35
+ end
36
+
37
+ if match = scan(/(?>( *)(\/(?!\[if)|-\#|:javascript|:ruby|:\w+) *)(?=\n)/)
38
+ encoder.text_token match, :comment
39
+
40
+ code = self[2]
41
+ if match = scan(/(?:\n+#{self[1]} .*)+/)
42
+ case code
43
+ when '/', '-#'
44
+ encoder.text_token match, :comment
45
+ when ':javascript'
46
+ # TODO: recognize #{...} snippets inside JavaScript
47
+ @java_script_scanner ||= CodeRay.scanner :java_script, :tokens => @tokens, :keep_tokens => true
48
+ @java_script_scanner.tokenize match, :tokens => encoder
49
+ when ':ruby'
50
+ @ruby_scanner.tokenize match, :tokens => encoder
51
+ when /:\w+/
52
+ encoder.text_token match, :comment
53
+ else
54
+ raise 'else-case reached: %p' % [code]
55
+ end
56
+ end
57
+ end
58
+
59
+ if match = scan(/ +/)
60
+ encoder.text_token match, :space
61
+ end
62
+
63
+ if match = scan(/\/.*/)
64
+ encoder.text_token match, :comment
65
+ next
66
+ end
67
+
68
+ if match = scan(/\\/)
69
+ encoder.text_token match, :plain
70
+ if match = scan(/.+/)
71
+ @html_scanner.tokenize match, :tokens => encoder
72
+ end
73
+ next
74
+ end
75
+
76
+ tag = false
77
+
78
+ if match = scan(/%[\w:]+\/?/)
79
+ encoder.text_token match, :tag
80
+ # if match = scan(/( +)(.+)/)
81
+ # encoder.text_token self[1], :space
82
+ # @embedded_ruby_scanner.tokenize self[2], :tokens => encoder
83
+ # end
84
+ tag = true
85
+ end
86
+
87
+ while match = scan(/([.#])[-\w]*\w/)
88
+ encoder.text_token match, self[1] == '#' ? :constant : :class
89
+ tag = true
90
+ end
91
+
92
+ if tag && match = scan(/(\()([^)]+)?(\))?/)
93
+ # TODO: recognize title=@title, class="widget_#{@widget.number}"
94
+ encoder.text_token self[1], :plain
95
+ @html_scanner.tokenize self[2], :tokens => encoder, :state => :attribute if self[2]
96
+ encoder.text_token self[3], :plain if self[3]
97
+ end
98
+
99
+ if tag && match = scan(/\{/)
100
+ encoder.text_token match, :plain
101
+
102
+ code = ''
103
+ level = 1
104
+ while true
105
+ code << scan(/([^\{\},\n]|, *\n?)*/)
106
+ case match = getch
107
+ when '{'
108
+ level += 1
109
+ code << match
110
+ when '}'
111
+ level -= 1
112
+ if level > 0
113
+ code << match
114
+ else
115
+ break
116
+ end
117
+ when "\n", ",", nil
118
+ break
119
+ end
120
+ end
121
+ @ruby_scanner.tokenize code, :tokens => encoder unless code.empty?
122
+
123
+ encoder.text_token match, :plain if match
124
+ end
125
+
126
+ if tag && match = scan(/(\[)([^\]\n]+)?(\])?/)
127
+ encoder.text_token self[1], :plain
128
+ @ruby_scanner.tokenize self[2], :tokens => encoder if self[2]
129
+ encoder.text_token self[3], :plain if self[3]
130
+ end
131
+
132
+ if tag && match = scan(/\//)
133
+ encoder.text_token match, :tag
134
+ end
135
+
136
+ if scan(/(>?<?[-=]|[&!]=|(& |!)|~)( *)([^,\n\|]+(?:(, *|\|(?=.|\n.*\|$))\n?[^,\n\|]*)*)?/)
137
+ encoder.text_token self[1] + self[3], :plain
138
+ if self[4]
139
+ if self[2]
140
+ @embedded_ruby_scanner.tokenize self[4], :tokens => encoder
141
+ else
142
+ @ruby_scanner.tokenize self[4], :tokens => encoder
143
+ end
144
+ end
145
+ elsif match = scan(/((?:<|><?)(?![!?\/\w]))?(.+)?/)
146
+ encoder.text_token self[1], :plain if self[1]
147
+ # TODO: recognize #{...} snippets
148
+ @html_scanner.tokenize self[2], :tokens => encoder if self[2]
149
+ end
150
+
151
+ elsif match = scan(/.+/)
152
+ @html_scanner.tokenize match, :tokens => encoder
153
+
154
+ end
155
+
156
+ if match = scan(/\n/)
157
+ encoder.text_token match, :space
158
+ end
159
+ end
160
+
161
+ encoder
162
+
163
+ end
164
+
165
+ end
166
+
167
+ end
168
+ end
@@ -81,7 +81,7 @@ module Scanners
81
81
  end
82
82
 
83
83
  def scan_tokens encoder, options
84
- state = @state
84
+ state = options[:state] || @state
85
85
  plain_string_content = @plain_string_content
86
86
  in_tag = in_attribute = nil
87
87
 
@@ -103,7 +103,7 @@ module Scanners
103
103
  encoder.text_token match, :doctype
104
104
  elsif match = scan(/<\?xml(?:.*?\?>|.*)/m)
105
105
  encoder.text_token match, :preprocessor
106
- elsif match = scan(/<\?(?:.*?\?>|.*)|<%(?:.*?%>|.*)/m)
106
+ elsif match = scan(/<\?(?:.*?\?>|.*)/m)
107
107
  encoder.text_token match, :comment
108
108
  elsif match = scan(/<\/[-\w.:]*>?/m)
109
109
  in_tag = nil
@@ -16,6 +16,10 @@ module Scanners
16
16
  autoload :Patterns, 'coderay/scanners/ruby/patterns'
17
17
  autoload :StringState, 'coderay/scanners/ruby/string_state'
18
18
 
19
+ def interpreted_string_state
20
+ StringState.new :string, true, '"'
21
+ end
22
+
19
23
  protected
20
24
 
21
25
  def setup
@@ -23,7 +27,7 @@ module Scanners
23
27
  end
24
28
 
25
29
  def scan_tokens encoder, options
26
- state, heredocs = @state
30
+ state, heredocs = options[:state] || @state
27
31
  heredocs = heredocs.dup if heredocs.is_a?(Array)
28
32
 
29
33
  if state && state.instance_of?(StringState)
@@ -52,7 +52,7 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
52
52
  .debug { color: white !important; background: blue !important; }
53
53
 
54
54
  .annotation { color:#007 }
55
- .attribute-name { color:#f08 }
55
+ .attribute-name { color:#b48 }
56
56
  .attribute-value { color:#700 }
57
57
  .binary { color:#509 }
58
58
  .char .content { color:#D20 }
@@ -97,7 +97,7 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
97
97
  .octal { color:#40E }
98
98
  .operator { }
99
99
  .predefined { color:#369; font-weight:bold }
100
- .predefined-class { color:#069 }
100
+ .predefined-constant { color:#069 }
101
101
  .predefined-type { color:#0a5; font-weight:bold }
102
102
  .preprocessor { color:#579 }
103
103
  .pseudo-class { color:#00C; font-weight:bold }
@@ -303,31 +303,11 @@ module CodeRay
303
303
  @dump = Marshal.load dump
304
304
  end
305
305
 
306
- if defined?(RUBY_ENGINE) && RUBY_ENGINE['rbx']
307
- #:nocov:
308
- def text_token text, kind
309
- self << text << kind
310
- end
311
- def begin_group kind
312
- self << :begin_group << kind
313
- end
314
- def end_group kind
315
- self << :end_group << kind
316
- end
317
- def begin_line kind
318
- self << :begin_line << kind
319
- end
320
- def end_line kind
321
- self << :end_line << kind
322
- end
323
- #:nocov:
324
- else
325
- alias text_token push
326
- def begin_group kind; push :begin_group, kind end
327
- def end_group kind; push :end_group, kind end
328
- def begin_line kind; push :begin_line, kind end
329
- def end_line kind; push :end_line, kind end
330
- end
306
+ alias text_token push
307
+ def begin_group kind; push :begin_group, kind end
308
+ def end_group kind; push :end_group, kind end
309
+ def begin_line kind; push :begin_line, kind end
310
+ def end_line kind; push :end_line, kind end
331
311
  alias tokens concat
332
312
 
333
313
  end
metadata CHANGED
@@ -1,124 +1,129 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: coderay
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0.835rc1
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease: 9
5
+ version: 1.0.0.846rc2
6
6
  platform: ruby
7
- authors:
8
- - Kornelius Kalnbach
7
+ authors:
8
+ - Kornelius Kalnbach
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-29 00:00:00.000000000Z
12
+
13
+ date: 2011-09-08 00:00:00 Z
13
14
  dependencies: []
14
- description: Fast and easy syntax highlighting for selected languages, written in
15
- Ruby. Comes with RedCloth integration and LOC counter.
16
- email:
17
- - murphy@rubychan.de
18
- executables:
19
- - coderay
15
+
16
+ description: Fast and easy syntax highlighting for selected languages, written in Ruby. Comes with RedCloth integration and LOC counter.
17
+ email:
18
+ - murphy@rubychan.de
19
+ executables:
20
+ - coderay
20
21
  extensions: []
21
- extra_rdoc_files:
22
- - README_INDEX.rdoc
23
- files:
24
- - lib/coderay/duo.rb
25
- - lib/coderay/encoder.rb
26
- - lib/coderay/encoders/_map.rb
27
- - lib/coderay/encoders/comment_filter.rb
28
- - lib/coderay/encoders/count.rb
29
- - lib/coderay/encoders/debug.rb
30
- - lib/coderay/encoders/div.rb
31
- - lib/coderay/encoders/filter.rb
32
- - lib/coderay/encoders/html/css.rb
33
- - lib/coderay/encoders/html/numbering.rb
34
- - lib/coderay/encoders/html/output.rb
35
- - lib/coderay/encoders/html.rb
36
- - lib/coderay/encoders/json.rb
37
- - lib/coderay/encoders/lines_of_code.rb
38
- - lib/coderay/encoders/null.rb
39
- - lib/coderay/encoders/page.rb
40
- - lib/coderay/encoders/span.rb
41
- - lib/coderay/encoders/statistic.rb
42
- - lib/coderay/encoders/terminal.rb
43
- - lib/coderay/encoders/text.rb
44
- - lib/coderay/encoders/token_kind_filter.rb
45
- - lib/coderay/encoders/xml.rb
46
- - lib/coderay/encoders/yaml.rb
47
- - lib/coderay/for_redcloth.rb
48
- - lib/coderay/helpers/file_type.rb
49
- - lib/coderay/helpers/gzip.rb
50
- - lib/coderay/helpers/plugin.rb
51
- - lib/coderay/helpers/word_list.rb
52
- - lib/coderay/scanner.rb
53
- - lib/coderay/scanners/_map.rb
54
- - lib/coderay/scanners/c.rb
55
- - lib/coderay/scanners/clojure.rb
56
- - lib/coderay/scanners/cpp.rb
57
- - lib/coderay/scanners/css.rb
58
- - lib/coderay/scanners/debug.rb
59
- - lib/coderay/scanners/delphi.rb
60
- - lib/coderay/scanners/diff.rb
61
- - lib/coderay/scanners/erb.rb
62
- - lib/coderay/scanners/groovy.rb
63
- - lib/coderay/scanners/html.rb
64
- - lib/coderay/scanners/java/builtin_types.rb
65
- - lib/coderay/scanners/java.rb
66
- - lib/coderay/scanners/java_script.rb
67
- - lib/coderay/scanners/json.rb
68
- - lib/coderay/scanners/php.rb
69
- - lib/coderay/scanners/python.rb
70
- - lib/coderay/scanners/raydebug.rb
71
- - lib/coderay/scanners/ruby/patterns.rb
72
- - lib/coderay/scanners/ruby/string_state.rb
73
- - lib/coderay/scanners/ruby.rb
74
- - lib/coderay/scanners/sql.rb
75
- - lib/coderay/scanners/text.rb
76
- - lib/coderay/scanners/xml.rb
77
- - lib/coderay/scanners/yaml.rb
78
- - lib/coderay/style.rb
79
- - lib/coderay/styles/_map.rb
80
- - lib/coderay/styles/alpha.rb
81
- - lib/coderay/token_kinds.rb
82
- - lib/coderay/tokens.rb
83
- - lib/coderay/version.rb
84
- - lib/coderay.rb
85
- - Rakefile
86
- - README_INDEX.rdoc
87
- - LICENSE
88
- - test/functional/basic.rb
89
- - test/functional/examples.rb
90
- - test/functional/for_redcloth.rb
91
- - test/functional/suite.rb
92
- - bin/coderay
22
+
23
+ extra_rdoc_files:
24
+ - README_INDEX.rdoc
25
+ files:
26
+ - lib/coderay.rb
27
+ - lib/coderay/duo.rb
28
+ - lib/coderay/encoder.rb
29
+ - lib/coderay/for_redcloth.rb
30
+ - lib/coderay/scanner.rb
31
+ - lib/coderay/style.rb
32
+ - lib/coderay/token_kinds.rb
33
+ - lib/coderay/tokens.rb
34
+ - lib/coderay/version.rb
35
+ - lib/coderay/encoders/_map.rb
36
+ - lib/coderay/encoders/comment_filter.rb
37
+ - lib/coderay/encoders/count.rb
38
+ - lib/coderay/encoders/debug.rb
39
+ - lib/coderay/encoders/div.rb
40
+ - lib/coderay/encoders/filter.rb
41
+ - lib/coderay/encoders/html.rb
42
+ - lib/coderay/encoders/json.rb
43
+ - lib/coderay/encoders/lines_of_code.rb
44
+ - lib/coderay/encoders/null.rb
45
+ - lib/coderay/encoders/page.rb
46
+ - lib/coderay/encoders/span.rb
47
+ - lib/coderay/encoders/statistic.rb
48
+ - lib/coderay/encoders/terminal.rb
49
+ - lib/coderay/encoders/text.rb
50
+ - lib/coderay/encoders/token_kind_filter.rb
51
+ - lib/coderay/encoders/xml.rb
52
+ - lib/coderay/encoders/yaml.rb
53
+ - lib/coderay/encoders/html/css.rb
54
+ - lib/coderay/encoders/html/numbering.rb
55
+ - lib/coderay/encoders/html/output.rb
56
+ - lib/coderay/helpers/file_type.rb
57
+ - lib/coderay/helpers/gzip.rb
58
+ - lib/coderay/helpers/plugin.rb
59
+ - lib/coderay/helpers/word_list.rb
60
+ - lib/coderay/scanners/_map.rb
61
+ - lib/coderay/scanners/c.rb
62
+ - lib/coderay/scanners/clojure.rb
63
+ - lib/coderay/scanners/cpp.rb
64
+ - lib/coderay/scanners/css.rb
65
+ - lib/coderay/scanners/debug.rb
66
+ - lib/coderay/scanners/delphi.rb
67
+ - lib/coderay/scanners/diff.rb
68
+ - lib/coderay/scanners/erb.rb
69
+ - lib/coderay/scanners/groovy.rb
70
+ - lib/coderay/scanners/haml.rb
71
+ - lib/coderay/scanners/html.rb
72
+ - lib/coderay/scanners/java.rb
73
+ - lib/coderay/scanners/java_script.rb
74
+ - lib/coderay/scanners/json.rb
75
+ - lib/coderay/scanners/php.rb
76
+ - lib/coderay/scanners/python.rb
77
+ - lib/coderay/scanners/raydebug.rb
78
+ - lib/coderay/scanners/ruby.rb
79
+ - lib/coderay/scanners/sql.rb
80
+ - lib/coderay/scanners/text.rb
81
+ - lib/coderay/scanners/xml.rb
82
+ - lib/coderay/scanners/yaml.rb
83
+ - lib/coderay/scanners/java/builtin_types.rb
84
+ - lib/coderay/scanners/ruby/patterns.rb
85
+ - lib/coderay/scanners/ruby/string_state.rb
86
+ - lib/coderay/styles/_map.rb
87
+ - lib/coderay/styles/alpha.rb
88
+ - Rakefile
89
+ - README_INDEX.rdoc
90
+ - LICENSE
91
+ - test/functional/basic.rb
92
+ - test/functional/examples.rb
93
+ - test/functional/for_redcloth.rb
94
+ - test/functional/suite.rb
95
+ - bin/coderay
93
96
  homepage: http://coderay.rubychan.de
94
97
  licenses: []
98
+
95
99
  post_install_message:
96
- rdoc_options:
97
- - -SNw2
98
- - -mREADME_INDEX.rdoc
99
- - -t CodeRay Documentation
100
- require_paths:
101
- - lib
102
- required_ruby_version: !ruby/object:Gem::Requirement
100
+ rdoc_options:
101
+ - -SNw2
102
+ - -mREADME_INDEX.rdoc
103
+ - -t CodeRay Documentation
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
103
107
  none: false
104
- requirements:
105
- - - ! '>='
106
- - !ruby/object:Gem::Version
107
- version: 1.8.7
108
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 1.8.7
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
113
  none: false
110
- requirements:
111
- - - ! '>'
112
- - !ruby/object:Gem::Version
113
- version: 1.3.1
114
+ requirements:
115
+ - - ">"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.1
114
118
  requirements: []
119
+
115
120
  rubyforge_project: coderay
116
- rubygems_version: 1.8.8
121
+ rubygems_version: 1.8.9
117
122
  signing_key:
118
123
  specification_version: 3
119
124
  summary: Fast syntax highlighting for selected languages.
120
- test_files:
121
- - test/functional/basic.rb
122
- - test/functional/examples.rb
123
- - test/functional/for_redcloth.rb
124
- - test/functional/suite.rb
125
+ test_files:
126
+ - test/functional/basic.rb
127
+ - test/functional/examples.rb
128
+ - test/functional/for_redcloth.rb
129
+ - test/functional/suite.rb