raldred-coderay 0.9.3431 → 0.9.3551

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/lib/README CHANGED
@@ -18,7 +18,7 @@ And with line numbers.
18
18
  * is what everybody should have on their website
19
19
  * solves all your problems and makes the girls run after you
20
20
 
21
- Version: 0.8.1
21
+ Version: 0.9.0
22
22
  Author:: murphy (Kornelius Kalnbach)
23
23
  Contact:: murphy rubychan de
24
24
  Website:: coderay.rubychan.de[http://coderay.rubychan.de]
@@ -1,5 +1,3 @@
1
- require "stringio"
2
-
3
1
  module CodeRay
4
2
 
5
3
  # This module holds the Encoder class and its subclasses.
@@ -132,7 +130,7 @@ module CodeRay
132
130
  # By default, it calls text_token or block_token, depending on
133
131
  # whether +text+ is a String.
134
132
  def token text, kind
135
- out =
133
+ encoded_token =
136
134
  if text.is_a? ::String
137
135
  text_token text, kind
138
136
  elsif text.is_a? ::Symbol
@@ -140,12 +138,18 @@ module CodeRay
140
138
  else
141
139
  raise 'Unknown token text type: %p' % text
142
140
  end
143
- @out << out if defined?(@out) && @out
141
+ append_encoded_token_to_output encoded_token
144
142
  end
145
-
143
+
144
+ def append_encoded_token_to_output encoded_token
145
+ @out << encoded_token if encoded_token && defined?(@out) && @out
146
+ end
147
+
148
+ # Called for each text token ([text, kind]), where text is a String.
146
149
  def text_token text, kind
147
150
  end
148
-
151
+
152
+ # Called for each block (non-text) token ([action, kind]), where action is a Symbol.
149
153
  def block_token action, kind
150
154
  case action
151
155
  when :open
@@ -160,6 +164,22 @@ module CodeRay
160
164
  raise 'unknown block action: %p' % action
161
165
  end
162
166
  end
167
+
168
+ # Called for each block token at the start of the block ([:open, kind]).
169
+ def open_token kind
170
+ end
171
+
172
+ # Called for each block token end of the block ([:close, kind]).
173
+ def close_token kind
174
+ end
175
+
176
+ # Called for each line token block at the start of the line ([:begin_line, kind]).
177
+ def begin_line kind
178
+ end
179
+
180
+ # Called for each line token block at the end of the line ([:end_line, kind]).
181
+ def end_line kind
182
+ end
163
183
 
164
184
  # Called with merged options after encoding starts.
165
185
  # The return value is the result of encoding, typically @out.
@@ -9,10 +9,9 @@ module Encoders
9
9
 
10
10
  register_for :div
11
11
 
12
- DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
12
+ DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge \
13
13
  :css => :style,
14
- :wrap => :div,
15
- })
14
+ :wrap => :div
16
15
 
17
16
  end
18
17
 
@@ -9,11 +9,10 @@ module Encoders
9
9
 
10
10
  register_for :page
11
11
 
12
- DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
12
+ DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge \
13
13
  :css => :class,
14
14
  :wrap => :page,
15
15
  :line_numbers => :table
16
- })
17
16
 
18
17
  end
19
18
 
@@ -9,10 +9,9 @@ module Encoders
9
9
 
10
10
  register_for :span
11
11
 
12
- DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
12
+ DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge \
13
13
  :css => :style,
14
- :wrap => :span,
15
- })
14
+ :wrap => :span
16
15
 
17
16
  end
18
17
 
@@ -14,16 +14,16 @@ module Encoders
14
14
 
15
15
  protected
16
16
  def setup options
17
- @out = ''
17
+ super
18
18
  @sep = options[:separator]
19
19
  end
20
20
 
21
- def token text, kind
22
- @out << text + @sep if text.is_a? ::String
21
+ def text_token text, kind
22
+ text + @sep
23
23
  end
24
24
 
25
25
  def finish options
26
- @out.chomp @sep
26
+ super.chomp @sep
27
27
  end
