raldred-coderay 0.9.0 → 0.9.339

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.
Files changed (58) hide show
  1. data/lib/README +128 -0
  2. data/lib/coderay.rb +319 -0
  3. data/lib/coderay/duo.rb +85 -0
  4. data/lib/coderay/encoder.rb +187 -0
  5. data/lib/coderay/encoders/_map.rb +9 -0
  6. data/lib/coderay/encoders/count.rb +21 -0
  7. data/lib/coderay/encoders/debug.rb +49 -0
  8. data/lib/coderay/encoders/div.rb +20 -0
  9. data/lib/coderay/encoders/html.rb +306 -0
  10. data/lib/coderay/encoders/html/css.rb +70 -0
  11. data/lib/coderay/encoders/html/numerization.rb +133 -0
  12. data/lib/coderay/encoders/html/output.rb +206 -0
  13. data/lib/coderay/encoders/json.rb +19 -0
  14. data/lib/coderay/encoders/null.rb +26 -0
  15. data/lib/coderay/encoders/page.rb +21 -0
  16. data/lib/coderay/encoders/span.rb +20 -0
  17. data/lib/coderay/encoders/statistic.rb +77 -0
  18. data/lib/coderay/encoders/term.rb +114 -0
  19. data/lib/coderay/encoders/text.rb +32 -0
  20. data/lib/coderay/encoders/tokens.rb +44 -0
  21. data/lib/coderay/encoders/xml.rb +71 -0
  22. data/lib/coderay/encoders/yaml.rb +22 -0
  23. data/lib/coderay/for_redcloth.rb +73 -0
  24. data/lib/coderay/helpers/file_type.rb +226 -0
  25. data/lib/coderay/helpers/gzip_simple.rb +123 -0
  26. data/lib/coderay/helpers/plugin.rb +339 -0
  27. data/lib/coderay/helpers/word_list.rb +124 -0
  28. data/lib/coderay/scanner.rb +271 -0
  29. data/lib/coderay/scanners/_map.rb +21 -0
  30. data/lib/coderay/scanners/c.rb +166 -0
  31. data/lib/coderay/scanners/css.rb +202 -0
  32. data/lib/coderay/scanners/debug.rb +61 -0
  33. data/lib/coderay/scanners/delphi.rb +150 -0
  34. data/lib/coderay/scanners/diff.rb +104 -0
  35. data/lib/coderay/scanners/groovy.rb +271 -0
  36. data/lib/coderay/scanners/html.rb +175 -0
  37. data/lib/coderay/scanners/java.rb +173 -0
  38. data/lib/coderay/scanners/java/builtin_types.rb +419 -0
  39. data/lib/coderay/scanners/java_script.rb +195 -0
  40. data/lib/coderay/scanners/json.rb +107 -0
  41. data/lib/coderay/scanners/nitro_xhtml.rb +132 -0
  42. data/lib/coderay/scanners/php.rb +404 -0
  43. data/lib/coderay/scanners/plaintext.rb +18 -0
  44. data/lib/coderay/scanners/python.rb +232 -0
  45. data/lib/coderay/scanners/rhtml.rb +71 -0
  46. data/lib/coderay/scanners/ruby.rb +386 -0
  47. data/lib/coderay/scanners/ruby/patterns.rb +232 -0
  48. data/lib/coderay/scanners/scheme.rb +142 -0
  49. data/lib/coderay/scanners/sql.rb +162 -0
  50. data/lib/coderay/scanners/xml.rb +17 -0
  51. data/lib/coderay/scanners/yaml.rb +142 -0
  52. data/lib/coderay/style.rb +20 -0
  53. data/lib/coderay/styles/_map.rb +7 -0
  54. data/lib/coderay/styles/cycnus.rb +151 -0
  55. data/lib/coderay/styles/murphy.rb +132 -0
  56. data/lib/coderay/token_classes.rb +86 -0
  57. data/lib/coderay/tokens.rb +387 -0
  58. metadata +59 -1
