[英]How to minify inline css in an html using HtmlCompressor?
我试图通过我的Java代码来缩小html页面。 我正在使用https://code.google.com/archive/p/htmlcompressor/进行压缩。
这是我的缩小方法:
public static String minifyHtml(String html) {
HtmlCompressor htmlCompressor = new HtmlCompressor();
htmlCompressor.setRemoveSurroundingSpaces(HtmlCompressor.ALL_TAGS);
htmlCompressor.setPreserveLineBreaks(false);
htmlCompressor.setCompressCss(true);
return htmlCompressor.compress(document.toString());
}
但是,这不能使我在html中的内联CSS最小化。 例如,以下标记:
<div class="content" style="font-family: Helvetica,sans-serif,Lucida Sans Unicode; font-size: 12pt; font-weight: normal; font-style: normal; text-decoration: none; color: rgb(0,0,0); background-color: transparent; margin-top: 0.0pt; margin-bottom: 0.0pt; text-indent: 0.0in; margin-left: 0.0in; margin-right: 0.0in; text-align: left; border-style: none; border-width: 0.0pt; border-color: rgb(0,0,0); padding: 0.0pt; white-space: pre-wrap;">
可以使用HtmlCompressor将其缩小吗? 如果不是,那么还有其他库吗?
简单的Java替换字符串对象
String html_new = html.replace(': ' , ':').replace('; ' , ';');
return html_new;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.