28
28
 
29
29
  end
@@ -15,7 +15,9 @@ module CodeRay
15
15
  def self.install
16
16
  gem 'RedCloth', '>= 4.0.3' rescue nil
17
17
  require 'redcloth'
18
- raise 'CodeRay.for_redcloth needs RedCloth 4.0.3 or later.' unless RedCloth::VERSION.to_s >= '4.0.3'
18
+ unless RedCloth::VERSION.to_s >= '4.0.3'
19
+ raise 'CodeRay.for_redcloth needs RedCloth version 4.0.3 or later.'
20
+ end
19
21
  RedCloth::TextileDoc.send :include, ForRedCloth::TextileDoc
20
22
  RedCloth::Formatters::HTML.module_eval do
21
23
  def unescape(html)
@@ -30,6 +32,11 @@ module CodeRay
30
32
  undef_method :code, :bc_open, :bc_close, :escape_pre
31
33
  def code(opts) # :nodoc:
32
34
  opts[:block] = true
35
+ if !opts[:lang] && RedCloth::VERSION.to_s >= '4.2.0'
36
+ # simulating pre-4.2 behavior
37
+ opts[:text].sub!(/\A\[(\w+)\]/, '')
38
+ opts[:lang] = $1
39
+ end
33
40
  if opts[:lang] && !filter_coderay
34
41
  require 'coderay'
35
42
  @in_bc ||= nil
@@ -85,6 +85,7 @@ module FileType
85
85
  'cpp' => :c,
86
86
  'css' => :css,
87
87
  'diff' => :diff,
88
+ 'dpr' => :delphi,
88
89
  'groovy' => :groovy,
89
90
  'gvy' => :groovy,
90
91
  'h' => :c,
@@ -95,6 +96,7 @@ module FileType
95
96
  'js' => :java_script,
96
97
  'json' => :json,
97
98
  'mab' => :ruby,
99
+ 'pas' => :delphi,
98
100
  'patch' => :diff,
99
101
  'php' => :php,
100
102
  'php3' => :php,
@@ -108,6 +110,7 @@ module FileType
108
110
  'rb' => :ruby,
109
111
  'rbw' => :ruby,
110
112
  'rhtml' => :rhtml,
113
+ 'rxml' => :ruby,
111
114
  'sch' => :scheme,
112
115
  'sql' => :sql,
113
116
  'ss' => :scheme,
@@ -281,6 +281,14 @@ module Plugin
281
281
  plugin_host.register self, *ids
282
282
  end
283
283
 
284
+ def title title = nil
285
+ if title
286
+ @title = title.to_s
287
+ else
288
+ @title ||= name[/([^:]+)$/, 1]
289
+ end
290
+ end
291
+
284
292
  # The host for this Plugin class.
285
293
  def plugin_host host = nil
286
294
  if host and not host.is_a? PluginHost
@@ -7,6 +7,7 @@ module Scanners
7
7
  include Streamable
8
8
  register_for :debug
9
9
  file_extension 'raydebug'
10
+ title 'CodeRay Token Dump'
10
11
 
11
12
  protected
12
13
  def scan_tokens tokens, options
@@ -4,6 +4,7 @@ module Scanners
4
4
  class Diff < Scanner
5
5
 
6
6
  register_for :diff
7
+ title 'diff output'
7
8
 
8
9
  def scan_tokens tokens, options
9
10
 
@@ -10,6 +10,7 @@ module Scanners
10
10
  include Streamable
11
11
  register_for :nitro_xhtml
12
12
  file_extension :xhtml
13
+ title 'Nitro XHTML'
13
14
 
14
15
  NITRO_RUBY_BLOCK = /
15
16
  <\?r
@@ -4,6 +4,7 @@ module Scanners
4
4
  class Plaintext < Scanner
5
5
 
6
6
  register_for :plaintext, :plain
7
+ title 'Plain text'
7
8
 
8
9
  include Streamable
9
10
 
@@ -70,7 +70,7 @@ module Scanners
70
70
  [,;:()\[\]{}] | # simple delimiters
