rack-codehighlighter 0.4.7 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ Gemfile.lock
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sinatra-filler.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009, 2010 Wlodek Bzyl
1
+ Copyright (c) 2009, 2010, 2011 Włodek Bzyl
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
@@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
19
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
20
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
21
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -11,6 +11,7 @@ It supports the most popular Ruby code highlighters of today:
11
11
  * ultraviolet
12
12
  * coderay
13
13
  * syntax
14
+ * pygments (through [rygments](https://github.com/thedjinn/rygments))
14
15
 
15
16
  As well as
16
17
 
@@ -30,26 +31,42 @@ highlighter.
30
31
 
31
32
  Install the gem with:
32
33
 
33
- sudo gem install rack-codehighlighter
34
+ gem install rack-codehighlighter
34
35
 
35
36
  In order for the highlighting to show up, you’ll need to include a
36
37
  highlighting stylesheet. For example stylesheets you can look at
37
38
  stylesheets in the *examples/public/stylesheets* directory.
38
39
 
39
- ### Rails
40
+ ### Rails 2
40
41
 
41
42
  In order to use, include the following code in a Rails application
42
43
  *config/environment.rb* file:
43
44
 
44
- require 'coderay' # get one of supported highlighters
45
+ require 'coderay' # get one of supported highlighters
45
46
  require 'rack/codehighlighter'
46
-
47
- Rails::Initializer.run do |config|
47
+
48
+ Rails::Initializer.run do |config|
48
49
  config.gem 'coderay'
49
50
  config.gem 'rack-codehighlighter'
50
-
51
+
51
52
  config.middleware.use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/
52
- end
53
+ end
54
+
55
+ ### Rails 3
56
+
57
+ In order to use, update *Gemfile* with:
58
+
59
+ gem 'coderay'
60
+ gem 'rack-codehighlighter', :require => 'rack/codehighlighter'
61
+
62
+ Next, add *Rack::Codehighlighter* to the application middleware stack,
63
+ updating *config/environments/development.rb* and
64
+ *config/environments/production.rb* with:
65
+
66
+ config.middleware.use Rack::Codehighlighter, :coderay,
67
+ :element => "pre", :pattern => /\A:::(\w+)\s*(\n|
)/i, :logging => false
68
+
69
+ (see [Rails on Rack](http://guides.rubyonrails.org/rails_on_rack.html)).
53
70
 
54
71
  ### Any Rack application
55
72
 
@@ -58,12 +75,9 @@ for example with a **Sinatra** application. If your application
58
75
  includes a rackup file or uses *Rack::Builder* to construct the
59
76
  application pipeline, simply require and use as follows:
60
77
 
61
- gem 'coderay' # get one of supported highlighters
62
- require 'coderay'
63
-
64
- gem 'rack-codehighlighter'
78
+ require 'coderay' # get one of supported highlighters
65
79
  require 'rack/codehighlighter'
66
-
80
+
67
81
  use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/
68
82
  run app
69
83
 
@@ -83,7 +97,7 @@ element below:
83
97
  puts "hello world"
84
98
  </pre>
85
99
 
86
- the *ruby* name is extracted.
100
+ the *ruby* name is extracted.
87
101
 
88
102
  To find the appropriate name to use for programming language,
89
103
  look at the lists below.
@@ -112,16 +126,21 @@ Ultraviolet:
112
126
 
113
127
  or
114
128
 
115
- use Rack::Codehighlighter, :ultraviolet, :markdown => true,
116
- :theme => "minimal_theme", :lines => false, :element => "pre>code",
129
+ use Rack::Codehighlighter, :ultraviolet, :markdown => true,
130
+ :theme => "minimal_theme", :lines => false, :element => "pre>code",
117
131
  :pattern => /\A:::([-_+\w]+)\s*(\n|&#x000A;)/, :logging => false,
118
132
  :themes => {"vibrant_ink" => ["ruby"], "upstream_sunburst" => ["objective-c", "java"]}
119
133
 
120
- Unofficial Pygments API:
134
+ Unofficial Pygments API (uses web service, no dependencies):
121
135
 
122
136
  use Rack::Codehighlighter, :pygments_api, :element => "pre",
123
137
  :pattern => /\A:::([-_+\w]+)\s*(\n|&#x000A;)/, :logging => false
124
138
 
139
+ Rygments (with the *rygments* gem):
140
+
141
+ use Rack::Codehighlighter, :pygments, :element => "pre",
142
+ :pattern => /\A:::([-_+\w]+)\s*(\n|&#x000A;)/, :logging => false
143
+
125
144
  Syntax:
126
145
 
127
146
  use Rack::Codehighlighter, :syntax,
@@ -133,7 +152,7 @@ Censor:
133
152
  :element => "pre", :pattern => /\A:::(\w+)\s*(\n|&#x000A;)/i, :logging => false
134
153
 
135
154
 
136
- Markdown, Maruku and RDiscount processors, the code is wrapped with `pre>code`.
155
+ Markdown, Maruku and RDiscount processors, the code is wrapped with `pre>code`.
137
156
  To remove this extra one level of nesting the `:markdown` option should be used:
138
157
 
139
158
  use Rack::Codehighlighter, :coderay, :markdown => true,
@@ -148,11 +167,11 @@ as rendered by HAML, `&#x000A;` was added to the default pattern.
148
167
 
149
168
  The *examples* directory contains several rackup files.
150
169
  Each rackup file uses a different highlighter.
151
- Install the *shotgun* gem and try, for example, the Pygments highlighter:
170
+ Try, for example, the Pygments highlighter:
152
171
 
153
- shotgun pygments.ru
172
+ rackup coderay.ru
154
173
 
155
- The results could be checked at *http://localhost:9393*.
174
+ The results could be checked at *http://localhost:9292*.
156
175
 
157
176
 
158
177
  ## Try it!
@@ -162,17 +181,15 @@ A simple Copy & Paste example.
162
181
  # example.rb
163
182
 
164
183
  require 'rubygems'
165
- gem 'sinatra'
166
184
  require 'sinatra'
167
- gem 'rack-codehighlighter'
168
185
  require 'rack/codehighlighter'
169
-
186
+
170
187
  use Rack::Codehighlighter, :censor, :reason => '[[--difficult code removed--]]'
171
-
188
+
172
189
  get "/" do
173
190
  erb :hello
174
191
  end
175
-
192
+
176
193
  __END__
177
194
  @@ hello
178
195
  <h3>Fibonacci numbers in Ruby</h3>
@@ -190,33 +207,38 @@ Run the example with:
190
207
 
191
208
  ruby example.rb
192
209
 
193
- and check results at *http://localhost:4567*.
210
+ and check the results at *http://localhost:4567*.
194
211
 
195
212
 
196
213
  ## Supported highlighters
197
214
 
198
- These currently include: *Syntax* (fast), *Coderay* (very fast),
199
- *Ultraviolet* (slow, but highlights almost any language).
215
+ These currently include: *Syntax* (fast), *Coderay* (very fast),
216
+ *Ultraviolet* (slow, but highlights almost any language),
217
+ Pygments (via the *rygments* gem or unofficial api).
200
218
 
201
219
  ### [Syntax](http://syntax.rubyforge.org/)
202
220
 
203
- Languages supported by *Syntax*:
221
+ Languages supported by *Syntax*:
204
222
 
205
223
  * xml
206
224
  * ruby
207
225
 
208
226
  ### [Coderay](http://coderay.rubychan.de/)
209
227
 
210
- Languages supported by *Coderay*:
228
+ Languages supported by
229
+ the [coderay](https://github.com/rubychan/coderay) library:
211
230
 
212
- * C, CSS
231
+ * C, C++, CSS
213
232
  * Delphi, diff
214
- * HTML, RHTML (Rails), Nitro-XHTML
233
+ * ERB+HTML, Groovy (beta), HTML
215
234
  * Java, JavaScript, JSON
216
- * Ruby
217
- * YAML
235
+ * Nitro-XHTML, PHP, Python
236
+ * Ruby, Scheme (beta), SQL
237
+ * XML, YAML
238
+
239
+
218
240
 
219
- ### [Ultraviolet](http://ultraviolet.rubyforge.org/)
241
+ ### [Ultraviolet](http://ultraviolet.rubyforge.org/) and 1.8 tree of the Ruby programming language
220
242
 
221
243
  The *ultraviolet* gem needs oniguruma regexp library.
222
244
 
@@ -231,6 +253,12 @@ Now, install the gem:
231
253
 
232
254
  sudo gem install ultraviolet
233
255
 
256
+ ### [Ultraviolet](http://ultraviolet.rubyforge.org/) and 1.9 tree of the Ruby programming language
257
+
258
+ Install a fixed version of the Ultraviolet syntax highlighting
259
+ library for the 1.9 tree of the Ruby programming language from
260
+ [here](https://github.com/spox/ultraviolet).
261
+
234
262
  See also [Ultraviolet themes gallery](http://ultraviolet.rubyforge.org/themes.xhtml)
235
263
 
236
264
  Ultraviolet supports almost any language:
@@ -247,7 +275,7 @@ Ultraviolet supports almost any language:
247
275
  * haml, haskell, html, html-asp, html\_django, html\_for\_asp.net, html\_mason,
248
276
  html\_rails, html\_tcl
249
277
  * icalendar, inform, ini, installer\_distribution\_script, io
250
- * java, javaproperties, javascript, javascript\_+\_prototype,
278
+ * java, javaproperties, javascript, javascript\_+\_prototype,
251
279
  javascript\_+\_prototype\_bracketed, jquery\_javascript, json
252
280
  * languagedefinition, latex, latex\_beamer, latex\_log, latex\_memoir, lexflex,
253
281
  lighttpd, lilypond, lisp, literate\_haskell, logo, logtalk, lua
data/Rakefile CHANGED
@@ -1,24 +1,2 @@
1
- require "rake"
2
-
3
- begin
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gemspec|
6
- gemspec.name = "rack-codehighlighter"
7
- gemspec.summary = "Rack Middleware for Code Highlighting."
8
- gemspec.email = "matwb@univ.gda.pl"
9
- gemspec.homepage = "http://github.com/wbzyl/rack-codehighlighter"
10
- gemspec.authors = ["Wlodek Bzyl"]
11
- gemspec.description = gemspec.summary
12
-
13
- gemspec.files = %w[LICENSE TODO Rakefile VERSION.yml] + FileList['lib/**/*.rb', "examples/**/*"]
14
-
15
- gemspec.add_runtime_dependency 'rack', '>=1.0.0'
16
- gemspec.add_runtime_dependency 'nokogiri', '>=1.4.1'
17
-
18
- gemspec.add_development_dependency 'rack-test', '>=0.3.0'
19
- end
20
- Jeweler::GemcutterTasks.new
21
- rescue LoadError
22
- puts "Jeweler not available. Install it with:"
23
- puts " sudo gem install jeweler"
24
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/TODO CHANGED
@@ -1,9 +1,4 @@
1
- [15.06.2009]
2
-
3
- Compare: http://freelancing-god.github.com/ts/en/
4
- Description of thinking-sphinx gem.
5
-
6
- [13.10.2009]
1
+ [22.07.2011]
7
2
 
8
3
  Currently, almost everything what I write is rendered by Ruby on Rails
9
4
  and Sinatra applications. To improve the readability of the text, I
@@ -14,7 +9,7 @@ The problem is to how syntax highlighting features are hooked into
14
9
  these frameworks.
15
10
 
16
11
  Look at the current practice. To this end, analyze the top three tools
17
- listed on *The Ruby Toolbox* in category
12
+ listed on *The Ruby Toolbox* in category
18
13
  [Syntax Highlighting](http://ruby-toolbox.com/categories/syntax_highlighting.html).
19
14
 
20
15
  [tm_syntax_highlighting](http://github.com/arya/tm_syntax_highlighting/) (plugin):
@@ -29,7 +24,7 @@ listed on *The Ruby Toolbox* in category
29
24
 
30
25
  [Redcloth with CodeRay](http://github.com/augustl/redcloth-with-coderay) (gem):
31
26
 
32
- <source:ruby> some_ruby_code </source>
27
+ <source:ruby> some_ruby_code </source>
33
28
 
34
29
  In each piece of code inserted into html we must change:
35
30
  `<` to `&lt;`. This is annoying thing.
@@ -6,10 +6,6 @@ require 'sinatra'
6
6
 
7
7
  require 'rack/codehighlighter'
8
8
 
9
- require 'coderay' # Coderay
10
- require 'syntax/convertors/html' # Syntax
11
- require 'uv' # Ultraviolet
12
-
13
9
  get "/" do
14
10
  erb :index
15
11
  end
@@ -1,3 +1,4 @@
1
+ $:.unshift File.dirname(__FILE__)
1
2
  require 'app'
2
3
 
3
4
  use Rack::ShowExceptions
@@ -3,6 +3,8 @@ require 'rubygems'
3
3
  require 'coderay'
4
4
  require 'uv'
5
5
  require 'syntax/convertors/html'
6
+ require 'rygments'
7
+ #require 'pygments'
6
8
 
7
9
  str = "def hitch; end"
8
10
 
@@ -14,3 +16,9 @@ puts CodeRay.encoder(:html).encode(str, 'ruby')
14
16
 
15
17
  puts "---- Ultraviolet ----"
16
18
  puts Uv.parse(str, 'xhtml', 'ruby_experimental', false, 'dawn')
19
+
20
+ puts "---- Rygments ----"
21
+ puts Rygments.highlight_string(str, 'ruby', 'html')
22
+
23
+ #puts "---- Pygments ----"
24
+ #puts Pygments.highlight(str, :lexer => 'ruby', :formatter => 'html')
@@ -1,8 +1,10 @@
1
+ $:.unshift File.dirname(__FILE__)
1
2
  require 'app'
2
3
 
3
4
  use Rack::ShowExceptions
4
5
  use Rack::Lint
5
6
 
6
- use Rack::Codehighlighter, :prettify, :element => "pre", :pattern => /\A:::(\w+)\s*\n/, :logging => true
7
+ require 'coderay'
8
+ use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/, :logging => true
7
9
 
8
10
  run Sinatra::Application
@@ -0,0 +1,25 @@
1
+ path = File.expand_path("../lib")
2
+ $:.unshift(path) unless $:.include?(path)
3
+
4
+ require 'rubygems'
5
+ require 'sinatra'
6
+ require 'rack/codehighlighter'
7
+
8
+ use Rack::Codehighlighter, :censor, :reason => '[[--difficult code removed--]]'
9
+
10
+ get "/" do
11
+ erb :hello
12
+ end
13
+
14
+ __END__
15
+ @@ hello
16
+ <h3>Fibonacci numbers in Ruby</h3>
17
+ <pre>:::ruby
18
+ def fib(n)
19
+ if n < 2
20
+ 1
21
+ else
22
+ fib(n-2) + fib(n-1)
23
+ end
24
+ end
25
+ </pre>
@@ -1,61 +1,62 @@
1
- .hll { background-color: #ffffcc }
2
- .c { color: #408080; font-style: italic } /* Comment */
3
- .err { border: 1px solid #FF0000 } /* Error */
4
- .k { color: #008000; font-weight: bold } /* Keyword */
5
- .o { color: #666666 } /* Operator */
6
- .cm { color: #408080; font-style: italic } /* Comment.Multiline */
7
- .cp { color: #BC7A00 } /* Comment.Preproc */
8
- .c1 { color: #408080; font-style: italic } /* Comment.Single */
9
- .cs { color: #408080; font-style: italic } /* Comment.Special */
10
- .gd { color: #A00000 } /* Generic.Deleted */
11
- .ge { font-style: italic } /* Generic.Emph */
12
- .gr { color: #FF0000 } /* Generic.Error */
13
- .gh { color: #000080; font-weight: bold } /* Generic.Heading */
14
- .gi { color: #00A000 } /* Generic.Inserted */
15
- .go { color: #808080 } /* Generic.Output */
16
- .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
17
- .gs { font-weight: bold } /* Generic.Strong */
18
- .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
19
- .gt { color: #0040D0 } /* Generic.Traceback */
20
- .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
21
- .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
22
- .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
23
- .kp { color: #008000 } /* Keyword.Pseudo */
24
- .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
25
- .kt { color: #B00040 } /* Keyword.Type */
26
- .m { color: #666666 } /* Literal.Number */
27
- .s { color: #BA2121 } /* Literal.String */
28
- .na { color: #7D9029 } /* Name.Attribute */
29
- .nb { color: #008000 } /* Name.Builtin */
30
- .nc { color: #0000FF; font-weight: bold } /* Name.Class */
31
- .no { color: #880000 } /* Name.Constant */
32
- .nd { color: #AA22FF } /* Name.Decorator */
33
- .ni { color: #999999; font-weight: bold } /* Name.Entity */
34
- .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
35
- .nf { color: #0000FF } /* Name.Function */
36
- .nl { color: #A0A000 } /* Name.Label */
37
- .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
38
- .nt { color: #008000; font-weight: bold } /* Name.Tag */
39
- .nv { color: #19177C } /* Name.Variable */
40
- .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
41
- .w { color: #bbbbbb } /* Text.Whitespace */
42
- .mf { color: #666666 } /* Literal.Number.Float */
43
- .mh { color: #666666 } /* Literal.Number.Hex */
44
- .mi { color: #666666 } /* Literal.Number.Integer */
45
- .mo { color: #666666 } /* Literal.Number.Oct */
46
- .sb { color: #BA2121 } /* Literal.String.Backtick */
47
- .sc { color: #BA2121 } /* Literal.String.Char */
48
- .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
49
- .s2 { color: #BA2121 } /* Literal.String.Double */
50
- .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
51
- .sh { color: #BA2121 } /* Literal.String.Heredoc */
52
- .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
53
- .sx { color: #008000 } /* Literal.String.Other */
54
- .sr { color: #BB6688 } /* Literal.String.Regex */
55
- .s1 { color: #BA2121 } /* Literal.String.Single */
56
- .ss { color: #19177C } /* Literal.String.Symbol */
57
- .bp { color: #008000 } /* Name.Builtin.Pseudo */
58
- .vc { color: #19177C } /* Name.Variable.Class */
59
- .vg { color: #19177C } /* Name.Variable.Global */
60
- .vi { color: #19177C } /* Name.Variable.Instance */
61
- .il { color: #666666 } /* Literal.Number.Integer.Long */
1
+ .highlight .hll { background-color: #ffffcc }
2
+ .highlight { background: #f8f8f8; }
3
+ .highlight .c { color: #008800; font-style: italic } /* Comment */
4
+ .highlight .err { border: 1px solid #FF0000 } /* Error */
5
+ .highlight .k { color: #AA22FF; font-weight: bold } /* Keyword */
6
+ .highlight .o { color: #666666 } /* Operator */
7
+ .highlight .cm { color: #008800; font-style: italic } /* Comment.Multiline */
8
+ .highlight .cp { color: #008800 } /* Comment.Preproc */
9
+ .highlight .c1 { color: #008800; font-style: italic } /* Comment.Single */
10
+ .highlight .cs { color: #008800; font-weight: bold } /* Comment.Special */
11
+ .highlight .gd { color: #A00000 } /* Generic.Deleted */
12
+ .highlight .ge { font-style: italic } /* Generic.Emph */
13
+ .highlight .gr { color: #FF0000 } /* Generic.Error */
14
+ .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
15
+ .highlight .gi { color: #00A000 } /* Generic.Inserted */
16
+ .highlight .go { color: #808080 } /* Generic.Output */
17
+ .highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
18
+ .highlight .gs { font-weight: bold } /* Generic.Strong */
19
+ .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
20
+ .highlight .gt { color: #0040D0 } /* Generic.Traceback */
21
+ .highlight .kc { color: #AA22FF; font-weight: bold } /* Keyword.Constant */
22
+ .highlight .kd { color: #AA22FF; font-weight: bold } /* Keyword.Declaration */
23
+ .highlight .kn { color: #AA22FF; font-weight: bold } /* Keyword.Namespace */
24
+ .highlight .kp { color: #AA22FF } /* Keyword.Pseudo */
25
+ .highlight .kr { color: #AA22FF; font-weight: bold } /* Keyword.Reserved */
26
+ .highlight .kt { color: #00BB00; font-weight: bold } /* Keyword.Type */
27
+ .highlight .m { color: #666666 } /* Literal.Number */
28
+ .highlight .s { color: #BB4444 } /* Literal.String */
29
+ .highlight .na { color: #BB4444 } /* Name.Attribute */
30
+ .highlight .nb { color: #AA22FF } /* Name.Builtin */
31
+ .highlight .nc { color: #0000FF } /* Name.Class */
32
+ .highlight .no { color: #880000 } /* Name.Constant */
33
+ .highlight .nd { color: #AA22FF } /* Name.Decorator */
34
+ .highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
35
+ .highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
36
+ .highlight .nf { color: #00A000 } /* Name.Function */
37
+ .highlight .nl { color: #A0A000 } /* Name.Label */
38
+ .highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
39
+ .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
40
+ .highlight .nv { color: #B8860B } /* Name.Variable */
41
+ .highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
42
+ .highlight .w { color: #bbbbbb } /* Text.Whitespace */
43
+ .highlight .mf { color: #666666 } /* Literal.Number.Float */
44
+ .highlight .mh { color: #666666 } /* Literal.Number.Hex */
45
+ .highlight .mi { color: #666666 } /* Literal.Number.Integer */
46
+ .highlight .mo { color: #666666 } /* Literal.Number.Oct */
47
+ .highlight .sb { color: #BB4444 } /* Literal.String.Backtick */
48
+ .highlight .sc { color: #BB4444 } /* Literal.String.Char */
49
+ .highlight .sd { color: #BB4444; font-style: italic } /* Literal.String.Doc */
50
+ .highlight .s2 { color: #BB4444 } /* Literal.String.Double */
51
+ .highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
52
+ .highlight .sh { color: #BB4444 } /* Literal.String.Heredoc */
53
+ .highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
54
+ .highlight .sx { color: #008000 } /* Literal.String.Other */
55
+ .highlight .sr { color: #BB6688 } /* Literal.String.Regex */
56
+ .highlight .s1 { color: #BB4444 } /* Literal.String.Single */
57
+ .highlight .ss { color: #B8860B } /* Literal.String.Symbol */
58
+ .highlight .bp { color: #AA22FF } /* Name.Builtin.Pseudo */
59
+ .highlight .vc { color: #B8860B } /* Name.Variable.Class */
60
+ .highlight .vg { color: #B8860B } /* Name.Variable.Global */
61
+ .highlight .vi { color: #B8860B } /* Name.Variable.Instance */
62
+ .highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
@@ -1,9 +1,10 @@
1
+ $:.unshift File.dirname(__FILE__)
1
2
  require 'app'
2
3
 
3
4
  use Rack::ShowExceptions
4
5
  use Rack::Lint
5
6
 
6
- use Rack::Codehighlighter, :pygments_api, :element => "pre",
7
- :pattern => /\A:::([-_+\w]+)\s*\n/, :logging => true
7
+ require 'rygments'
8
+ use Rack::Codehighlighter, :pygments, :element => "pre", :pattern => /\A:::([-_+\w]+)\s*\n/, :logging => true
8
9
 
9
10
  run Sinatra::Application
@@ -0,0 +1,10 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'app'
3
+
4
+ use Rack::ShowExceptions
5
+ use Rack::Lint
6
+
7
+ use Rack::Codehighlighter, :pygments_api, :element => "pre",
8
+ :pattern => /\A:::([-_+\w]+)\s*\n/, :logging => true
9
+
10
+ run Sinatra::Application
@@ -0,0 +1,10 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'app'
3
+
4
+ use Rack::ShowExceptions
5
+ use Rack::Lint
6
+
7
+ require 'syntax/convertors/html'
8
+ use Rack::Codehighlighter, :syntax, :element => "pre", :pattern => /\A:::([-_+\w]+)\s*\n/, :logging => true
9
+
10
+ run Sinatra::Application
@@ -1,8 +1,10 @@
1
+ $:.unshift File.dirname(__FILE__)
1
2
  require 'app'
2
3
 
3
4
  use Rack::ShowExceptions
4
5
  use Rack::Lint
5
6
 
7
+ require 'uv'
6
8
  use Rack::Codehighlighter, :ultraviolet,
7
9
  :element => "pre", :pattern => /\A:::(\w+)\s*\n/,
8
10
  :themes => {"cobalt" => ["ruby"], "zenburnesque" => ["c", "sql"]},
@@ -48,3 +48,19 @@ create table exams (
48
48
  when datetime
49
49
  );
50
50
  </pre>
51
+
52
+ <h3>html</h3>
53
+
54
+ <pre>:::html
55
+ &lt;html&gt;
56
+ &lt;head&gt;
57
+ &lt;title&gt;Hello!&lt;/title&gt;
58
+ &lt;style type="text/css"&gt;
59
+ h1 { color: blue; }
60
+ &lt;/style&gt;
61
+ &lt;/head&gt;
62
+ &lt;body&gt;
63
+ &lt;h1&gt;Hello World&lt;/h1&gt;
64
+ &lt;/body&gt;
65
+ &lt;/html&gt;
66
+ </pre>
@@ -7,15 +7,15 @@ module Rack
7
7
 
8
8
  # for logging use
9
9
  FORMAT = %{%s - [%s] [%s] "%s %s%s %s" (%s) %d %d %0.4f\n}
10
-
10
+
11
11
  def initialize(app, highlighter = :censor, opts = {})
12
12
  @app = app
13
13
  @highlighter = highlighter
14
14
  @opts = {
15
15
  :element => "pre",
16
- :pattern => /\A:::([-_\w]+)\s*(\n|&#x000A;)/i, # &#x000A; == line feed
16
+ :pattern => /\A:::([-\w]+)\s*(\n|&#x000A;)/i, # &#x000A; == line feed
17
17
  :reason => "[[-- ugly code removed --]]", #8-)
18
- :markdown => false
18
+ :markdown => false
19
19
  }
20
20
  @opts.merge! opts
21
21
  end
@@ -37,9 +37,9 @@ module Rack
37
37
  nodes.each do |node|
38
38
  s = node.inner_html || "[++where is the code?++]"
39
39
  if @opts[:markdown]
40
- node.parent.swap(send(@highlighter, s))
40
+ node.parent.swap(send(@highlighter, s))
41
41
  else
42
- node.swap(send(@highlighter, s))
42
+ node.swap(send(@highlighter, s))
43
43
  end
44
44
  end
45
45
 
@@ -49,10 +49,10 @@ module Rack
49
49
  log(env, status, headers, began_at) if @opts[:logging]
50
50
  [status, headers, [body]]
51
51
  else
52
- [status, headers, response]
52
+ [status, headers, response]
53
53
  end
54
54
  end
55
-
55
+
56
56
  private
57
57
 
58
58
  def log(env, status, headers, began_at)
@@ -91,13 +91,13 @@ module Rack
91
91
  refs = @opts[:pattern].match(string) # extract language name
92
92
  if refs
93
93
  lang = refs[1]
94
- convertor = ::Syntax::Convertors::HTML.for_syntax translate[lang]
95
- convertor.convert(unescape_html(string.sub(@opts[:pattern], "")) || "[=this can'n happen=]")
94
+ convertor = ::Syntax::Convertors::HTML.for_syntax translate[lang] || lang
95
+ convertor.convert(unescape_html(string.sub(@opts[:pattern], "")) || "[=this can'n happen=]")
96
96
  else
97
97
  "<pre>#{string}</pre>"
98
98
  end
99
99
  end
100
-
100
+
101
101
  def coderay(string)
102
102
  lang = 'unknown'
103
103
  refs = @opts[:pattern].match(string) # extract language name
@@ -121,7 +121,7 @@ module Rack
121
121
  }
122
122
  lang = 'unknown'
123
123
  refs = @opts[:pattern].match(string) # extract language name
124
- if refs
124
+ if refs
125
125
  lang = refs[1]
126
126
  str = string.sub(@opts[:pattern], "")
127
127
  "<pre class='prettyprint lang-#{translate[lang] || lang}'>#{str}</pre>"
@@ -130,6 +130,18 @@ module Rack
130
130
  end
131
131
  end
132
132
 
133
+ def pygments(string)
134
+ refs = @opts[:pattern].match(string)
135
+ if refs
136
+ lang = refs[1]
137
+ str = unescape_html(string.sub(@opts[:pattern], ""))
138
+ #Pygments.highlight(str, :lexer => lang, :formatter => 'html')
139
+ Rygments.highlight_string(str, lang, 'html')
140
+ else
141
+ "<pre>#{string}</pre>"
142
+ end
143
+ end
144
+
133
145
  def pygments_api(string)
134
146
  require 'net/http'
135
147
  require 'uri'
@@ -153,7 +165,7 @@ module Rack
153
165
  refs = @opts[:pattern].match(string) # extract language name
154
166
  if refs
155
167
  lang = refs[1]
156
- theme = opts[:themes].collect do |k,v|
168
+ theme = opts[:themes].collect do |k,v|
157
169
  k if v.include? lang end.compact.first || opts[:theme]
158
170
  str = unescape_html(string.sub(@opts[:pattern], ""))
159
171
  "#{::Uv.parse(str, 'xhtml', lang, opts[:lines], theme)}"
@@ -161,10 +173,10 @@ module Rack
161
173
  "<pre class='#{opts[:theme]}'>#{string}</pre>"
162
174
  end
163
175
  end
164
-
176
+
165
177
  def unescape_html(string)
166
178
  string.to_s.gsub(/&#x000A;/i, "\n").gsub("&lt;", '<').gsub("&gt;", '>').gsub("&amp;", '&')
167
179
  end
168
-
180
+
169
181
  end
170
182
  end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "rack-codehighlighter"
5
+ s.version = "0.5.0"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Włodek Bzyl"]
8
+ s.email = ["matwb@ug.edu.pl"]
9
+ s.homepage = "http://tao.inf.ug.edu.pl/"
10
+ s.summary = %q{Rack Middleware for Code Highlighting.}
11
+ s.description = %q{Rack Middleware for Code Highlighting. Supports the most popular Ruby code highlighters.}
12
+
13
+ s.add_runtime_dependency 'rack', '>= 1.0.0'
14
+ s.add_runtime_dependency 'nokogiri', '>= 1.4.1'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.require_paths = ["lib"]
19
+ end
metadata CHANGED
@@ -1,90 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-codehighlighter
3
- version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 4
9
- - 7
10
- version: 0.4.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - Wlodek Bzyl
7
+ authors:
8
+ - Włodek Bzyl
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-09-03 00:00:00 +02:00
12
+ date: 2011-07-25 00:00:00.000000000 +02:00
19
13
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &18051100 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 1
32
- - 0
33
- - 0
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
34
22
  version: 1.0.0
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: nokogiri
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *18051100
26
+ - !ruby/object:Gem::Dependency
27
+ name: nokogiri
28
+ requirement: &18050440 !ruby/object:Gem::Requirement
41
29
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 5
46
- segments:
47
- - 1
48
- - 4
49
- - 1
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
50
33
  version: 1.4.1
51
34
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: rack-test
55
35
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 19
62
- segments:
63
- - 0
64
- - 3
65
- - 0
66
- version: 0.3.0
67
- type: :development
68
- version_requirements: *id003
69
- description: Rack Middleware for Code Highlighting.
70
- email: matwb@univ.gda.pl
36
+ version_requirements: *18050440
37
+ description: Rack Middleware for Code Highlighting. Supports the most popular Ruby
38
+ code highlighters.
39
+ email:
40
+ - matwb@ug.edu.pl
71
41
  executables: []
72
-
73
42
  extensions: []
74
-
75
- extra_rdoc_files:
76
- - LICENSE
77
- - README.markdown
78
- - TODO
79
- files:
43
+ extra_rdoc_files: []
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
80
47
  - LICENSE
48
+ - README.md
81
49
  - Rakefile
82
50
  - TODO
83
- - VERSION.yml
84
51
  - examples/app.rb
52
+ - examples/censor.ru
85
53
  - examples/check.rb
86
54
  - examples/coderay.ru
87
- - examples/config.ru
55
+ - examples/example.rb
88
56
  - examples/public/javascripts/lang-css.js
89
57
  - examples/public/javascripts/lang-hs.js
90
58
  - examples/public/javascripts/lang-lisp.js
@@ -111,45 +79,36 @@ files:
111
79
  - examples/public/stylesheets/uv/twilight.css
112
80
  - examples/public/stylesheets/uv/zenburnesque.css
113
81
  - examples/pygments.ru
82
+ - examples/pygments_api.ru
83
+ - examples/syntax.ru
114
84
  - examples/ultraviolet.ru
115
85
  - examples/views/index.erb
116
86
  - examples/views/layout.erb
117
87
  - lib/rack/codehighlighter.rb
118
- - README.markdown
88
+ - rack-codehighlighter.gemspec
119
89
  has_rdoc: true
120
- homepage: http://github.com/wbzyl/rack-codehighlighter
90
+ homepage: http://tao.inf.ug.edu.pl/
121
91
  licenses: []
122
-
123
92
  post_install_message:
124
- rdoc_options:
125
- - --charset=UTF-8
126
- require_paths:
93
+ rdoc_options: []
94
+ require_paths:
127
95
  - lib
128
- required_ruby_version: !ruby/object:Gem::Requirement
96
+ required_ruby_version: !ruby/object:Gem::Requirement
129
97
  none: false
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- hash: 3
134
- segments:
135
- - 0
136
- version: "0"
137
- required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
103
  none: false
139
- requirements:
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- hash: 3
143
- segments:
144
- - 0
145
- version: "0"
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
146
108
  requirements: []
147
-
148
109
  rubyforge_project:
149
- rubygems_version: 1.3.7
110
+ rubygems_version: 1.6.2
150
111
  signing_key:
151
112
  specification_version: 3
152
113
  summary: Rack Middleware for Code Highlighting.
153
- test_files:
154
- - examples/check.rb
155
- - examples/app.rb
114
+ test_files: []
@@ -1,5 +0,0 @@
1
- ---
2
- :minor: 4
3
- :patch: 7
4
- :build:
5
- :major: 0