coderay 1.0.5 → 1.0.6.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,6 +47,13 @@ module Encoders
47
47
  #
48
48
  # Default: 'CodeRay output'
49
49
  #
50
+ # === :break_lines
51
+ #
52
+ # Split multiline blocks at line breaks.
53
+ # Forced to true if :line_numbers option is set to :inline.
54
+ #
55
+ # Default: false
56
+ #
50
57
  # === :line_numbers
51
58
  # Include line numbers in :table, :inline, or nil (no line numbers)
52
59
  #
@@ -100,6 +107,8 @@ module Encoders
100
107
  :wrap => nil,
101
108
  :title => 'CodeRay output',
102
109
 
110
+ :break_lines => false,
111
+
103
112
  :line_numbers => nil,
104
113
  :line_number_anchors => 'n',
105
114
  :line_number_start => 1,
@@ -168,6 +177,10 @@ module Encoders
168
177
  @out = ''
169
178
  end
170
179
 
180
+ options[:break_lines] = true if options[:line_numbers] == :inline
181
+
182
+ @break_lines = (options[:break_lines] == true)
183
+
171
184
  @HTML_ESCAPE = HTML_ESCAPE.dup
172
185
  @HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
173
186
 
@@ -245,7 +258,19 @@ module Encoders
245
258
  if text =~ /#{HTML_ESCAPE_PATTERN}/o
246
259
  text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
247
260
  end
248
- if style = @span_for_kind[@last_opened ? [kind, *@opened] : kind]
261
+
262
+ style = @span_for_kind[@last_opened ? [kind, *@opened] : kind]
263
+
264
+ if @break_lines && (i = text.index("\n")) && (c = @opened.size + (style ? 1 : 0)) > 0
265
+ close = '</span>' * c
266
+ reopen = ''
267
+ @opened.each_with_index do |k, index|
268
+ reopen << (@span_for_kind[index > 0 ? [k, *@opened[0 ... index ]] : k] || '<span>')
269
+ end
270
+ text[i .. -1] = text[i .. -1].gsub("\n", "#{close}\n#{reopen}#{style}")
271
+ end
272
+
273
+ if style
249
274
  @out << style << text << '</span>'
250
275
  else
251
276
  @out << text
@@ -68,23 +68,11 @@ module Encoders
68
68
  when :inline
69
69
  max_width = (start + line_count).to_s.size
70
70
  line_number = start
71
- nesting = []
72
71
  output.gsub!(/^.*$\n?/) do |line|
73
- line.chomp!
74
- open = nesting.join
75
- line.scan(%r!<(/)?span[^>]*>?!) do |close,|
76
- if close
77
- nesting.pop
78
- else
79
- nesting << $&
80
- end
81
- end
82
- close = '</span>' * nesting.size
83
-
84
72
  line_number_text = bolding.call line_number
85
73
  indent = ' ' * (max_width - line_number.to_s.size) # TODO: Optimize (10^x)
86
74
  line_number += 1
87
- "<span class=\"line-numbers\">#{indent}#{line_number_text}</span>#{open}#{line}#{close}\n"
75
+ "<span class=\"line-numbers\">#{indent}#{line_number_text}</span>#{line}"
88
76
  end
89
77
 
90
78
  when :table
@@ -90,8 +90,8 @@ module CodeRay
90
90
  'gvy' => :groovy,
91
91
  'h' => :c,
92
92
  'haml' => :haml,
93
- 'htm' => :page,
94
- 'html' => :page,
93
+ 'htm' => :html,
94
+ 'html' => :html,
95
95
  'html.erb' => :erb,
96
96
  'java' => :java,
97
97
  'js' => :java_script,
@@ -120,7 +120,7 @@ module CodeRay
120
120
  'sql' => :sql,
121
121
  # 'ss' => :scheme,
122
122
  'tmproj' => :xml,
123
- 'xhtml' => :page,
123
+ 'xhtml' => :html,
124
124
  'xml' => :xml,
125
125
  'yaml' => :yaml,
126
126
  'yml' => :yaml,
