Need a Java-based HTML prettifier to clean up Velo

2019-04-30 00:41发布

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!

4条回答
冷血范
2楼-- · 2019-04-30 00:48

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

查看更多
姐就是有狂的资本
3楼-- · 2019-04-30 00:58

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

查看更多
我想做一个坏孩纸
4楼-- · 2019-04-30 01:01

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.

查看更多
倾城 Initia
5楼-- · 2019-04-30 01:07

JTidy could be what you're searching for.

查看更多
登录 后发表回答