coderay 0.5.0.121 → 0.7.1.147

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/FOLDERS +53 -0
  2. data/README +21 -13
  3. data/bin/coderay +79 -0
  4. data/demo/demo_cache.rb +12 -0
  5. data/demo/demo_html_list.rb +12 -0
  6. data/lib/coderay.rb +11 -2
  7. data/lib/coderay/duo.rb +29 -0
  8. data/lib/coderay/encoder.rb +4 -4
  9. data/lib/coderay/encoders/_map.rb +6 -6
  10. data/lib/coderay/encoders/count.rb +3 -3
  11. data/lib/coderay/encoders/debug.rb +38 -30
  12. data/lib/coderay/encoders/div.rb +4 -2
  13. data/lib/coderay/encoders/html.rb +9 -19
  14. data/lib/coderay/encoders/html/classes.rb +5 -2
  15. data/lib/coderay/encoders/html/css.rb +5 -6
  16. data/lib/coderay/encoders/html/numerization.rb +28 -18
  17. data/lib/coderay/encoders/html/output.rb +4 -4
  18. data/lib/coderay/encoders/null.rb +16 -16
  19. data/lib/coderay/encoders/page.rb +21 -0
  20. data/lib/coderay/encoders/span.rb +6 -3
  21. data/lib/coderay/encoders/statistic.rb +4 -2
  22. data/lib/coderay/encoders/tokens.rb +35 -35
  23. data/lib/coderay/encoders/xml.rb +53 -52
  24. data/lib/coderay/encoders/yaml.rb +13 -10
  25. data/lib/coderay/helpers/filetype.rb +41 -5
  26. data/lib/coderay/helpers/gzip_simple.rb +1 -1
  27. data/lib/coderay/helpers/plugin.rb +33 -17
  28. data/lib/coderay/scanner.rb +60 -19
  29. data/lib/coderay/scanners/_map.rb +12 -8
  30. data/lib/coderay/scanners/c.rb +16 -8
  31. data/lib/coderay/scanners/delphi.rb +9 -3
  32. data/lib/coderay/scanners/html.rb +167 -0
  33. data/lib/coderay/scanners/nitro_html.rb +125 -0
  34. data/lib/coderay/scanners/plaintext.rb +4 -2
  35. data/lib/coderay/scanners/rhtml.rb +65 -0
  36. data/lib/coderay/scanners/ruby.rb +51 -39
  37. data/lib/coderay/scanners/ruby/patterns.rb +12 -9
  38. data/lib/coderay/scanners/xml.rb +18 -0
  39. data/lib/coderay/scanners/yaml.rb +85 -0
  40. data/lib/coderay/styles/_map.rb +7 -0
  41. data/lib/coderay/styles/cycnus.rb +105 -99
  42. data/lib/coderay/styles/murphy.rb +18 -18
  43. metadata +19 -6
@@ -1,6 +1,7 @@
1
- module CodeRay module Scanners
1
+ module CodeRay
2
+ module Scanners
2
3
 
3
- class Ruby
4
+ module Ruby::Patterns # :nodoc:
4
5
 
