rack-codehighlighter 0.4.7 → 0.5.0
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/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +64 -36
- data/Rakefile +2 -24
- data/TODO +3 -8
- data/examples/app.rb +0 -4
- data/examples/{config.ru → censor.ru} +1 -0
- data/examples/check.rb +8 -0
- data/examples/coderay.ru +3 -1
- data/examples/example.rb +25 -0
- data/examples/public/stylesheets/pygments.css +62 -61
- data/examples/pygments.ru +3 -2
- data/examples/pygments_api.ru +10 -0
- data/examples/syntax.ru +10 -0
- data/examples/ultraviolet.ru +2 -0
- data/examples/views/index.erb +16 -0
- data/lib/rack/codehighlighter.rb +26 -14
- data/rack-codehighlighter.gemspec +19 -0
- metadata +50 -91
- data/VERSION.yml +0 -5
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2009, 2010
|
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
|
-
|
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
|
-
|
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|
)/, :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|
)/, :logging => false
|
124
138
|
|
139
|
+
Rygments (with the *rygments* gem):
|
140
|
+
|
141
|
+
use Rack::Codehighlighter, :pygments, :element => "pre",
|
142
|
+
:pattern => /\A:::([-_+\w]+)\s*(\n|
)/, :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|
)/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, `
` 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
|
-
|
170
|
+
Try, for example, the Pygments highlighter:
|
152
171
|
|
153
|
-
|
172
|
+
rackup coderay.ru
|
154
173
|
|
155
|
-
The results could be checked at *http://localhost:
|
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
|
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,
|
233
|
+
* ERB+HTML, Groovy (beta), HTML
|
215
234
|
* Java, JavaScript, JSON
|
216
|
-
*
|
217
|
-
*
|
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
|
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
|
-
[
|
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 `<`. This is annoying thing.
|
data/examples/app.rb
CHANGED
data/examples/check.rb
CHANGED
@@ -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')
|
data/examples/coderay.ru
CHANGED
@@ -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
|
-
|
7
|
+
require 'coderay'
|
8
|
+
use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/, :logging => true
|
7
9
|
|
8
10
|
run Sinatra::Application
|
data/examples/example.rb
ADDED
@@ -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
|
-
.
|
3
|
-
.
|
4
|
-
.
|
5
|
-
.
|
6
|
-
.
|
7
|
-
.
|
8
|
-
.
|
9
|
-
.
|
10
|
-
.
|
11
|
-
.
|
12
|
-
.
|
13
|
-
.
|
14
|
-
.
|
15
|
-
.
|
16
|
-
.
|
17
|
-
.
|
18
|
-
.
|
19
|
-
.
|
20
|
-
.
|
21
|
-
.
|
22
|
-
.
|
23
|
-
.
|
24
|
-
.
|
25
|
-
.
|
26
|
-
.
|
27
|
-
.
|
28
|
-
.
|
29
|
-
.
|
30
|
-
.
|
31
|
-
.
|
32
|
-
.
|
33
|
-
.
|
34
|
-
.
|
35
|
-
.
|
36
|
-
.
|
37
|
-
.
|
38
|
-
.
|
39
|
-
.
|
40
|
-
.
|
41
|
-
.
|
42
|
-
.
|
43
|
-
.
|
44
|
-
.
|
45
|
-
.
|
46
|
-
.
|
47
|
-
.
|
48
|
-
.
|
49
|
-
.
|
50
|
-
.
|
51
|
-
.
|
52
|
-
.
|
53
|
-
.
|
54
|
-
.
|
55
|
-
.
|
56
|
-
.
|
57
|
-
.
|
58
|
-
.
|
59
|
-
.
|
60
|
-
.
|
61
|
-
.
|
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 */
|
data/examples/pygments.ru
CHANGED
@@ -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
|
-
|
7
|
-
|
7
|
+
require 'rygments'
|
8
|
+
use Rack::Codehighlighter, :pygments, :element => "pre", :pattern => /\A:::([-_+\w]+)\s*\n/, :logging => true
|
8
9
|
|
9
10
|
run Sinatra::Application
|
data/examples/syntax.ru
ADDED
@@ -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
|
data/examples/ultraviolet.ru
CHANGED
@@ -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"]},
|
data/examples/views/index.erb
CHANGED
@@ -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
|
+
<html>
|
56
|
+
<head>
|
57
|
+
<title>Hello!</title>
|
58
|
+
<style type="text/css">
|
59
|
+
h1 { color: blue; }
|
60
|
+
</style>
|
61
|
+
</head>
|
62
|
+
<body>
|
63
|
+
<h1>Hello World</h1>
|
64
|
+
</body>
|
65
|
+
</html>
|
66
|
+
</pre>
|
data/lib/rack/codehighlighter.rb
CHANGED
@@ -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:::([
|
16
|
+
:pattern => /\A:::([-\w]+)\s*(\n|
)/i, # 
 == 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(/
/i, "\n").gsub("<", '<').gsub(">", '>').gsub("&", '&')
|
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
|
-
|
5
|
-
prerelease:
|
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
|
-
-
|
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
|
-
|
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
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
76
|
-
-
|
77
|
-
-
|
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/
|
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
|
-
-
|
88
|
+
- rack-codehighlighter.gemspec
|
119
89
|
has_rdoc: true
|
120
|
-
homepage: http://
|
90
|
+
homepage: http://tao.inf.ug.edu.pl/
|
121
91
|
licenses: []
|
122
|
-
|
123
92
|
post_install_message:
|
124
|
-
rdoc_options:
|
125
|
-
|
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
|
-
|
134
|
-
|
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
|
-
|
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.
|
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: []
|