71
71
  \/\/=? | \*\*=? | # special math
72
72
  [-+*\/%&|^]=? | # ordinary math and binary logic
73
- ~ | # binary complement
73
+ [~`] | # binary complement and inspection
74
74
  <<=? | >>=? | [<>=]=? | != # comparison and assignment
75
75
  /x
76
76
 
@@ -82,10 +82,16 @@ module Scanners
82
82
  h[delimiter] = / [^\\\n]+? (?= \\ | $ | #{Regexp.escape(delimiter)} ) /x
83
83
  end
84
84
 
85
+ DEF_NEW_STATE = WordList.new(:initial).
86
+ add(%w(def), :def_expected).
87
+ # add(%w(import from), :include_expected).
88
+ add(%w(class), :class_expected)
89
+
85
90
  def scan_tokens tokens, options
86
91
 
87
92
  state = :initial
88
93
  string_delimiter = nil
94
+ string_raw = false
89
95
  import_clause = class_name_follows = last_token_dot = false
90
96
  unicode = string.respond_to?(:encoding) && string.encoding.name == 'UTF-8'
91
97
 
@@ -94,19 +100,41 @@ module Scanners
94
100
  kind = nil
95
101
  match = nil
96
102
 
97
- case state
98
-
99
- when :initial
100
-
101
- if match = scan(/ [ \t]+ | \\?\n /x)
102
- tokens << [match, :space]
103
- next
104
-
105
- elsif match = scan(/ \# [^\n]* /mx)
106
- tokens << [match, :comment]
103
+ if state == :string
104
+ if scan(STRING_DELIMITER_REGEXP[string_delimiter])
105
+ tokens << [matched, :delimiter]
106
+ tokens << [:close, :string]
107
+ state = :initial
107
108
  next
109
+ elsif string_delimiter.size == 3 && scan(/\n/)
110
+ kind = :content
111
+ elsif scan(STRING_CONTENT_REGEXP[string_delimiter])
112
+ kind = :content
113
+ elsif !string_raw && scan(/ \\ #{ESCAPE} /ox)
114
+ kind = :char
115
+ elsif scan(/ \\ #{UNICODE_ESCAPE} /ox)
116
+ kind = :char
117
+ elsif scan(/ \\ . /x)
118
+ kind = :content
119
+ elsif scan(/ \\ | $ /x)
120
+ tokens << [:close, :string]
121
+ kind = :error
122
+ state = :initial
123
+ else
124
+ raise_inspect "else case \" reached; %p not handled." % peek(1), tokens, state
125
+ end
126
+
127
+ elsif match = scan(/ [ \t]+ | \\?\n /x)
128
+ tokens << [match, :space]
129
+ next
130
+
131
+ elsif match = scan(/ \# [^\n]* /mx)
132
+ tokens << [match, :comment]
133
+ next
134
+
135
+ elsif state == :initial
108
136
 
109
- elsif scan(/#{OPERATOR}/o)
137
+ if scan(/#{OPERATOR}/o)
110
138
  kind = :operator
111
139
 
112
140
  elsif match = scan(/(u?r?|b)?("""|"|'''|')/i)
@@ -122,14 +150,20 @@ module Scanners
122
150
  state = :string
123
151
  kind = :delimiter
124
152
 
125
- elsif match = (unicode && scan(/[[:alpha:]_]\w*/ux)) ||
126
- scan(/[[:alpha:]_]\w*/x)
153
+ # TODO: backticks
154
+
155
+ elsif match = scan(unicode ? /[[:alpha:]_]\w*/ux : /[[:alpha:]_]\w*/x)
127
156
  kind = IDENT_KIND[match]
128
- # TODO: handle class, def, from, import
157
+ # TODO: from, import
129
158
  # TODO: keyword arguments
130
159
  kind = :ident if last_token_dot
131
- kind = check(/\(/) ? :ident : :keyword if kind == :old_keyword
132
- kind = :ident if kind == :predefined && check(/=/)
160
+ if kind == :old_keyword
161
+ kind = check(/\(/) ? :ident : :keyword
162
+ elsif kind == :predefined && check(/ *=/)
163
+ kind = :ident
164
+ elsif kind == :keyword
165
+ state = DEF_NEW_STATE[match]
166
+ end
133
167
 
134
168
  elsif scan(/@[a-zA-Z0-9_.]+[lL]?/)
135
169
  kind = :decorator
@@ -162,51 +196,36 @@ module Scanners
162
196
  kind = :error
163
197
 
164
198
  end
165
-
166
- when :string
167
- if scan(STRING_DELIMITER_REGEXP[string_delimiter])
168
- tokens << [matched, :delimiter]
169
- tokens << [:close, :string]
170
- state = :initial
171
- next
172
- elsif string_delimiter.size == 3 && scan(/\n/)
173
- kind = :content
174
- elsif scan(STRING_CONTENT_REGEXP[string_delimiter])
175
- kind = :content
176
- elsif !string_raw && scan(/ \\ #{ESCAPE} /ox)
177
- kind = :char
178
- elsif scan(/ \\ #{UNICODE_ESCAPE} /ox)
179
- kind = :char
180
- elsif scan(/ \\ . /x)
181
- kind = :content
182
- elsif scan(/ \\ | $ /x)
183
- tokens << [:close, :string]
184
- kind = :error
185
- state = :initial
199
+
200
+ elsif state == :def_expected
201
+ state = :initial
202
+ if match = scan(unicode ? /[[:alpha:]_]\w*/ux : /[[:alpha:]_]\w*/x)
203
+ kind = :method
186
204
  else
187
- raise_inspect "else case \" reached; %p not handled." % peek(1), tokens, state
205
+ next
188
206
  end
189
207
 
190
- when :include_expected
191
- if scan(/<[^>\n]+>?|"[^"\n\\]*(?:\\.[^"\n\\]*)*"?/)
192
- kind = :include
193
- state = :initial
194
-
195
- elsif match = scan(/\s+/)
196
- kind = :space
197
- state = :initial if match.index ?\n
198
-
208
+ elsif state == :class_expected
209
+ state = :initial
210
+ if match = scan(unicode ? /[[:alpha:]_]\w*/ux : /[[:alpha:]_]\w*/x)
211
+ kind = :class
199
212
  else
200
- getch
201
- kind = :error
213
+ next
214
+ end
202
215
 
216
+ elsif state == :include_expected
217
+ state = :initial
218
+ if match = scan(unicode ? /[[:alpha:]_]\w*/ux : /[[:alpha:]_]\w*/x)
219
+ kind = :include
220
+ else
221
+ next
203
222
  end
204
223
 
205
224
  else
206
225
  raise_inspect 'Unknown state', tokens, state
207
-
226
+
208
227
  end
209
-
228
+
210
229
  match ||= matched
211
230
  if $DEBUG and not kind
212
231
  raise_inspect 'Error token %p in line %d' %
@@ -9,6 +9,7 @@ module Scanners
9
9
 
10
10
  include Streamable
11
11
  register_for :rhtml
12
+ title 'HTML.ERB'
12
13
 
13
14
  ERB_RUBY_BLOCK = /
14
15
  <%(?!%)[=-]?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raldred-coderay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3431
4
+ version: 0.9.3551
5
5
  platform: ruby
6
6
  authors:
7
7
  - murphy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-09 00:00:00 -07:00
12
+ date: 2009-08-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -90,6 +90,7 @@ files:
90
90
  - TODO
91
91
  has_rdoc: true
92
92
  homepage: http://coderay.rubychan.de
93
+ licenses:
93
94
  post_install_message:
94
95
  rdoc_options:
95
96
  - -SNw2
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  requirements: []
114
115
 
115
116
  rubyforge_project: coderay
116
- rubygems_version: 1.2.0
117
+ rubygems_version: 1.3.5
117
118
  signing_key:
118
119
  specification_version: 2
119
120
  summary: CodeRay is a fast syntax highlighter engine for many languages.