5
6
  RESERVED_WORDS = %w[
6
7
  and def end in or unless begin
@@ -46,7 +47,7 @@ module CodeRay module Scanners
46
47
  | <=?>? | >=? # comparison, rocket operator
47
48
  | ===? # simple equality and case equality
48
49
  /ox
49
- METHOD_NAME_EX = / #{IDENT} [?!=]? | #{METHOD_NAME_OPERATOR} /ox
50
+ METHOD_NAME_EX = / #{IDENT} (?:[?!]|=(?!>))? | #{METHOD_NAME_OPERATOR} /ox
50
51
  INSTANCE_VARIABLE = / @ #{IDENT} /ox
51
52
  CLASS_VARIABLE = / @@ #{IDENT} /ox
52
53
  OBJECT_VARIABLE = / @@? #{IDENT} /ox
@@ -130,16 +131,17 @@ module CodeRay module Scanners
130
131
 
131
132
  RDOC_DATA_START = / ^=begin (?!\S) | ^__END__$ /x
132
133
 
133
- FANCY_START = / % ( [qQwWxsr] | (?![\w\s=]) ) (.) /mox
134
+ # FIXME: \s and = are only a workaround, they are still allowed
135
+ # as delimiters.
136
+ FANCY_START_SAVE = / % ( [qQwWxsr] | (?![a-zA-Z0-9\s=]) ) ([^a-zA-Z0-9]) /mx
137
+ FANCY_START_CORRECT = / % ( [qQwWxsr] | (?![a-zA-Z0-9]) ) ([^a-zA-Z0-9]) /mx
134
138
 
135
139
  FancyStringType = {
136
140
  'q' => [:string, false],
137
141
  'Q' => [:string, true],
138
142
  'r' => [:regexp, true],
139
143
  's' => [:symbol, false],
140
- 'x' => [:shell, true],
141
- 'w' => [:string, :word],
142
- 'W' => [:string, :word],
144
+ 'x' => [:shell, true]
143
145
  }
144
146
  FancyStringType['w'] = FancyStringType['q']
145
147
  FancyStringType['W'] = FancyStringType[''] = FancyStringType['Q']
@@ -207,7 +209,8 @@ module CodeRay module Scanners
207
209
  super kind, interpreted, delim, heredoc, paren, paren_depth, pattern, :initial
208
210
  end
209
211
  end unless defined? StringState
210
-
212
+
211
213
  end
212
214
 
213
- end end
215
+ end
216
+ end
@@ -0,0 +1,18 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ load :html
5
+
6
+ # XML Scanner
7
+ #
8
+ # $Id$
9
+ #
10
+ # Currently this is the same scanner as Scanners::HTML.
11
+ class XML < HTML
12
+
13
+ register_for :xml
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,85 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ # YAML Scanner
5
+ #
6
+ # $Id$
7
+ #
8
+ # See http://yaml.org for information about YAML.
9
+ class YAML < Scanner
10
+
11
+ include Streamable
12
+ register_for :yaml
13
+
14
+ private
15
+ def setup
16
+ @state = :initial
17
+ end
18
+
19
+ def scan_tokens tokens, options
20
+
21
+ state = @state
22
+ start_of_line = true
23
+
24
+ until eos?
25
+
26
+ kind = :error
27
+ match = nil
28
+
29
+ if match = scan(/\s+/m)
30
+ if match.index ?\n # contains newline
31
+ start_of_line = true
32
+ end
33
+ kind = :space
34
+
35
+ else
36
+
37
+ case state
38
+
39
+ when :initial
40
+ if bol? and scan(/---(\s*.+)/m)
41
+ kind = :preprocessor
42
+ else
43
+ raise_inspect '[BUG] else-case reached with state %p' % [state], tokens
44
+ end
45
+
46
+ when :attribute
47
+ if scan(/#{TAG_END}/)
48
+ kind = :tag
49
+ state = :initial
50
+ elsif scan(/#{ATTR_NAME}/o)
51
+ kind = :attribute_name
52
+ state = :attribute_equal
53
+ else
54
+ getch
55
+ end
56
+
57
+ else
58
+ raise_inspect 'Unknown state: %p' % [state], tokens
59
+
60
+ end
61
+
62
+ start_of_line = false
63
+ end
64
+
65
+ match ||= matched
66
+ if $DEBUG and (not kind or kind == :error)
67
+ raise_inspect 'Error token %p in line %d' %
68
+ [[match, kind], line], tokens
69
+ end
70
+ raise_inspect 'Empty token', tokens unless match
71
+
72
+ tokens << [match, kind]
73
+ end
74
+
75
+ if options[:keep_state]
76
+ @state = state
77
+ end
78
+
79
+ tokens
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,7 @@
1
+ module CodeRay
2
+ module Styles
3
+
4
+ default :cycnus
5
+
6
+ end
7
+ end
@@ -1,119 +1,125 @@
1
1
  module CodeRay
2
- module Styles
3
-
4
- class CYcnus < Style
5
-
6
- register_for :cycnus
7
-
8
- code_background = '#f8f8f8'
9
- numbers_background = '#def'
10
- border_color = 'silver'
11
- normal_color = '#100'
12
-
13
- CSS_MAIN_STYLES = <<-MAIN
2
+ module Styles
3
+
4
+ class Cycnus < Style
5
+
6
+ register_for :cycnus
7
+
8
+ code_background = '#f8f8f8'
9
+ numbers_background = '#def'
10
+ border_color = 'silver'
11
+ normal_color = '#100'
12
+
13
+ CSS_MAIN_STYLES = <<-MAIN
14
14
  .CodeRay {
15
15
  background-color: #{code_background};
16
16
  border: 1px solid #{border_color};
17
17
  font-family: 'Courier New', 'Terminal', monospace;
18
18
  color: #{normal_color};
19
19
  }
20
- .CodeRay pre { margin: 0px; }
20
+ .CodeRay pre { margin: 0px }
21
21
 
22
22
  div.CodeRay { }
23
23
 
24
- span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
24
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px }
25
25
 
26
- table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
27
- table.CodeRay td { padding: 2px 4px; vertical-align: top; }
26
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
27
+ table.CodeRay td { padding: 2px 4px; vertical-align: top }
28
28
 
29
29
  .CodeRay .line_numbers, .CodeRay .no {
30
30
  background-color: #{numbers_background};
31
31
  color: gray;
32
32
  text-align: right;
33
33
  }
34
- .CodeRay .line_numbers tt { font-weight: bold; }
35
- .CodeRay .no { padding: 0px 4px; }
36
- .CodeRay .code { width: 100%; }
37
-
38
- ol.CodeRay { font-size: 10pt; }
39
- ol.CodeRay li { white-space: pre; }
40
-
41
- .CodeRay .code pre { overflow: auto; }
42
- MAIN
43
-
44
- TOKEN_COLORS = <<-'TOKENS'
45
- .af { color:#00C; }
46
- .an { color:#007; }
47
- .av { color:#700; }
48
- .aw { color:#C00; }
49
- .bi { color:#509; font-weight:bold; }
50
- .c { color:#888; }
51
-
52
- .ch { color:#04D; }
53
- .ch .k { color:#04D; }
54
- .ch .dl { color:#039; }
55
-
56
- .cl { color:#B06; font-weight:bold; }
57
- .co { color:#036; font-weight:bold; }
58
- .cr { color:#0A0; }
59
- .cv { color:#369; }
60
- .df { color:#099; font-weight:bold; }
61
- .di { color:#088; font-weight:bold; }
62
- .dl { color:black; }
63
- .do { color:#970; }
64
- .ds { color:#D42; font-weight:bold; }
65
- .e { color:#666; font-weight:bold; }
66
- .er { color:#F00; background-color:#FAA; }
67
- .ex { color:#F00; font-weight:bold; }
68
- .fl { color:#60E; font-weight:bold; }
69
- .fu { color:#06B; font-weight:bold; }
70
- .gv { color:#d70; font-weight:bold; }
71
- .hx { color:#058; font-weight:bold; }
72
- .i { color:#00D; font-weight:bold; }
73
- .ic { color:#B44; font-weight:bold; }
74
- .il { }
75
- .in { color:#B2B; font-weight:bold; }
76
- .iv { color:#33B; }
77
- .la { color:#970; font-weight:bold; }
78
- .lv { color:#963; }
79
- .oc { color:#40E; font-weight:bold; }
80
- .on { color:#000; font-weight:bold; }
34
+ .CodeRay .line_numbers tt { font-weight: bold }
35
+ .CodeRay .no { padding: 0px 4px }
36
+ .CodeRay .code { width: 100% }
37
+
38
+ ol.CodeRay { font-size: 10pt }
39
+ ol.CodeRay li { white-space: pre }
40
+
41
+ .CodeRay .code pre { overflow: auto }
42
+ MAIN
43
+
44
+ TOKEN_COLORS = <<-'TOKENS'
45
+ .af { color:#00C }
46
+ .an { color:#007 }
47
+ .av { color:#700 }
48
+ .aw { color:#C00 }
49
+ .bi { color:#509; font-weight:bold }
50
+ .c { color:#888 }
51
+
52
+ .ch { color:#04D }
53
+ .ch .k { color:#04D }
54
+ .ch .dl { color:#039 }
55
+
56
+ .cl { color:#B06; font-weight:bold }
57
+ .co { color:#036; font-weight:bold }
58
+ .cr { color:#0A0 }
59
+ .cv { color:#369 }
60
+ .df { color:#099; font-weight:bold }
61
+ .di { color:#088; font-weight:bold }
62
+ .dl { color:black }
63
+ .do { color:#970 }
64
+ .ds { color:#D42; font-weight:bold }
65
+ .e { color:#666; font-weight:bold }
66
+ .en { color:#800; font-weight:bold }
67
+ .er { color:#F00; background-color:#FAA }
68
+ .ex { color:#F00; font-weight:bold }
69
+ .fl { color:#60E; font-weight:bold }
70
+ .fu { color:#06B; font-weight:bold }
71
+ .gv { color:#d70; font-weight:bold }
72
+ .hx { color:#058; font-weight:bold }
73
+ .i { color:#00D; font-weight:bold }
74
+ .ic { color:#B44; font-weight:bold }
75
+
76
+ .il { background: #eee }
77
+ .il .il { background: #ddd }
78
+ .il .il .il { background: #ccc }
79
+ .il .dl { font-weight: bold ! important; color: #888 ! important }
80
+
81
+ .in { color:#B2B; font-weight:bold }
82
+ .iv { color:#33B }
83
+ .la { color:#970; font-weight:bold }
84
+ .lv { color:#963 }
85
+ .oc { color:#40E; font-weight:bold }
86
+ .on { color:#000; font-weight:bold }
81
87
  .op { }
82
- .pc { color:#038; font-weight:bold; }
83
- .pd { color:#369; font-weight:bold; }
84
- .pp { color:#579; }
85
- .pt { color:#339; font-weight:bold; }
86
- .r { color:#080; font-weight:bold; }
87
-
88
- .rx { background-color:#fff0ff; }
89
- .rx .k { color:#808; }
90
- .rx .dl { color:#404; }
91
- .rx .mod { color:#C2C; }
92
- .rx .fu { color:#404; font-weight: bold; }
93
-
94
- .s { background-color:#fff0f0; }
95
- .s .s { background-color:#ffe0e0; }
96
- .s .s .s { background-color:#ffd0d0; }
97
- .s .k { color:#D20; }
98
- .s .dl { color:#710; }
99
-
100
- .sh { background-color:#f0fff0; }
101
- .sh .k { color:#2B2; }
102
- .sh .dl { color:#161; }
103
-
104
- .sy { color:#A60; }
105
- .sy .k { color:#A60; }
106
- .sy .dl { color:#630; }
107
-
108
- .ta { color:#070; }
109
- .tf { color:#070; font-weight:bold; }
110
- .ts { color:#D70; font-weight:bold; }
111
- .ty { color:#339; font-weight:bold; }
112
- .v { color:#036; }
113
- .xt { color:#444; }
114
- TOKENS
115
-
116
- end
117
-
88
+ .pc { color:#038; font-weight:bold }
89
+ .pd { color:#369; font-weight:bold }
90
+ .pp { color:#579 }
91
+ .pt { color:#339; font-weight:bold }
92
+ .r { color:#080; font-weight:bold }
93
+
94
+ .rx { background-color:#fff0ff }
95
+ .rx .k { color:#808 }
96
+ .rx .dl { color:#404 }
97
+ .rx .mod { color:#C2C }
98
+ .rx .fu { color:#404; font-weight: bold }
99
+
100
+ .s { background-color:#fff0f0 }
101
+ .s .s { background-color:#ffe0e0 }
102
+ .s .s .s { background-color:#ffd0d0 }
103
+ .s .k { color:#D20 }
104
+ .s .dl { color:#710 }
105
+
106
+ .sh { background-color:#f0fff0 }
107
+ .sh .k { color:#2B2 }
108
+ .sh .dl { color:#161 }
109
+
110
+ .sy { color:#A60 }
111
+ .sy .k { color:#A60 }
112
+ .sy .dl { color:#630 }
113
+
114
+ .ta { color:#070 }
115
+ .tf { color:#070; font-weight:bold }
116
+ .ts { color:#D70; font-weight:bold }
117
+ .ty { color:#339; font-weight:bold }
118
+ .v { color:#036 }
119
+ .xt { color:#444 }
120
+ TOKENS
121
+
118
122
  end
123
+
124
+ end
119
125
  end
@@ -1,16 +1,16 @@
1
1
  module CodeRay
2
- module Styles
3
-
4
- class Murphy < Style
5
-
6
- register_for :murphy
7
-
8
- code_background = '#001129'
9
- numbers_background = code_background
10
- border_color = 'silver'
11
- normal_color = '#C0C0C0'
12
-
13
- CSS_MAIN_STYLES = <<-MAIN
2
+ module Styles
3
+
4
+ class Murphy < Style
5
+
6
+ register_for :murphy
7
+
8
+ code_background = '#001129'
9
+ numbers_background = code_background
10
+ border_color = 'silver'
11
+ normal_color = '#C0C0C0'
12
+
13
+ CSS_MAIN_STYLES = <<-MAIN
14
14
  .CodeRay {
15
15
  background-color: #{code_background};
16
16
  border: 1px solid #{border_color};
@@ -39,9 +39,9 @@ ol.CodeRay { font-size: 10pt; }
39
39
  ol.CodeRay li { white-space: pre; }
40
40
 
41
41
  .CodeRay .code pre { overflow: auto; }
42
- MAIN
42
+ MAIN
43
43
 
44
- TOKEN_COLORS = <<-'TOKENS'
44
+ TOKEN_COLORS = <<-'TOKENS'
45
45
  .af { color:#00C; }
46
46
  .an { color:#007; }
47
47
  .av { color:#700; }
@@ -111,9 +111,9 @@ ol.CodeRay li { white-space: pre; }
111
111
  .ty { color:#339; font-weight:bold; }
112
112
  .v { color:#036; }
113
113
  .xt { color:#444; }
114
- TOKENS
115
-
116
- end
117
-
114
+ TOKENS
115
+
118
116
  end
117
+
118
+ end
119
119
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: coderay
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.0.121
7
- date: 2006-03-16 00:00:00 +01:00
6
+ version: 0.7.1.147
7
+ date: 2006-07-05 00:00:00 +02:00
8
8
  summary: CodeRay is a fast syntax highlighter engine for many languages.
9
9
  require_paths:
10
10
  - lib
11
11
  email: murphy@cYcnus.de
12
- homepage: http://rd.cycnus.de/coderay
12
+ homepage: http://coderay.rubychan.de
13
13
  rubyforge_project: coderay
14
14
  description: "CodeRay is a Ruby library for syntax highlighting. I try to make CodeRay easy to use and intuitive, but at the same time fully featured, complete, fast and efficient. Usage is simple: require 'coderay' code = 'some %q(weird (Ruby) can't shock) me!' puts CodeRay.scan(code, :ruby).html"
15
15
  autorequire: coderay
@@ -25,10 +25,12 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - murphy
30
31
  files:
31
32
  - ./lib/coderay.rb
33
+ - ./lib/coderay/duo.rb
32
34
  - ./lib/coderay/encoder.rb
33
35
  - ./lib/coderay/scanner.rb
34
36
  - ./lib/coderay/style.rb
@@ -38,6 +40,7 @@ files:
38
40
  - ./lib/coderay/encoders/div.rb
39
41
  - ./lib/coderay/encoders/html.rb
40
42
  - ./lib/coderay/encoders/null.rb
43
+ - ./lib/coderay/encoders/page.rb
41
44
  - ./lib/coderay/encoders/span.rb
42
45
  - ./lib/coderay/encoders/statistic.rb
43
46
  - ./lib/coderay/encoders/text.rb
@@ -55,12 +58,19 @@ files:
55
58
  - ./lib/coderay/helpers/word_list.rb
56
59
  - ./lib/coderay/scanners/c.rb
57
60
  - ./lib/coderay/scanners/delphi.rb
61
+ - ./lib/coderay/scanners/html.rb
62
+ - ./lib/coderay/scanners/nitro_html.rb
58
63
  - ./lib/coderay/scanners/plaintext.rb
64
+ - ./lib/coderay/scanners/rhtml.rb
59
65
  - ./lib/coderay/scanners/ruby.rb
66
+ - ./lib/coderay/scanners/xml.rb
67
+ - ./lib/coderay/scanners/yaml.rb
60
68
  - ./lib/coderay/scanners/_map.rb
61
69
  - ./lib/coderay/scanners/ruby/patterns.rb
62
70
  - ./lib/coderay/styles/cycnus.rb
63
71
  - ./lib/coderay/styles/murphy.rb
72
+ - ./lib/coderay/styles/_map.rb
73
+ - ./demo/demo_cache.rb
64
74
  - ./demo/demo_count.rb
65
75
  - ./demo/demo_css.rb
66
76
  - ./demo/demo_div.rb
@@ -71,6 +81,7 @@ files:
71
81
  - ./demo/demo_highlight.rb
72
82
  - ./demo/demo_html.rb
73
83
  - ./demo/demo_html2.rb
84
+ - ./demo/demo_html_list.rb
74
85
  - ./demo/demo_load_encoder.rb
75
86
  - ./demo/demo_load_scanner.rb
76
87
  - ./demo/demo_more.rb
@@ -83,6 +94,7 @@ files:
83
94
  - ./demo/suite.rb
84
95
  - ./README
85
96
  - ./LICENSE
97
+ - ./FOLDERS
86
98
  test_files: []
87
99
 
88
100
  rdoc_options:
@@ -92,8 +104,9 @@ rdoc_options:
92
104
  - -t CodeRay Documentation
93
105
  extra_rdoc_files:
94
106
  - ./README
95
- executables: []
96
-
107
+ - ./FOLDERS
108
+ executables:
109
+ - coderay
97
110
  extensions: []
98
111
 
99
112
  requirements: