# Low level syntax highlighting tools?

**URL:** <https://www.ruby-forum.com/t/low-level-syntax-highlighting-tools/151231>\
**Category:** Ruby\
**Created:** [October 18, 2008, 5:42pm UTC](https://www.ruby-forum.com/t/low-level-syntax-highlighting-tools/151231 "2008-10-18T17:42:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [October 18, 2008, 5:42pm UTC](https://www.ruby-forum.com/t/low-level-syntax-highlighting-tools/151231/1 "2008-10-18T17:42:53Z")

</div>

I’ll confess I didn’t research this deeply, in hopes that someone  
knows of a library and can point me right at it.

Are there any syntax gems out there that’ll spit back simple strings  
and color values,  
something like:

[[“def foo\n”, “ccffcc”], [" bar()\n", “ffffff”], [“end”, “ccffcc”]]

If such a tool exists, I can rejoice, because it’d allow me to build  
an awsum Prawn based presentation builder.

-greg

---

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [October 18, 2008, 6:13pm UTC](https://www.ruby-forum.com/t/low-level-syntax-highlighting-tools/151231/2 "2008-10-18T18:13:21Z")

</div>

2008/10/18 Gregory B. :

> I’ll confess I didn’t research this deeply, in hopes that someone  
> knows of a library and can point me right at it.
> 
> Are there any syntax gems out there that’ll spit back simple strings  
> and color values,  
> something like:
> 
> [[“def foo\n”, “ccffcc”], [" bar()\n", “ffffff”], [“end”, “ccffcc”]]

I guess no, but if you’re using a syntax-colorizing, I think the  
thing to do is using the scanner/tokenizer part, that will yield you  
tokens for a specified language, and then you just have to create  
your own class of Encoder/Converter that will consume tokens  
and generate what you need, here an array like you want. It should  
be easy, for example, with CodeRay [1] : write your encoder, and  
don’t use the html encoder.

> If such a tool exists, I can rejoice, because it’d allow me to build  
> an awsum Prawn based presentation builder.

Very interesting. I was also thinking of using Prawn to generate  
slides.

– Jean-François.

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

---

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [October 18, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/low-level-syntax-highlighting-tools/151231/3 "2008-10-18T18:30:59Z")

</div>

On Sat, Oct 18, 2008 at 12:11 PM, Jean-François  
Trân[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I guess no, but if you’re using a syntax-colorizing, I think the  
> thing to do is using the scanner/tokenizer part, that will yield you  
> tokens for a specified language, and then you just have to create  
> your own class of Encoder/Converter that will consume tokens  
> and generate what you need, here an array like you want. It should  
> be easy, for example, with CodeRay [1] : write your encoder, and  
> don’t use the html encoder.

Cool, I’ll look into this, thanks.

> > If such a tool exists, I can rejoice, because it’d allow me to build  
> > an awsum Prawn based presentation builder.
> 
> Very interesting. I was also thinking of using Prawn to generate  
> slides.

This code is very old, but will eventually be replaced with modernized  
Prawn code:

> **[GitHub - practicingruby/brine: Simple presentation software based on Prawn](https://github.com/practicingruby/brine/tree/master)**
>
> master

If you’re thinking of working on this, you’re welcome to fork this  
repos so that we don’t duplicate effort.

---

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [October 18, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/low-level-syntax-highlighting-tools/151231/4 "2008-10-18T18:33:55Z")

</div>

On Oct 18, 2008, at 9:41 AM, Gregory B. wrote:

> an awsum Prawn based presentation builder.
> 
> -greg

it seems like using Hpricot against one of the current highlighters  
would work - just skim out innerHTML/class pairs right?

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![naething](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@naething](https://www.ruby-forum.com/u/naething)\
**Post date:** [October 18, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/low-level-syntax-highlighting-tools/151231/5 "2008-10-18T18:45:05Z")

</div>

On Sat, Oct 18, 2008 at 12:32 PM, ara.t.howard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > [[“def foo\n”, “ccffcc”], [" bar()\n", “ffffff”], [“end”, “ccffcc”]]
> > 
> > If such a tool exists, I can rejoice, because it’d allow me to build  
> > an awsum Prawn based presentation builder.
> > 
> > -greg
> 
> it seems like using Hpricot against one of the current highlighters would  
> work - just skim out innerHTML/class pairs right?

Hmm… that’s an interesting idea too. I’ll take a quick look at how  
easy it is to get under the hood of Code Ray, and if it seems  
complicated, such a hack would probably do fine.

-greg
