giga-fast-rb 0.0.1
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.
- checksums.yaml +7 -0
- data/coderay-1.1.3/MIT-LICENSE +22 -0
- data/coderay-1.1.3/README_INDEX.rdoc +123 -0
- data/coderay-1.1.3/bin/coderay +215 -0
- data/coderay-1.1.3/lib/coderay/duo.rb +81 -0
- data/coderay-1.1.3/lib/coderay/encoders/_map.rb +17 -0
- data/coderay-1.1.3/lib/coderay/encoders/comment_filter.rb +25 -0
- data/coderay-1.1.3/lib/coderay/encoders/count.rb +39 -0
- data/coderay-1.1.3/lib/coderay/encoders/debug.rb +49 -0
- data/coderay-1.1.3/lib/coderay/encoders/debug_lint.rb +63 -0
- data/coderay-1.1.3/lib/coderay/encoders/div.rb +23 -0
- data/coderay-1.1.3/lib/coderay/encoders/encoder.rb +190 -0
- data/coderay-1.1.3/lib/coderay/encoders/filter.rb +58 -0
- data/coderay-1.1.3/lib/coderay/encoders/html/css.rb +65 -0
- data/coderay-1.1.3/lib/coderay/encoders/html/numbering.rb +108 -0
- data/coderay-1.1.3/lib/coderay/encoders/html/output.rb +164 -0
- data/coderay-1.1.3/lib/coderay/encoders/html.rb +333 -0
- data/coderay-1.1.3/lib/coderay/encoders/json.rb +83 -0
- data/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb +45 -0
- data/coderay-1.1.3/lib/coderay/encoders/lint.rb +59 -0
- data/coderay-1.1.3/lib/coderay/encoders/null.rb +18 -0
- data/coderay-1.1.3/lib/coderay/encoders/page.rb +24 -0
- data/coderay-1.1.3/lib/coderay/encoders/span.rb +23 -0
- data/coderay-1.1.3/lib/coderay/encoders/statistic.rb +95 -0
- data/coderay-1.1.3/lib/coderay/encoders/terminal.rb +195 -0
- data/coderay-1.1.3/lib/coderay/encoders/text.rb +46 -0
- data/coderay-1.1.3/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/coderay-1.1.3/lib/coderay/encoders/xml.rb +72 -0
- data/coderay-1.1.3/lib/coderay/encoders/yaml.rb +50 -0
- data/coderay-1.1.3/lib/coderay/encoders.rb +18 -0
- data/coderay-1.1.3/lib/coderay/for_redcloth.rb +95 -0
- data/coderay-1.1.3/lib/coderay/helpers/file_type.rb +151 -0
- data/coderay-1.1.3/lib/coderay/helpers/plugin.rb +55 -0
- data/coderay-1.1.3/lib/coderay/helpers/plugin_host.rb +221 -0
- data/coderay-1.1.3/lib/coderay/helpers/word_list.rb +72 -0
- data/coderay-1.1.3/lib/coderay/scanners/_map.rb +24 -0
- data/coderay-1.1.3/lib/coderay/scanners/c.rb +189 -0
- data/coderay-1.1.3/lib/coderay/scanners/clojure.rb +217 -0
- data/coderay-1.1.3/lib/coderay/scanners/cpp.rb +217 -0
- data/coderay-1.1.3/lib/coderay/scanners/css.rb +196 -0
- data/coderay-1.1.3/lib/coderay/scanners/debug.rb +75 -0
- data/coderay-1.1.3/lib/coderay/scanners/delphi.rb +144 -0
- data/coderay-1.1.3/lib/coderay/scanners/diff.rb +221 -0
- data/coderay-1.1.3/lib/coderay/scanners/erb.rb +81 -0
- data/coderay-1.1.3/lib/coderay/scanners/go.rb +208 -0
- data/coderay-1.1.3/lib/coderay/scanners/groovy.rb +268 -0
- data/coderay-1.1.3/lib/coderay/scanners/haml.rb +168 -0
- data/coderay-1.1.3/lib/coderay/scanners/html.rb +275 -0
- data/coderay-1.1.3/lib/coderay/scanners/java/builtin_types.rb +421 -0
- data/coderay-1.1.3/lib/coderay/scanners/java.rb +174 -0
- data/coderay-1.1.3/lib/coderay/scanners/java_script.rb +236 -0
- data/coderay-1.1.3/lib/coderay/scanners/json.rb +98 -0
- data/coderay-1.1.3/lib/coderay/scanners/lua.rb +280 -0
- data/coderay-1.1.3/lib/coderay/scanners/php.rb +527 -0
- data/coderay-1.1.3/lib/coderay/scanners/python.rb +287 -0
- data/coderay-1.1.3/lib/coderay/scanners/raydebug.rb +75 -0
- data/coderay-1.1.3/lib/coderay/scanners/ruby/patterns.rb +178 -0
- data/coderay-1.1.3/lib/coderay/scanners/ruby/string_state.rb +79 -0
- data/coderay-1.1.3/lib/coderay/scanners/ruby.rb +477 -0
- data/coderay-1.1.3/lib/coderay/scanners/sass.rb +232 -0
- data/coderay-1.1.3/lib/coderay/scanners/scanner.rb +337 -0
- data/coderay-1.1.3/lib/coderay/scanners/sql.rb +169 -0
- data/coderay-1.1.3/lib/coderay/scanners/taskpaper.rb +36 -0
- data/coderay-1.1.3/lib/coderay/scanners/text.rb +26 -0
- data/coderay-1.1.3/lib/coderay/scanners/xml.rb +17 -0
- data/coderay-1.1.3/lib/coderay/scanners/yaml.rb +140 -0
- data/coderay-1.1.3/lib/coderay/scanners.rb +27 -0
- data/coderay-1.1.3/lib/coderay/styles/_map.rb +7 -0
- data/coderay-1.1.3/lib/coderay/styles/alpha.rb +153 -0
- data/coderay-1.1.3/lib/coderay/styles/style.rb +18 -0
- data/coderay-1.1.3/lib/coderay/styles.rb +15 -0
- data/coderay-1.1.3/lib/coderay/token_kinds.rb +85 -0
- data/coderay-1.1.3/lib/coderay/tokens.rb +164 -0
- data/coderay-1.1.3/lib/coderay/tokens_proxy.rb +55 -0
- data/coderay-1.1.3/lib/coderay/version.rb +3 -0
- data/coderay-1.1.3/lib/coderay.rb +284 -0
- data/giga-fast-rb.gemspec +12 -0
- metadata +117 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Encoders
|
|
3
|
+
|
|
4
|
+
# Outputs code highlighted for a color terminal.
|
|
5
|
+
#
|
|
6
|
+
# Note: This encoder is in beta. It currently doesn't use the Styles.
|
|
7
|
+
#
|
|
8
|
+
# Alias: +term+
|
|
9
|
+
#
|
|
10
|
+
# == Authors & License
|
|
11
|
+
#
|
|
12
|
+
# By Rob Aldred (http://robaldred.co.uk)
|
|
13
|
+
#
|
|
14
|
+
# Based on idea by Nathan Weizenbaum (http://nex-3.com)
|
|
15
|
+
#
|
|
16
|
+
# MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
17
|
+
class Terminal < Encoder
|
|
18
|
+
|
|
19
|
+
register_for :terminal
|
|
20
|
+
|
|
21
|
+
TOKEN_COLORS = {
|
|
22
|
+
:debug => "\e[1;37;44m",
|
|
23
|
+
|
|
24
|
+
:annotation => "\e[34m",
|
|
25
|
+
:attribute_name => "\e[35m",
|
|
26
|
+
:attribute_value => "\e[31m",
|
|
27
|
+
:binary => {
|
|
28
|
+
:self => "\e[31m",
|
|
29
|
+
:char => "\e[1;31m",
|
|
30
|
+
:delimiter => "\e[1;31m",
|
|
31
|
+
},
|
|
32
|
+
:char => {
|
|
33
|
+
:self => "\e[35m",
|
|
34
|
+
:delimiter => "\e[1;35m"
|
|
35
|
+
},
|
|
36
|
+
:class => "\e[1;35;4m",
|
|
37
|
+
:class_variable => "\e[36m",
|
|
38
|
+
:color => "\e[32m",
|
|
39
|
+
:comment => {
|
|
40
|
+
:self => "\e[1;30m",
|
|
41
|
+
:char => "\e[37m",
|
|
42
|
+
:delimiter => "\e[37m",
|
|
43
|
+
},
|
|
44
|
+
:constant => "\e[1;34;4m",
|
|
45
|
+
:decorator => "\e[35m",
|
|
46
|
+
:definition => "\e[1;33m",
|
|
47
|
+
:directive => "\e[33m",
|
|
48
|
+
:docstring => "\e[31m",
|
|
49
|
+
:doctype => "\e[1;34m",
|
|
50
|
+
:done => "\e[1;30;2m",
|
|
51
|
+
:entity => "\e[31m",
|
|
52
|
+
:error => "\e[1;37;41m",
|
|
53
|
+
:exception => "\e[1;31m",
|
|
54
|
+
:float => "\e[1;35m",
|
|
55
|
+
:function => "\e[1;34m",
|
|
56
|
+
:global_variable => "\e[1;32m",
|
|
57
|
+
:hex => "\e[1;36m",
|
|
58
|
+
:id => "\e[1;34m",
|
|
59
|
+
:include => "\e[31m",
|
|
60
|
+
:integer => "\e[1;34m",
|
|
61
|
+
:imaginary => "\e[1;34m",
|
|
62
|
+
:important => "\e[1;31m",
|
|
63
|
+
:key => {
|
|
64
|
+
:self => "\e[35m",
|
|
65
|
+
:char => "\e[1;35m",
|
|
66
|
+
:delimiter => "\e[1;35m",
|
|
67
|
+
},
|
|
68
|
+
:keyword => "\e[32m",
|
|
69
|
+
:label => "\e[1;33m",
|
|
70
|
+
:local_variable => "\e[33m",
|
|
71
|
+
:namespace => "\e[1;35m",
|
|
72
|
+
:octal => "\e[1;34m",
|
|
73
|
+
:predefined => "\e[36m",
|
|
74
|
+
:predefined_constant => "\e[1;36m",
|
|
75
|
+
:predefined_type => "\e[1;32m",
|
|
76
|
+
:preprocessor => "\e[1;36m",
|
|
77
|
+
:pseudo_class => "\e[1;34m",
|
|
78
|
+
:regexp => {
|
|
79
|
+
:self => "\e[35m",
|
|
80
|
+
:delimiter => "\e[1;35m",
|
|
81
|
+
:modifier => "\e[35m",
|
|
82
|
+
:char => "\e[1;35m",
|
|
83
|
+
},
|
|
84
|
+
:reserved => "\e[32m",
|
|
85
|
+
:shell => {
|
|
86
|
+
:self => "\e[33m",
|
|
87
|
+
:char => "\e[1;33m",
|
|
88
|
+
:delimiter => "\e[1;33m",
|
|
89
|
+
:escape => "\e[1;33m",
|
|
90
|
+
},
|
|
91
|
+
:string => {
|
|
92
|
+
:self => "\e[31m",
|
|
93
|
+
:modifier => "\e[1;31m",
|
|
94
|
+
:char => "\e[1;35m",
|
|
95
|
+
:delimiter => "\e[1;31m",
|
|
96
|
+
:escape => "\e[1;31m",
|
|
97
|
+
},
|
|
98
|
+
:symbol => {
|
|
99
|
+
:self => "\e[33m",
|
|
100
|
+
:delimiter => "\e[1;33m",
|
|
101
|
+
},
|
|
102
|
+
:tag => "\e[32m",
|
|
103
|
+
:type => "\e[1;34m",
|
|
104
|
+
:value => "\e[36m",
|
|
105
|
+
:variable => "\e[34m",
|
|
106
|
+
|
|
107
|
+
:insert => {
|
|
108
|
+
:self => "\e[42m",
|
|
109
|
+
:insert => "\e[1;32;42m",
|
|
110
|
+
:eyecatcher => "\e[102m",
|
|
111
|
+
},
|
|
112
|
+
:delete => {
|
|
113
|
+
:self => "\e[41m",
|
|
114
|
+
:delete => "\e[1;31;41m",
|
|
115
|
+
:eyecatcher => "\e[101m",
|
|
116
|
+
},
|
|
117
|
+
:change => {
|
|
118
|
+
:self => "\e[44m",
|
|
119
|
+
:change => "\e[37;44m",
|
|
120
|
+
},
|
|
121
|
+
:head => {
|
|
122
|
+
:self => "\e[45m",
|
|
123
|
+
:filename => "\e[37;45m"
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
TOKEN_COLORS[:keyword] = TOKEN_COLORS[:reserved]
|
|
128
|
+
TOKEN_COLORS[:method] = TOKEN_COLORS[:function]
|
|
129
|
+
TOKEN_COLORS[:escape] = TOKEN_COLORS[:delimiter]
|
|
130
|
+
|
|
131
|
+
protected
|
|
132
|
+
|
|
133
|
+
def setup(options)
|
|
134
|
+
super
|
|
135
|
+
@opened = []
|
|
136
|
+
@color_scopes = [TOKEN_COLORS]
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
public
|
|
140
|
+
|
|
141
|
+
def text_token text, kind
|
|
142
|
+
if color = @color_scopes.last[kind]
|
|
143
|
+
color = color[:self] if color.is_a? Hash
|
|
144
|
+
|
|
145
|
+
@out << color
|
|
146
|
+
@out << (text.index("\n") ? text.gsub("\n", "\e[0m\n" + color) : text)
|
|
147
|
+
@out << "\e[0m"
|
|
148
|
+
if outer_color = @color_scopes.last[:self]
|
|
149
|
+
@out << outer_color
|
|
150
|
+
end
|
|
151
|
+
else
|
|
152
|
+
@out << text
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def begin_group kind
|
|
157
|
+
@opened << kind
|
|
158
|
+
@out << open_token(kind)
|
|
159
|
+
end
|
|
160
|
+
alias begin_line begin_group
|
|
161
|
+
|
|
162
|
+
def end_group kind
|
|
163
|
+
if @opened.pop
|
|
164
|
+
@color_scopes.pop
|
|
165
|
+
@out << "\e[0m"
|
|
166
|
+
if outer_color = @color_scopes.last[:self]
|
|
167
|
+
@out << outer_color
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def end_line kind
|
|
173
|
+
@out << (@line_filler ||= "\t" * 100)
|
|
174
|
+
end_group kind
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
private
|
|
178
|
+
|
|
179
|
+
def open_token kind
|
|
180
|
+
if color = @color_scopes.last[kind]
|
|
181
|
+
if color.is_a? Hash
|
|
182
|
+
@color_scopes << color
|
|
183
|
+
color[:self]
|
|
184
|
+
else
|
|
185
|
+
@color_scopes << @color_scopes.last
|
|
186
|
+
color
|
|
187
|
+
end
|
|
188
|
+
else
|
|
189
|
+
@color_scopes << @color_scopes.last
|
|
190
|
+
''
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Encoders
|
|
3
|
+
|
|
4
|
+
# Concats the tokens into a single string, resulting in the original
|
|
5
|
+
# code string if no tokens were removed.
|
|
6
|
+
#
|
|
7
|
+
# Alias: +plain+, +plaintext+
|
|
8
|
+
#
|
|
9
|
+
# == Options
|
|
10
|
+
#
|
|
11
|
+
# === :separator
|
|
12
|
+
# A separator string to join the tokens.
|
|
13
|
+
#
|
|
14
|
+
# Default: empty String
|
|
15
|
+
class Text < Encoder
|
|
16
|
+
|
|
17
|
+
register_for :text
|
|
18
|
+
|
|
19
|
+
FILE_EXTENSION = 'txt'
|
|
20
|
+
|
|
21
|
+
DEFAULT_OPTIONS = {
|
|
22
|
+
:separator => nil
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def text_token text, kind
|
|
26
|
+
super
|
|
27
|
+
|
|
28
|
+
if @first
|
|
29
|
+
@first = false
|
|
30
|
+
else
|
|
31
|
+
@out << @sep
|
|
32
|
+
end if @sep
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
protected
|
|
36
|
+
def setup options
|
|
37
|
+
super
|
|
38
|
+
|
|
39
|
+
@first = true
|
|
40
|
+
@sep = options[:separator]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Encoders
|
|
3
|
+
|
|
4
|
+
load :filter
|
|
5
|
+
|
|
6
|
+
# A Filter that selects tokens based on their token kind.
|
|
7
|
+
#
|
|
8
|
+
# == Options
|
|
9
|
+
#
|
|
10
|
+
# === :exclude
|
|
11
|
+
#
|
|
12
|
+
# One or many symbols (in an Array) which shall be excluded.
|
|
13
|
+
#
|
|
14
|
+
# Default: []
|
|
15
|
+
#
|
|
16
|
+
# === :include
|
|
17
|
+
#
|
|
18
|
+
# One or many symbols (in an array) which shall be included.
|
|
19
|
+
#
|
|
20
|
+
# Default: :all, which means all tokens are included.
|
|
21
|
+
#
|
|
22
|
+
# Exclusion wins over inclusion.
|
|
23
|
+
#
|
|
24
|
+
# See also: CommentFilter
|
|
25
|
+
class TokenKindFilter < Filter
|
|
26
|
+
|
|
27
|
+
register_for :token_kind_filter
|
|
28
|
+
|
|
29
|
+
DEFAULT_OPTIONS = {
|
|
30
|
+
:exclude => [],
|
|
31
|
+
:include => :all
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected
|
|
35
|
+
def setup options
|
|
36
|
+
super
|
|
37
|
+
|
|
38
|
+
@group_excluded = false
|
|
39
|
+
@exclude = options[:exclude]
|
|
40
|
+
@exclude = Array(@exclude) unless @exclude == :all
|
|
41
|
+
@include = options[:include]
|
|
42
|
+
@include = Array(@include) unless @include == :all
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def include_text_token? text, kind
|
|
46
|
+
include_group? kind
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def include_group? kind
|
|
50
|
+
(@include == :all || @include.include?(kind)) &&
|
|
51
|
+
!(@exclude == :all || @exclude.include?(kind))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
public
|
|
55
|
+
|
|
56
|
+
# Add the token to the output stream if +kind+ matches the conditions.
|
|
57
|
+
def text_token text, kind
|
|
58
|
+
super if !@group_excluded && include_text_token?(text, kind)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Add the token group to the output stream if +kind+ matches the
|
|
62
|
+
# conditions.
|
|
63
|
+
#
|
|
64
|
+
# If it does not, all tokens inside the group are excluded from the
|
|
65
|
+
# stream, even if their kinds match.
|
|
66
|
+
def begin_group kind
|
|
67
|
+
if @group_excluded
|
|
68
|
+
@group_excluded += 1
|
|
69
|
+
elsif include_group? kind
|
|
70
|
+
super
|
|
71
|
+
else
|
|
72
|
+
@group_excluded = 1
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# See +begin_group+.
|
|
77
|
+
def begin_line kind
|
|
78
|
+
if @group_excluded
|
|
79
|
+
@group_excluded += 1
|
|
80
|
+
elsif include_group? kind
|
|
81
|
+
super
|
|
82
|
+
else
|
|
83
|
+
@group_excluded = 1
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Take care of re-enabling the delegation of tokens to the output stream
|
|
88
|
+
# if an exluded group has ended.
|
|
89
|
+
def end_group kind
|
|
90
|
+
if @group_excluded
|
|
91
|
+
@group_excluded -= 1
|
|
92
|
+
@group_excluded = false if @group_excluded.zero?
|
|
93
|
+
else
|
|
94
|
+
super
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# See +end_group+.
|
|
99
|
+
def end_line kind
|
|
100
|
+
if @group_excluded
|
|
101
|
+
@group_excluded -= 1
|
|
102
|
+
@group_excluded = false if @group_excluded.zero?
|
|
103
|
+
else
|
|
104
|
+
super
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Encoders
|
|
3
|
+
|
|
4
|
+
# = XML Encoder
|
|
5
|
+
#
|
|
6
|
+
# Uses REXML. Very slow.
|
|
7
|
+
class XML < Encoder
|
|
8
|
+
|
|
9
|
+
register_for :xml
|
|
10
|
+
|
|
11
|
+
FILE_EXTENSION = 'xml'
|
|
12
|
+
|
|
13
|
+
autoload :REXML, 'rexml/document'
|
|
14
|
+
|
|
15
|
+
DEFAULT_OPTIONS = {
|
|
16
|
+
:tab_width => 8,
|
|
17
|
+
:pretty => -1,
|
|
18
|
+
:transitive => false,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
def setup options
|
|
23
|
+
super
|
|
24
|
+
|
|
25
|
+
@doc = REXML::Document.new
|
|
26
|
+
@doc << REXML::XMLDecl.new
|
|
27
|
+
@tab_width = options[:tab_width]
|
|
28
|
+
@root = @node = @doc.add_element('coderay-tokens')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def finish options
|
|
32
|
+
@doc.write @out, options[:pretty], options[:transitive], true
|
|
33
|
+
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
public
|
|
38
|
+
def text_token text, kind
|
|
39
|
+
if kind == :space
|
|
40
|
+
token = @node
|
|
41
|
+
else
|
|
42
|
+
token = @node.add_element kind.to_s
|
|
43
|
+
end
|
|
44
|
+
text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl|
|
|
45
|
+
case
|
|
46
|
+
when space
|
|
47
|
+
token << REXML::Text.new(space, true)
|
|
48
|
+
when tab
|
|
49
|
+
token << REXML::Text.new(tab, true)
|
|
50
|
+
when nl
|
|
51
|
+
token << REXML::Text.new(nl, true)
|
|
52
|
+
else
|
|
53
|
+
token << REXML::Text.new($&)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def begin_group kind
|
|
59
|
+
@node = @node.add_element kind.to_s
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def end_group kind
|
|
63
|
+
if @node == @root
|
|
64
|
+
raise 'no token to close!'
|
|
65
|
+
end
|
|
66
|
+
@node = @node.parent
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
autoload :YAML, 'yaml'
|
|
2
|
+
|
|
3
|
+
module CodeRay
|
|
4
|
+
module Encoders
|
|
5
|
+
|
|
6
|
+
# = YAML Encoder
|
|
7
|
+
#
|
|
8
|
+
# Slow.
|
|
9
|
+
class YAML < Encoder
|
|
10
|
+
|
|
11
|
+
register_for :yaml
|
|
12
|
+
|
|
13
|
+
FILE_EXTENSION = 'yaml'
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
def setup options
|
|
17
|
+
super
|
|
18
|
+
|
|
19
|
+
@data = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def finish options
|
|
23
|
+
output ::YAML.dump(@data)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
public
|
|
27
|
+
def text_token text, kind
|
|
28
|
+
@data << [text, kind]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def begin_group kind
|
|
32
|
+
@data << [:begin_group, kind]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def end_group kind
|
|
36
|
+
@data << [:end_group, kind]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def begin_line kind
|
|
40
|
+
@data << [:begin_line, kind]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def end_line kind
|
|
44
|
+
@data << [:end_line, kind]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
|
|
3
|
+
# This module holds the Encoder class and its subclasses.
|
|
4
|
+
# For example, the HTML encoder is named CodeRay::Encoders::HTML
|
|
5
|
+
# can be found in coderay/encoders/html.
|
|
6
|
+
#
|
|
7
|
+
# Encoders also provides methods and constants for the register
|
|
8
|
+
# mechanism and the [] method that returns the Encoder class
|
|
9
|
+
# belonging to the given format.
|
|
10
|
+
module Encoders
|
|
11
|
+
|
|
12
|
+
extend PluginHost
|
|
13
|
+
plugin_path File.dirname(__FILE__), 'encoders'
|
|
14
|
+
|
|
15
|
+
autoload :Encoder, CodeRay.coderay_path('encoders', 'encoder')
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
|
|
3
|
+
# A little hack to enable CodeRay highlighting in RedCloth.
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# require 'coderay'
|
|
7
|
+
# require 'coderay/for_redcloth'
|
|
8
|
+
# RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
|
|
9
|
+
#
|
|
10
|
+
# Make sure you have RedCloth 4.0.3 activated, for example by calling
|
|
11
|
+
# require 'rubygems'
|
|
12
|
+
# before RedCloth is loaded and before calling CodeRay.for_redcloth.
|
|
13
|
+
module ForRedCloth
|
|
14
|
+
|
|
15
|
+
def self.install
|
|
16
|
+
gem 'RedCloth', '>= 4.0.3' if defined? gem
|
|
17
|
+
require 'redcloth'
|
|
18
|
+
unless RedCloth::VERSION.to_s >= '4.0.3'
|
|
19
|
+
if defined? gem
|
|
20
|
+
raise 'CodeRay.for_redcloth needs RedCloth version 4.0.3 or later. ' +
|
|
21
|
+
"You have #{RedCloth::VERSION}. Please gem install RedCloth."
|
|
22
|
+
else
|
|
23
|
+
$".delete 'redcloth.rb' # sorry, but it works
|
|
24
|
+
require 'rubygems'
|
|
25
|
+
return install # retry
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
unless RedCloth::VERSION.to_s >= '4.2.2'
|
|
29
|
+
warn 'CodeRay.for_redcloth works best with RedCloth version 4.2.2 or later.'
|
|
30
|
+
end
|
|
31
|
+
RedCloth::TextileDoc.send :include, ForRedCloth::TextileDoc
|
|
32
|
+
RedCloth::Formatters::HTML.module_eval do
|
|
33
|
+
def unescape(html) # :nodoc:
|
|
34
|
+
replacements = {
|
|
35
|
+
'&' => '&',
|
|
36
|
+
'"' => '"',
|
|
37
|
+
'>' => '>',
|
|
38
|
+
'<' => '<',
|
|
39
|
+
}
|
|
40
|
+
html.gsub(/&(?:amp|quot|[gl]t);/) { |entity| replacements[entity] }
|
|
41
|
+
end
|
|
42
|
+
undef code, bc_open, bc_close, escape_pre
|
|
43
|
+
def code(opts) # :nodoc:
|
|
44
|
+
opts[:block] = true
|
|
45
|
+
if !opts[:lang] && RedCloth::VERSION.to_s >= '4.2.0'
|
|
46
|
+
# simulating pre-4.2 behavior
|
|
47
|
+
if opts[:text].sub!(/\A\[(\w+)\]/, '')
|
|
48
|
+
if CodeRay::Scanners[$1].lang == :text
|
|
49
|
+
opts[:text] = $& + opts[:text]
|
|
50
|
+
else
|
|
51
|
+
opts[:lang] = $1
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
if opts[:lang] && !filter_coderay
|
|
56
|
+
require 'coderay'
|
|
57
|
+
@in_bc ||= nil
|
|
58
|
+
format = @in_bc ? :div : :span
|
|
59
|
+
opts[:text] = unescape(opts[:text]) unless @in_bc
|
|
60
|
+
highlighted_code = CodeRay.encode opts[:text], opts[:lang], format
|
|
61
|
+
highlighted_code.sub!(/\A<(span|div)/) { |m| m + pba(@in_bc || opts) }
|
|
62
|
+
highlighted_code
|
|
63
|
+
else
|
|
64
|
+
"<code#{pba(opts)}>#{opts[:text]}</code>"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
def bc_open(opts) # :nodoc:
|
|
68
|
+
opts[:block] = true
|
|
69
|
+
@in_bc = opts
|
|
70
|
+
opts[:lang] ? '' : "<pre#{pba(opts)}>"
|
|
71
|
+
end
|
|
72
|
+
def bc_close(opts) # :nodoc:
|
|
73
|
+
opts = @in_bc
|
|
74
|
+
@in_bc = nil
|
|
75
|
+
opts[:lang] ? '' : "</pre>\n"
|
|
76
|
+
end
|
|
77
|
+
def escape_pre(text) # :nodoc:
|
|
78
|
+
if @in_bc ||= nil
|
|
79
|
+
text
|
|
80
|
+
else
|
|
81
|
+
html_esc(text, :html_escape_preformatted)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
module TextileDoc # :nodoc:
|
|
88
|
+
attr_accessor :filter_coderay
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
CodeRay::ForRedCloth.install
|