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 +1 -1
- data/lib/coderay/encoder.rb +26 -6
- data/lib/coderay/encoders/div.rb +2 -3
- data/lib/coderay/encoders/page.rb +1 -2
- data/lib/coderay/encoders/span.rb +2 -3
- data/lib/coderay/encoders/text.rb +4 -4
- data/lib/coderay/for_redcloth.rb +8 -1
- data/lib/coderay/helpers/file_type.rb +3 -0
- data/lib/coderay/helpers/plugin.rb +8 -0
- data/lib/coderay/scanners/debug.rb +1 -0
- data/lib/coderay/scanners/diff.rb +1 -0
- data/lib/coderay/scanners/nitro_xhtml.rb +1 -0
- data/lib/coderay/scanners/plaintext.rb +1 -0
- data/lib/coderay/scanners/python.rb +71 -52
- data/lib/coderay/scanners/rhtml.rb +1 -0
- metadata +4 -3
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.
|
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]
|
data/lib/coderay/encoder.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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.
|
data/lib/coderay/encoders/div.rb
CHANGED
@@ -14,16 +14,16 @@ module Encoders
|
|
14
14
|
|
15
15
|
protected
|
16
16
|
def setup options
|
17
|
-
|
17
|
+
super
|
18
18
|
@sep = options[:separator]
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
21
|
+
def text_token text, kind
|
22
|
+
text + @sep
|
23
23
|
end
|
24
24
|
|
25
25
|
def finish options
|
26
|
-
|
26
|
+
super.chomp @sep
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
data/lib/coderay/for_redcloth.rb
CHANGED
@@ -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
|
-
|
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
|
@@ -70,7 +70,7 @@ module Scanners
|
|
70
70
|
[,;:()\[\]{}] | # simple delimiters
|
71
71
|
\/\/=? | \*\*=? | # special math
|
72
72
|
[-+*\/%&|^]=? | # ordinary math and binary logic
|
73
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
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
|
-
|
126
|
-
|
153
|
+
# TODO: backticks
|
154
|
+
|
155
|
+
elsif match = scan(unicode ? /[[:alpha:]_]\w*/ux : /[[:alpha:]_]\w*/x)
|
127
156
|
kind = IDENT_KIND[match]
|
128
|
-
# TODO:
|
157
|
+
# TODO: from, import
|
129
158
|
# TODO: keyword arguments
|
130
159
|
kind = :ident if last_token_dot
|
131
|
-
|
132
|
-
|
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
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
205
|
+
next
|
188
206
|
end
|
189
207
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
-
|
201
|
-
|
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' %
|
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.
|
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-
|
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.
|
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.
|