textile + ruby + programming = ugly mess

I'm trying to get proper html for tags in index, but it's difficult. This don't work, but I wanted to preserve it before moving on…
***WARNING: Ugly Code **** Getting tags to display in the same way on blog/index page as on single blog post pages.

This is probably the ugliest code I have ever committed. The comment, wrapped as a javascript, says it all...