@@ -0,0 +1,17 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ load :html
5
+
6
+ # XML Scanner
7
+ #
8
+ # Currently this is the same scanner as Scanners::HTML.
9
+ class XML < HTML
10
+
11
+ register_for :xml
12
+ file_extension 'xml'
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,142 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ # YAML Scanner
5
+ #
6
+ # Based on the YAML scanner from Syntax by Jamis Buck.
7
+ class YAML < Scanner
8
+
9
+ register_for :yaml
10
+ file_extension 'yml'
11
+
12
+ def scan_tokens tokens, options
13
+
14
+ value_expected = nil
15
+ state = :initial
16
+ key_indent = indent = 0
17
+
18
+ until eos?
19
+
20
+ kind = nil
21
+ match = nil
22
+
23
+ if bol?
24
+ key_indent = nil
25
+ if $DEBUG
26
+ indent = check(/ +/) ? matched.size : 0
27
+ tokens << [indent.to_s, :debug]
28
+ end
29
+ end
30
+
31
+ if match = scan(/ +[\t ]*/)
32
+ kind = :space
33
+
34
+ elsif match = scan(/\n+/)
35
+ kind = :space
36
+ state = :initial if match.index(?\n)
37
+
38
+ elsif match = scan(/#.*/)
39
+ kind = :comment
40
+
41
+ elsif bol? and case
42
+ when match = scan(/---|\.\.\./)
43
+ tokens << [:open, :head]
44
+ tokens << [match, :head]
45
+ tokens << [:close, :head]
46
+ next
47
+ when match = scan(/%.*/)
48
+ tokens << [match, :doctype]
49
+ next
50
+ end
51
+
52
+ elsif state == :value and case
53
+ when !check(/(?:"[^"]*")(?=: |:$)/) && scan(/"/)
54
+ tokens << [:open, :string]
55
+ tokens << [matched, :delimiter]
56
+ tokens << [matched, :content] if scan(/ [^"\\]* (?: \\. [^"\\]* )* /mx)
57
+ tokens << [matched, :delimiter] if scan(/"/)
58
+ tokens << [:close, :string]
59
+ next
60
+ when match = scan(/[|>][-+]?/)
61
+ tokens << [:open, :string]
62
+ tokens << [match, :delimiter]
63
+ string_indent = key_indent || column(pos - match.size - 1)
64
+ tokens << [matched, :content] if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
65
+ tokens << [:close, :string]
66
+ next
67
+ when match = scan(/(?![!"*&]).+?(?=$|\s+#)/)
68
+ tokens << [match, :string]
69
+ string_indent = key_indent || column(pos - match.size - 1)
70
+ tokens << [matched, :string] if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
71
+ next
72
+ end
73
+
74
+ elsif case
75
+ when match = scan(/[-:](?= |$)/)
76
+ state = :value if state == :colon && (match == ':' || match == '-')
77
+ state = :value if state == :initial && match == '-'
78
+ kind = :operator
79
+ when match = scan(/[,{}\[\]]/)
80
+ kind = :operator
81
+ when state == :initial && match = scan(/[\w.() ]*\S(?=: |:$)/)
82
+ kind = :key
83
+ key_indent = column(pos - match.size - 1)
84
+ # tokens << [key_indent.inspect, :debug]
85
+ state = :colon
86
+ when match = scan(/(?:"[^"\n]*"|'[^'\n]*')(?=: |:$)/)
87
+ tokens << [:open, :key]
88
+ tokens << [match[0,1], :delimiter]
89
+ tokens << [match[1..-2], :content]
90
+ tokens << [match[-1,1], :delimiter]
91
+ tokens << [:close, :key]
92
+ key_indent = column(pos - match.size - 1)
93
+ # tokens << [key_indent.inspect, :debug]
94
+ state = :colon
95
+ next
96
+ when scan(/(![\w\/]+)(:([\w:]+))?/)
97
+ tokens << [self[1], :type]
98
+ if self[2]
99
+ tokens << [':', :operator]
100
+ tokens << [self[3], :class]
101
+ end
102
+ next
103
+ when scan(/&\S+/)
104
+ kind = :variable
105
+ when scan(/\*\w+/)
106
+ kind = :global_variable
107
+ when scan(/<</)
108
+ kind = :class_variable
109
+ when scan(/\d\d:\d\d:\d\d/)
110
+ kind = :oct
111
+ when scan(/\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d(\.\d+)? [-+]\d\d:\d\d/)
112
+ kind = :oct
113
+ when scan(/:\w+/)
114
+ kind = :symbol
115
+ when scan(/[^:\s]+(:(?! |$)[^:\s]*)* .*/)
116
+ kind = :error
117
+ when scan(/[^:\s]+(:(?! |$)[^:\s]*)*/)
118
+ kind = :error
119
+ end
120
+
121
+ else
122
+ getch
123
+ kind = :error
124
+
125
+ end
126
+
127
+ match ||= matched
128
+
129
+ raise_inspect 'Error token %p in line %d' % [[match, kind], line], tokens if $DEBUG && !kind
130
+ raise_inspect 'Empty token', tokens unless match
131
+
132
+ tokens << [match, kind]
133
+
134
+ end
135
+
136
+ tokens
137
+ end
138
+
139
+ end
140
+
141
+ end
142
+ end
@@ -0,0 +1,20 @@
1
+ module CodeRay
2
+
3
+ # This module holds the Style class and its subclasses.
4
+ #
5
+ # See Plugin.
6
+ module Styles
7
+ extend PluginHost
8
+ plugin_path File.dirname(__FILE__), 'styles'
9
+
10
+ class Style
11
+ extend Plugin
12
+ plugin_host Styles
13
+
14
+ DEFAULT_OPTIONS = { }
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,7 @@
1
+ module CodeRay
2
+ module Styles
3
+
4
+ default :cycnus
5
+
6
+ end
7
+ end
@@ -0,0 +1,151 @@
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 = '#000'
12
+
13
+ CSS_MAIN_STYLES = <<-MAIN
14
+ .CodeRay {
15
+ background-color: #{code_background};
16
+ border: 1px solid #{border_color};
17
+ font-family: 'Courier New', 'Terminal', monospace;
18
+ color: #{normal_color};
19
+ }
20
+ .CodeRay pre { margin: 0px }
21
+
22
+ div.CodeRay { }
23
+
24
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px }
25
+
26
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
27
+ table.CodeRay td { padding: 2px 4px; vertical-align: top }
28
+
29
+ .CodeRay .line_numbers, .CodeRay .no {
30
+ background-color: #{numbers_background};
31
+ color: gray;
32
+ text-align: right;
33
+ }
34
+ .CodeRay .line_numbers tt { font-weight: bold }
35
+ .CodeRay .line_numbers .highlighted { color: red }
36
+ .CodeRay .no { padding: 0px 4px }
37
+ .CodeRay .code { width: 100% }
38
+
39
+ ol.CodeRay { font-size: 10pt }
40
+ ol.CodeRay li { white-space: pre }
41
+
42
+ .CodeRay .code pre { overflow: auto }
43
+ MAIN
44
+
45
+ TOKEN_COLORS = <<-'TOKENS'
46
+ .debug { color:white ! important; background:blue ! important; }
47
+
48
+ .af { color:#00C }
49
+ .an { color:#007 }
50
+ .at { color:#f08 }
51
+ .av { color:#700 }
52
+ .aw { color:#C00 }
53
+ .bi { color:#509; font-weight:bold }
54
+ .c { color:#888; }
55
+
56
+ .ch { color:#04D }
57
+ .ch .k { color:#04D }
58
+ .ch .dl { color:#039 }
59
+
60
+ .cl { color:#B06; font-weight:bold }
61
+ .cm { color:#A08; font-weight:bold }
62
+ .co { color:#036; font-weight:bold }
63
+ .cr { color:#0A0 }
64
+ .cv { color:#369 }
65
+ .de { color:#B0B; }
66
+ .df { color:#099; font-weight:bold }
67
+ .di { color:#088; font-weight:bold }
68
+ .dl { color:black }
69
+ .do { color:#970 }
70
+ .dt { color:#34b }
71
+ .ds { color:#D42; font-weight:bold }
72
+ .e { color:#666; font-weight:bold }
73
+ .en { color:#800; font-weight:bold }
74
+ .er { color:#F00; background-color:#FAA }
75
+ .ex { color:#F00; font-weight:bold }
76
+ .fl { color:#60E; font-weight:bold }
77
+ .fu { color:#06B; font-weight:bold }
78
+ .gv { color:#d70; font-weight:bold }
79
+ .hx { color:#058; font-weight:bold }
80
+ .i { color:#00D; font-weight:bold }
81
+ .ic { color:#B44; font-weight:bold }
82
+
83
+ .il { background: #ddd; color: black }
84
+ .il .il { background: #ccc }
85
+ .il .il .il { background: #bbb }
86
+ .il .idl { background: #ddd; font-weight: bold; color: #666 }
87
+ .idl { background-color: #bbb; font-weight: bold; color: #666; }
88
+
89
+ .im { color:#f00; }
90
+ .in { color:#B2B; font-weight:bold }
91
+ .iv { color:#33B }
92
+ .la { color:#970; font-weight:bold }
93
+ .lv { color:#963 }
94
+ .oc { color:#40E; font-weight:bold }
95
+ .of { color:#000; font-weight:bold }
96
+ .op { }
97
+ .pc { color:#038; font-weight:bold }
98
+ .pd { color:#369; font-weight:bold }
99
+ .pp { color:#579; }
100
+ .ps { color:#00C; font-weight: bold; }
101
+ .pt { color:#349; font-weight:bold }
102
+ .r, .kw { color:#080; font-weight:bold }
103
+
104
+ .ke { color: #808; }
105
+ .ke .dl { color: #606; }
106
+ .ke .ch { color: #80f; }
107
+ .vl { color: #088; }
108
+
109
+ .rx { background-color:#fff0ff }
110
+ .rx .k { color:#808 }
111
+ .rx .dl { color:#404 }
112
+ .rx .mod { color:#C2C }
113
+ .rx .fu { color:#404; font-weight: bold }
114
+
115
+ .s { background-color:#fff0f0; color: #D20; }
116
+ .s .s { background-color:#ffe0e0 }
117
+ .s .s .s { background-color:#ffd0d0 }
118
+ .s .k { }
119
+ .s .ch { color: #b0b; }
120
+ .s .dl { color: #710; }
121
+
122
+ .sh { background-color:#f0fff0; color:#2B2 }
123
+ .sh .k { }
124
+ .sh .dl { color:#161 }
125
+
126
+ .sy { color:#A60 }
127
+ .sy .k { color:#A60 }
128
+ .sy .dl { color:#630 }
129
+
130
+ .ta { color:#070 }
131
+ .tf { color:#070; font-weight:bold }
132
+ .ts { color:#D70; font-weight:bold }
133
+ .ty { color:#339; font-weight:bold }
134
+ .v { color:#036 }
135
+ .xt { color:#444 }
136
+
137
+ .ins { background: #afa; }
138
+ .del { background: #faa; }
139
+ .chg { color: #aaf; background: #007; }
140
+ .head { color: #f8f; background: #505 }
141
+
142
+ .ins .ins { color: #080; font-weight:bold }
143
+ .del .del { color: #800; font-weight:bold }
144
+ .chg .chg { color: #66f; }
145
+ .head .head { color: #f4f; }
146
+ TOKENS
147
+
148
+ end
149
+
150
+ end
151
+ end
@@ -0,0 +1,132 @@
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
14
+ .CodeRay {
15
+ background-color: #{code_background};
16
+ border: 1px solid #{border_color};
17
+ font-family: 'Courier New', 'Terminal', monospace;
18
+ color: #{normal_color};
19
+ }
20
+ .CodeRay pre { margin: 0px; }
21
+
22
+ div.CodeRay { }
23
+
24
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
25
+
26
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
27
+ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
28
+
29
+ .CodeRay .line_numbers, .CodeRay .no {
30
+ background-color: #{numbers_background};
31
+ color: gray;
32
+ text-align: right;
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:#555; background-color: black; }
51
+
52
+ .ch { color:#88F; }
53
+ .ch .k { color:#04D; }
54
+ .ch .dl { color:#039; }
55
+
56
+ .cl { color:#e9e; font-weight:bold; }
57
+ .co { color:#5ED; font-weight:bold; }
58
+ .cr { color:#0A0; }
59
+ .cv { color:#ccf; }
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:#5ed; font-weight:bold; }
70
+ .gv { color:#f84; }
71
+ .hx { color:#058; font-weight:bold; }
72
+ .i { color:#66f; font-weight:bold; }
73
+ .ic { color:#B44; font-weight:bold; }
74
+ .il { }
75
+ .in { color:#B2B; font-weight:bold; }
76
+ .iv { color:#aaf; }
77
+ .la { color:#970; font-weight:bold; }
78
+ .lv { color:#963; }
79
+ .oc { color:#40E; font-weight:bold; }
80
+ .of { color:#000; font-weight:bold; }
81
+ .op { }
82
+ .pc { color:#08f; font-weight:bold; }
83
+ .pd { color:#369; font-weight:bold; }
84
+ .pp { color:#579; }
85
+ .pt { color:#66f; font-weight:bold; }
86
+ .r { color:#5de; font-weight:bold; }
87
+ .r, .kw { color:#5de; font-weight:bold }
88
+
89
+ .ke { color: #808; }
90
+
91
+ .rx { background-color:#221133; }
92
+ .rx .k { color:#f8f; }
93
+ .rx .dl { color:#f0f; }
94
+ .rx .mod { color:#f0b; }
95
+ .rx .fu { color:#404; font-weight: bold; }
96
+
97
+ .s { background-color:#331122; }
98
+ .s .s { background-color:#ffe0e0; }
99
+ .s .s .s { background-color:#ffd0d0; }
100
+ .s .k { color:#F88; }
101
+ .s .dl { color:#f55; }
102
+
103
+ .sh { background-color:#f0fff0; }
104
+ .sh .k { color:#2B2; }
105
+ .sh .dl { color:#161; }
106
+
107
+ .sy { color:#Fc8; }
108
+ .sy .k { color:#Fc8; }
109
+ .sy .dl { color:#F84; }
110
+
111
+ .ta { color:#070; }
112
+ .tf { color:#070; font-weight:bold; }
113
+ .ts { color:#D70; font-weight:bold; }
114
+ .ty { color:#339; font-weight:bold; }
115
+ .v { color:#036; }
116
+ .xt { color:#444; }
117
+
118
+ .ins { background: #afa; }
119
+ .del { background: #faa; }
120
+ .chg { color: #aaf; background: #007; }
121
+ .head { color: #f8f; background: #505 }
122
+
123
+ .ins .ins { color: #080; font-weight:bold }
124
+ .del .del { color: #800; font-weight:bold }
125
+ .chg .chg { color: #66f; }
126
+ .head .head { color: #f4f; }
127
+ TOKENS
128
+
129
+ end
130
+
131
+ end
132
+ end