# Color syntax for ruby code in Typo

**URL:** <https://www.ruby-forum.com/t/color-syntax-for-ruby-code-in-typo/47944>\
**Category:** Rails\
**Created:** [November 13, 2005, 11:02pm UTC](https://www.ruby-forum.com/t/color-syntax-for-ruby-code-in-typo/47944 "2005-11-13T23:02:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hipertracker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/58f4c7/32.png) [@hipertracker](https://www.ruby-forum.com/u/hipertracker)\
**Post date:** [November 13, 2005, 11:02pm UTC](https://www.ruby-forum.com/t/color-syntax-for-ruby-code-in-typo/47944/1 "2005-11-13T23:02:28Z")

</div>

Do you know how get color syntax for Ruby code snippets in Typo? It is  
possible, but I do not know how:  
[http://scottstuff.net/blog/articles/tag/](http://scottstuff.net/blog/articles/tag/)

Is it possible for Typo to get color syntax for other languages,  
Python, PHP, etc?

–  
JZ

---

<div class="post-metadata">

**Author:** ![hipertracker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/58f4c7/32.png) [@hipertracker](https://www.ruby-forum.com/u/hipertracker)\
**Post date:** [November 14, 2005, 1:26am UTC](https://www.ruby-forum.com/t/color-syntax-for-ruby-code-in-typo/47944/2 "2005-11-14T01:26:40Z")

</div>

It’s so easy to do color syntax formatting with the syntax gem. I  
recently added this feature to the app on working on so here’s my 4  
steps.

1. install the gem…

gem install syntax

1. Add the following require statements to the environment.rb file of  
your Rails app:

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

1. Write yourself a helper method that does the conversion and  
conveniently wraps the resulting html in a div, for example…

def ruby\_to\_html(script\_str)  
convertor = Syntax::Convertors::HTML.for\_syntax(‘ruby’)  
return %(

#{convertor.convert(script\_str)}
)  
end

1. Include a copy of ruby syntax css file in your application, for  
example [http://syntax.rubyforge.org/stylesheets/ruby.css](http://syntax.rubyforge.org/stylesheets/ruby.css)

Hope it helps,  
Obie

---

<div class="post-metadata">

**Author:** ![hipertracker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/58f4c7/32.png) [@hipertracker](https://www.ruby-forum.com/u/hipertracker)\
**Post date:** [November 14, 2005, 4:12am UTC](https://www.ruby-forum.com/t/color-syntax-for-ruby-code-in-typo/47944/3 "2005-11-14T04:12:00Z")

</div>

It’s even easier than that in Typo. I’m running 2.5.5, and this is what  
I  
add:

\<typo:code lang=“ruby”\>  
\</typo:code\>

If you click on the ‘filters’ tab in the admin pages, you’ll see what  
code  
filters you’ve got installed. Also, the theme CSS needs to have the  
correct  
entries for the typocode classes - the built in azure theme does, the  
orange  
theme does not.
