views:

204

answers:

4

Hello,

Web app I'm working on generates HTML using Velocity templates. Problem is that using whitespace in velocity templates and other formatting results in butt-ugly HTML (excessive whitespace, misalignment, etc.)

Looking for a nice (single jar packaging would be nice) Java-based HTML prettifier to run over the generated HTML right before we dump it to the servlet response to make the source nicer to look at.

Third party integrators would like to be able to glance at the HTML and know which templates are causing problems. The first step to this is having the HTML formatted nicely.

Thanks in advance for any guidance you can provide!

+2  A: 

JTidy could be what you're searching for.

regards,
Guillaume

PATRY
+4  A: 

JTidy has a JTidyFilter. Just define it in web.xml and the respone HTML will be prettified.

BalusC
+1  A: 

There are many HTML parsers here: link text

Arturo Tena
+1  A: 

I know it's not helping right now, but I think the ideal solution would be for Velocity in first place to support a "better whitespace generation and control" :).

If many users would request and vote such a feature, maybe the Velocity team would include it. Running jTidy or other parsers over the output all the time (e.g. for live requests) consumes quite a few resources, so I'm not sure if it's the best approach especially for dynamic content where caching of that cleaned output doesn't bring much.

A. Ionescu