@@ -144,7 +144,7 @@ module Scanners
144
144
  encoder.end_group :string
145
145
 
146
146
  elsif match = scan(/#{RE::Function}/o)
147
- encoder.begin_group :string
147
+ encoder.begin_group :function
148
148
  start = match[/^\w+\(/]
149
149
  encoder.text_token start, :delimiter
150
150
  if match[-1] == ?)
@@ -153,7 +153,7 @@ module Scanners
153
153
  else
154
154
  encoder.text_token match[start.size..-1], :content
155
155
  end
156
- encoder.end_group :string
156
+ encoder.end_group :function
157
157
 
158
158
  elsif match = scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox)
159
159
  encoder.text_token match, :float
@@ -1,3 +1,4 @@
1
+ # encoding: ASCII-8BIT
1
2
  module CodeRay
2
3
  module Scanners
3
4
 
@@ -61,7 +61,7 @@ module Scanners
61
61
  add(PREDEFINED_VARIABLES_AND_CONSTANTS, :predefined_constant).
62
62
  add(PREDEFINED_EXCEPTIONS, :exception) # :nodoc:
63
63
 
64
- NAME = / [^\W\d] \w* /x # :nodoc:
64
+ NAME = / [[:alpha:]_] \w* /x # :nodoc:
65
65
  ESCAPE = / [abfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
66
66
  UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} | N\{[-\w ]+\} /x # :nodoc:
67
67
 
@@ -1,3 +1,3 @@
1
1
  module CodeRay
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
3
3
  end
metadata CHANGED
@@ -1,34 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: coderay
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 5
10
- version: 1.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.6.rc1
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Kornelius Kalnbach
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-12-28 00:00:00 +01:00
19
- default_executable:
12
+ date: 2012-04-01 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
- description: Fast and easy syntax highlighting for selected languages, written in Ruby. Comes with RedCloth integration and LOC counter.
23
- email:
14
+ description: Fast and easy syntax highlighting for selected languages, written in
15
+ Ruby. Comes with RedCloth integration and LOC counter.
16
+ email:
24
17
  - murphy@rubychan.de
25
- executables:
18
+ executables:
26
19
  - coderay
27
20
  extensions: []
28
-
29
- extra_rdoc_files:
21
+ extra_rdoc_files:
30
22
  - README_INDEX.rdoc
31
- files:
23
+ files:
32
24
  - LICENSE
33
25
  - README_INDEX.rdoc
34
26
  - Rakefile
@@ -99,46 +91,36 @@ files:
99
91
  - test/functional/examples.rb
100
92
  - test/functional/for_redcloth.rb
101
93
  - test/functional/suite.rb
102
- - bin/coderay
103
- has_rdoc: true
94
+ - !binary |-
95
+ YmluL2NvZGVyYXk=
104
96
  homepage: http://coderay.rubychan.de
105
97
  licenses: []
106
-
107
98
  post_install_message:
108
- rdoc_options:
99
+ rdoc_options:
109
100
  - -SNw2
110
101
  - -mREADME_INDEX.rdoc
111
102
  - -t CodeRay Documentation
112
- require_paths:
103
+ require_paths:
113
104
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
105
+ required_ruby_version: !ruby/object:Gem::Requirement
115
106
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 59
120
- segments:
121
- - 1
122
- - 8
123
- - 6
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
124
110
  version: 1.8.6
125
- required_rubygems_version: !ruby/object:Gem::Requirement
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
112
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
113
+ requirements:
114
+ - - ! '>'
115
+ - !ruby/object:Gem::Version
116
+ version: 1.3.1
134
117
  requirements: []
135
-
136
118
  rubyforge_project: coderay
137
- rubygems_version: 1.6.2
119
+ rubygems_version: 1.8.21
138
120
  signing_key:
139
121
  specification_version: 3
140
122
  summary: Fast syntax highlighting for selected languages.
141
- test_files:
123
+ test_files:
142
124
  - test/functional/basic.rb
143
125
  - test/functional/examples.rb
144
126
  - test/functional/for_redcloth.rb