# Syntax highlighting library

**URL:** <https://www.ruby-forum.com/t/syntax-highlighting-library/94408>\
**Category:** Ruby\
**Created:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/syntax-highlighting-library/94408 "2006-05-03T18:59:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor123789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@victor123789](https://www.ruby-forum.com/u/victor123789)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/syntax-highlighting-library/94408/1 "2006-05-03T18:59:08Z")

</div>

Hello all.

Does some good subj exists?  
If no, maybe it would be useful If I’ll port GeShi[1]?

Victor.

1. [GeSHi - Generic Syntax Highlighter :: Home](http://qbnz.com/highlighter/index.php)

---

<div class="post-metadata">

**Author:** ![victor123789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@victor123789](https://www.ruby-forum.com/u/victor123789)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/syntax-highlighting-library/94408/2 "2006-05-03T18:59:27Z")

</div>

On 5/2/06, Victor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Does some good subj exists?

Try Syntax [http://rubyforge.org/projects/syntax](http://rubyforge.org/projects/syntax) or  
CodeRay[http://rd.cycnus.de/coderay/](http://rd.cycnus.de/coderay/)  
.

- Dimitri

---

<div class="post-metadata">

**Author:** ![victor123789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@victor123789](https://www.ruby-forum.com/u/victor123789)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/syntax-highlighting-library/94408/3 "2006-05-03T18:59:57Z")

</div>

On Tue, 2 May 2006, Dimitri A. wrote:

> - Dimitri  
> this simple script will convert any src file, including fortran, c++,  
> java,  
> etc, to html:

harp:~ \> cat a.rb

#!/usr/bin/env ruby  
require ‘tempfile’  
$VERBOSE=nil  
STDERR.reopen(Tempfile::new($$)) unless STDIN.tty?

fin, fout, \_ = ARGV  
fin = ((fin.nil? or fin == ‘-’) ? STDIN : open(fin))  
fout = ((fout.nil? or fout == ‘-’) ? STDOUT : open(fout,‘w+’))

ts = Tempfile::new($$), Tempfile::new($$)  
ts[0].write fin.read  
ts.each{|t| t.close}  
command = %Q( vim -f +‘syn on’ +‘set filetype=ruby’ +‘set  
background=light’ +‘run! syntax/2html.vim’ +‘w! #{ ts[1].path }’ +‘qa!’

- \< #{ ts[0].path } \> /dev/null 2\>&1 )  
system command  
ts.each{|t| t.open; t.rewind}  
fout.write(ts[1].read)  
ts.each{|t| t.close!}

the ‘set filetype=ruby’ functions only as a default. for instance this

ruby a.rb src.c src.html

does the right thing.

regards.

-a

---

<div class="post-metadata">

**Author:** ![victor123789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@victor123789](https://www.ruby-forum.com/u/victor123789)\
**Post date:** [May 3, 2006, 7:06pm UTC](https://www.ruby-forum.com/t/syntax-highlighting-library/94408/4 "2006-05-03T19:06:10Z")

</div>

> Dimitri A. wrote:
> 
> Try Syntax [http://rubyforge.org/projects/syntax](http://rubyforge.org/projects/syntax) or  
> CodeRay[http://rd.cycnus.de/coderay/](http://rd.cycnus.de/coderay/)

Unfortunally, they noth have very poor base of ready language files and  
rather complicated mechanism for defining new ones.

> From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]
> 
> this simple script will convert any src file, including fortran, c++,  
> java,  
> etc, to html:

…

> command = %Q( vim -f +‘syn on’ +‘set filetype=ruby’ +‘set  
> background=light’ +‘run! syntax/2html.vim’ +‘w! #{ ts[1].path }’ +‘qa!’ -  
> \< #{ ts[0].path } \> /dev/null 2\>&1 )

Not very universal solution. At least requires vim installed (which  
seams to  
be _very_ uncommon on non-Unix systems 😉

V.
