# Ruby code colorizer

**URL:** <https://www.ruby-forum.com/t/ruby-code-colorizer/97308>\
**Category:** Rails\
**Created:** [July 6, 2006, 9:35am UTC](https://www.ruby-forum.com/t/ruby-code-colorizer/97308 "2006-07-06T09:35:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@johnny](https://www.ruby-forum.com/u/johnny)\
**Post date:** [July 6, 2006, 9:35am UTC](https://www.ruby-forum.com/t/ruby-code-colorizer/97308/1 "2006-07-06T09:35:42Z")

</div>

Hi,

Does anyone know of a html code colorizer for ruby source code?  
Ideally a typo plugin 🙂

Regards, Jason

---

<div class="post-metadata">

**Author:** ![johnny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@johnny](https://www.ruby-forum.com/u/johnny)\
**Post date:** [July 6, 2006, 5:17pm UTC](https://www.ruby-forum.com/t/ruby-code-colorizer/97308/2 "2006-07-06T17:17:25Z")

</div>

On Thu, Jul 06, 2006, Jason Hyland wrote:

> Hi,
> 
> Does anyone know of a html code colorizer for ruby source code?  
> Ideally a typo plugin 🙂

If you have the syntax gem installed, Typo already does this:

\<typo:code lang=“ruby”\>  
some.ruby {|code| here}

Go to your Admin page’s Filters tab to learn more.

You’ll need to modify the stylesheet as mentioned elsewhere, but I  
believe the default theme has it already.

Ben

---

<div class="post-metadata">

**Author:** ![johnny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@johnny](https://www.ruby-forum.com/u/johnny)\
**Post date:** [July 6, 2006, 5:37pm UTC](https://www.ruby-forum.com/t/ruby-code-colorizer/97308/3 "2006-07-06T17:37:11Z")

</div>

On Jul 6, 2006, at 8:15 AM, Ben B. wrote:

> Go to your Admin page’s Filters tab to learn more.
> 
> You’ll need to modify the stylesheet as mentioned elsewhere, but I  
> believe the default theme has it already.
> 
> Ben

```
I have found that CodeRay[1] is faster and more flexibile then the

```

syntax gem.

Cheers-  
-Ezra

[1] [http://coderay.rubychan.de/](http://coderay.rubychan.de/)

---

<div class="post-metadata">

**Author:** ![johnny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@johnny](https://www.ruby-forum.com/u/johnny)\
**Post date:** [July 6, 2006, 1:23pm UTC](https://www.ruby-forum.com/t/ruby-code-colorizer/97308/4 "2006-07-06T13:23:54Z")

</div>

On Thu, Jul 06, 2006 at 08:33:12AM +0100, Jason Hyland wrote:  
} Hi,  
}  
} Does anyone know of a html code colorizer for ruby source code?  
} Ideally a typo plugin 🙂

gem install syntax

Then consider the following script:

#######################  
#!/usr/bin/env ruby

unless [1,2].include? ARGV.size  
$stderr.puts “Usage: #{$PROGRAM\_NAME} [file]”  
exit 1  
end

require ‘rubygems’  
require ‘syntax/convertors/html’

convertor = Syntax::Convertors::HTML.for\_syntax ARGV.shift

highlighted = convertor.convert(ARGF.read)  
highlighted.sub!(/^

```
/, “<pre class="code">\n”)
puts highlighted
#######################

You’ll need appropriate CSS defined for it. I use the following, derived  
from Vim highlighting:

pre.code span.keyword { color: rgb(165, 42, 42); }  
pre.code span.module, pre.code span.class { color: rgb(160, 32, 240); }  
pre.code span.punct { color: rgb(106, 90, 205); }  
pre.code span.ident { color: rgb(0, 0, 0); }  
pre.code span.method { color: rgb(0, 139, 139); }  
pre.code span.string { color: rgb(255, 0, 255); }  
pre.code span.number { color: rgb(255, 0, 255); }  
pre.code span.constant { color: rgb(0, 139, 139); }

This is what I use for my (shameless plug!) blog at  
[redcorundum.blogspot.com](http://redcorundum.blogspot.com). There you go!

} Regards, Jason  
–Greg
```
