2016-06-03 2 views
0

Java 코드를 통해 html 페이지를 축소하려고합니다. 압축을 수행하려면 https://code.google.com/archive/p/htmlcompressor/을 사용하고 있습니다.HtmlCompressor를 사용하여 HTML에서 인라인 CSS를 축소하는 방법은 무엇입니까?

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를 사용하여 축소 된 할 수 있습니까? 그렇지 않다면 그것을하는 다른 라이브러리가 있습니까?

답변

0

간단한 자바는 문자열 객체에 교체

String html_new = html.replace(': ' , ':').replace('; ' , ';'); 

return html_new;