Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need a Java-based HTML prettifier to clean up Velocity-generated HTML

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!

like image 831
ubermensch Avatar asked Feb 17 '10 00:02

ubermensch


4 Answers

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

like image 139
BalusC Avatar answered Oct 12 '22 14:10

BalusC


JTidy could be what you're searching for.

like image 40
PATRY Guillaume Avatar answered Oct 12 '22 14:10

PATRY Guillaume


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.

like image 1
A. Ionescu Avatar answered Oct 12 '22 14:10

A. Ionescu


There are many HTML parsers here: Open Source HTML Parsers in Java

like image 1
ArturoTena Avatar answered Oct 12 '22 13:10

ArturoTena