Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved from pygments.rb to rygments; pygments.rb does not work for me

  • Loading branch information...
commit 8160893529c68cb7692dc60f6a9140d8e46648cf 1 parent 6d3e260
@wbzyl authored
View
44 README.md
@@ -11,7 +11,7 @@ It supports the most popular Ruby code highlighters of today:
* ultraviolet
* coderay
* syntax
-* pygments (through pygments.rb)
+* pygments (through [rygments](https://github.com/thedjinn/rygments))
As well as
@@ -31,13 +31,13 @@ highlighter.
Install the gem with:
- sudo gem install rack-codehighlighter
+ gem install rack-codehighlighter
In order for the highlighting to show up, you’ll need to include a
highlighting stylesheet. For example stylesheets you can look at
stylesheets in the *examples/public/stylesheets* directory.
-### Rails
+### Rails 2
In order to use, include the following code in a Rails application
*config/environment.rb* file:
@@ -52,6 +52,22 @@ In order to use, include the following code in a Rails application
config.middleware.use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/
end
+### Rails 3
+
+In order to use, update *Gemfile* with:
+
+ gem 'coderay'
+ gem 'rack-codehighlighter', :require => 'rack/codehighlighter'
+
+Next, add *Rack::Codehighlighter* to the application middleware stack,
+updating *config/environments/development.rb* and
+*config/environments/production.rb* with:
+
+ config.middleware.use Rack::Codehighlighter, :coderay,
+ :element => "pre", :pattern => /\A:::(\w+)\s*(\n|
)/i, :logging => false
+
+(see [Rails on Rack](http://guides.rubyonrails.org/rails_on_rack.html)).
+
### Any Rack application
The *rack-codehighlighter* gem can be used with any Rack application,
@@ -59,10 +75,7 @@ for example with a **Sinatra** application. If your application
includes a rackup file or uses *Rack::Builder* to construct the
application pipeline, simply require and use as follows:
- gem 'coderay' # get one of supported highlighters
- require 'coderay'
-
- gem 'rack-codehighlighter'
+ require 'coderay' # get one of supported highlighters
require 'rack/codehighlighter'
use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/
@@ -118,12 +131,12 @@ or
:pattern => /\A:::([-_+\w]+)\s*(\n|
)/, :logging => false,
:themes => {"vibrant_ink" => ["ruby"], "upstream_sunburst" => ["objective-c", "java"]}
-Unofficial Pygments API (uses web service no dependencies):
+Unofficial Pygments API (uses web service, no dependencies):
use Rack::Codehighlighter, :pygments_api, :element => "pre",
:pattern => /\A:::([-_+\w]+)\s*(\n|
)/, :logging => false
-Pygments (with pygments.rb):
+Rygments (with the *rygments* gem):
use Rack::Codehighlighter, :pygments, :element => "pre",
:pattern => /\A:::([-_+\w]+)\s*(\n|
)/, :logging => false
@@ -154,11 +167,11 @@ as rendered by HAML, `
` was added to the default pattern.
The *examples* directory contains several rackup files.
Each rackup file uses a different highlighter.
-Install the *shotgun* gem and try, for example, the Pygments highlighter:
+Try, for example, the Pygments highlighter:
- shotgun pygments.ru
+ rackup coderay.ru
-The results could be checked at *http://localhost:9393*.
+The results could be checked at *http://localhost:9292*.
## Try it!
@@ -168,9 +181,7 @@ A simple Copy & Paste example.
# example.rb
require 'rubygems'
- gem 'sinatra'
require 'sinatra'
- gem 'rack-codehighlighter'
require 'rack/codehighlighter'
use Rack::Codehighlighter, :censor, :reason => '[[--difficult code removed--]]'
@@ -196,13 +207,14 @@ Run the example with:
ruby example.rb
-and check results at *http://localhost:4567*.
+and check the results at *http://localhost:4567*.
## Supported highlighters
These currently include: *Syntax* (fast), *Coderay* (very fast),
-*Ultraviolet* (slow, but highlights almost any language).
+*Ultraviolet* (slow, but highlights almost any language),
+Pygments (via the *rygments* gem or unofficial api).
### [Syntax](http://syntax.rubyforge.org/)
View
0  examples/config.ru → examples/censor.ru
File renamed without changes
View
10 examples/check.rb
@@ -3,7 +3,8 @@
require 'coderay'
require 'uv'
require 'syntax/convertors/html'
-require 'pygments'
+require 'rygments'
+#require 'pygments'
str = "def hitch; end"
@@ -16,5 +17,8 @@
puts "---- Ultraviolet ----"
puts Uv.parse(str, 'xhtml', 'ruby_experimental', false, 'dawn')
-puts "---- Pygments ----"
-puts Pygments.highlight(str, :lexer => 'ruby', :formatter => 'html')
+puts "---- Rygments ----"
+puts Rygments.highlight_string(str, 'ruby', 'html')
+
+#puts "---- Pygments ----"
+#puts Pygments.highlight(str, :lexer => 'ruby', :formatter => 'html')
View
25 examples/example.rb
@@ -0,0 +1,25 @@
+path = File.expand_path("../lib")
+$:.unshift(path) unless $:.include?(path)
+
+require 'rubygems'
+require 'sinatra'
+require 'rack/codehighlighter'
+
+use Rack::Codehighlighter, :censor, :reason => '[[--difficult code removed--]]'
+
+get "/" do
+ erb :hello
+end
+
+__END__
+@@ hello
+<h3>Fibonacci numbers in Ruby</h3>
+<pre>:::ruby
+def fib(n)
+ if n < 2
+ 1
+ else
+ fib(n-2) + fib(n-1)
+ end
+end
+</pre>
View
123 examples/public/stylesheets/pygments.css
@@ -1,61 +1,62 @@
-.hll { background-color: #ffffcc }
-.c { color: #408080; font-style: italic } /* Comment */
-.err { border: 1px solid #FF0000 } /* Error */
-.k { color: #008000; font-weight: bold } /* Keyword */
-.o { color: #666666 } /* Operator */
-.cm { color: #408080; font-style: italic } /* Comment.Multiline */
-.cp { color: #BC7A00 } /* Comment.Preproc */
-.c1 { color: #408080; font-style: italic } /* Comment.Single */
-.cs { color: #408080; font-style: italic } /* Comment.Special */
-.gd { color: #A00000 } /* Generic.Deleted */
-.ge { font-style: italic } /* Generic.Emph */
-.gr { color: #FF0000 } /* Generic.Error */
-.gh { color: #000080; font-weight: bold } /* Generic.Heading */
-.gi { color: #00A000 } /* Generic.Inserted */
-.go { color: #808080 } /* Generic.Output */
-.gp { color: #000080; font-weight: bold } /* Generic.Prompt */
-.gs { font-weight: bold } /* Generic.Strong */
-.gu { color: #800080; font-weight: bold } /* Generic.Subheading */
-.gt { color: #0040D0 } /* Generic.Traceback */
-.kc { color: #008000; font-weight: bold } /* Keyword.Constant */
-.kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
-.kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
-.kp { color: #008000 } /* Keyword.Pseudo */
-.kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
-.kt { color: #B00040 } /* Keyword.Type */
-.m { color: #666666 } /* Literal.Number */
-.s { color: #BA2121 } /* Literal.String */
-.na { color: #7D9029 } /* Name.Attribute */
-.nb { color: #008000 } /* Name.Builtin */
-.nc { color: #0000FF; font-weight: bold } /* Name.Class */
-.no { color: #880000 } /* Name.Constant */
-.nd { color: #AA22FF } /* Name.Decorator */
-.ni { color: #999999; font-weight: bold } /* Name.Entity */
-.ne { color: #D2413A; font-weight: bold } /* Name.Exception */
-.nf { color: #0000FF } /* Name.Function */
-.nl { color: #A0A000 } /* Name.Label */
-.nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
-.nt { color: #008000; font-weight: bold } /* Name.Tag */
-.nv { color: #19177C } /* Name.Variable */
-.ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
-.w { color: #bbbbbb } /* Text.Whitespace */
-.mf { color: #666666 } /* Literal.Number.Float */
-.mh { color: #666666 } /* Literal.Number.Hex */
-.mi { color: #666666 } /* Literal.Number.Integer */
-.mo { color: #666666 } /* Literal.Number.Oct */
-.sb { color: #BA2121 } /* Literal.String.Backtick */
-.sc { color: #BA2121 } /* Literal.String.Char */
-.sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
-.s2 { color: #BA2121 } /* Literal.String.Double */
-.se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
-.sh { color: #BA2121 } /* Literal.String.Heredoc */
-.si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
-.sx { color: #008000 } /* Literal.String.Other */
-.sr { color: #BB6688 } /* Literal.String.Regex */
-.s1 { color: #BA2121 } /* Literal.String.Single */
-.ss { color: #19177C } /* Literal.String.Symbol */
-.bp { color: #008000 } /* Name.Builtin.Pseudo */
-.vc { color: #19177C } /* Name.Variable.Class */
-.vg { color: #19177C } /* Name.Variable.Global */
-.vi { color: #19177C } /* Name.Variable.Instance */
-.il { color: #666666 } /* Literal.Number.Integer.Long */
+.highlight .hll { background-color: #ffffcc }
+.highlight { background: #f8f8f8; }
+.highlight .c { color: #008800; font-style: italic } /* Comment */
+.highlight .err { border: 1px solid #FF0000 } /* Error */
+.highlight .k { color: #AA22FF; font-weight: bold } /* Keyword */
+.highlight .o { color: #666666 } /* Operator */
+.highlight .cm { color: #008800; font-style: italic } /* Comment.Multiline */
+.highlight .cp { color: #008800 } /* Comment.Preproc */
+.highlight .c1 { color: #008800; font-style: italic } /* Comment.Single */
+.highlight .cs { color: #008800; font-weight: bold } /* Comment.Special */
+.highlight .gd { color: #A00000 } /* Generic.Deleted */
+.highlight .ge { font-style: italic } /* Generic.Emph */
+.highlight .gr { color: #FF0000 } /* Generic.Error */
+.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+.highlight .gi { color: #00A000 } /* Generic.Inserted */
+.highlight .go { color: #808080 } /* Generic.Output */
+.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+.highlight .gs { font-weight: bold } /* Generic.Strong */
+.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+.highlight .gt { color: #0040D0 } /* Generic.Traceback */
+.highlight .kc { color: #AA22FF; font-weight: bold } /* Keyword.Constant */
+.highlight .kd { color: #AA22FF; font-weight: bold } /* Keyword.Declaration */
+.highlight .kn { color: #AA22FF; font-weight: bold } /* Keyword.Namespace */
+.highlight .kp { color: #AA22FF } /* Keyword.Pseudo */
+.highlight .kr { color: #AA22FF; font-weight: bold } /* Keyword.Reserved */
+.highlight .kt { color: #00BB00; font-weight: bold } /* Keyword.Type */
+.highlight .m { color: #666666 } /* Literal.Number */
+.highlight .s { color: #BB4444 } /* Literal.String */
+.highlight .na { color: #BB4444 } /* Name.Attribute */
+.highlight .nb { color: #AA22FF } /* Name.Builtin */
+.highlight .nc { color: #0000FF } /* Name.Class */
+.highlight .no { color: #880000 } /* Name.Constant */
+.highlight .nd { color: #AA22FF } /* Name.Decorator */
+.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
+.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+.highlight .nf { color: #00A000 } /* Name.Function */
+.highlight .nl { color: #A0A000 } /* Name.Label */
+.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
+.highlight .nv { color: #B8860B } /* Name.Variable */
+.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+.highlight .w { color: #bbbbbb } /* Text.Whitespace */
+.highlight .mf { color: #666666 } /* Literal.Number.Float */
+.highlight .mh { color: #666666 } /* Literal.Number.Hex */
+.highlight .mi { color: #666666 } /* Literal.Number.Integer */
+.highlight .mo { color: #666666 } /* Literal.Number.Oct */
+.highlight .sb { color: #BB4444 } /* Literal.String.Backtick */
+.highlight .sc { color: #BB4444 } /* Literal.String.Char */
+.highlight .sd { color: #BB4444; font-style: italic } /* Literal.String.Doc */
+.highlight .s2 { color: #BB4444 } /* Literal.String.Double */
+.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+.highlight .sh { color: #BB4444 } /* Literal.String.Heredoc */
+.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+.highlight .sx { color: #008000 } /* Literal.String.Other */
+.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
+.highlight .s1 { color: #BB4444 } /* Literal.String.Single */
+.highlight .ss { color: #B8860B } /* Literal.String.Symbol */
+.highlight .bp { color: #AA22FF } /* Name.Builtin.Pseudo */
+.highlight .vc { color: #B8860B } /* Name.Variable.Class */
+.highlight .vg { color: #B8860B } /* Name.Variable.Global */
+.highlight .vi { color: #B8860B } /* Name.Variable.Instance */
+.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
View
2  examples/pygments.ru
@@ -4,7 +4,7 @@ require 'app'
use Rack::ShowExceptions
use Rack::Lint
-require 'pygments'
+require 'rygments'
use Rack::Codehighlighter, :pygments, :element => "pre", :pattern => /\A:::([-_+\w]+)\s*\n/, :logging => true
run Sinatra::Application
View
3  lib/rack/codehighlighter.rb
@@ -135,7 +135,8 @@ def pygments(string)
if refs
lang = refs[1]
str = unescape_html(string.sub(@opts[:pattern], ""))
- Pygments.highlight(str, :lexer => lang, :formatter => 'html')
+ #Pygments.highlight(str, :lexer => lang, :formatter => 'html')
+ Rygments.highlight_string(str, lang, 'html')
else
"<pre>#{string}</pre>"
end
View
2  rack-codehighlighter.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = "rack-codehighlighter"
- s.version = "1.0.0"
+ s.version = "0.5.0"
s.platform = Gem::Platform::RUBY
s.authors = ["Włodek Bzyl"]
s.email = ["matwb@ug.edu.pl"]
Please sign in to comment.
Something went wrong with that request. Please try again.