我的问题是jsoup破坏了我的HTML代码。我正在从url下载网站,稍微更改一下并在WebView中显示它。
Jsoup向代码添加格式化并导致问题:
之前 html:http://jsfiddle.net/zr3xtus9/
<div class="ctr-element"><div class="ctr-content" style="z-index: 100; margin: 0px; left: 0px; top: 0px; visibility: visible; position: relative;"><div class="ctr-textWrapper" style="text-align: center; line-height: 1; font-size: 124px;" spellcheck="false"><span style="font-size: 124px; color: rgb(245, 230, 93); font-family: capture_it_2;" id="object13textContainer0"> P</span><span style="font-size: 124px; color: rgb(245, 230, 93); font-family: capture_it_2;" id="object13textContainer1">arty</span></div></div></div>
后 html:http://jsfiddle.net/5kv47sny/
<div class="ctr-element">
<div class="ctr-content" style="z-index: 100; margin: 0px; left: 0px; top: 0px; visibility: visible; position: relative;">
<div class="ctr-textWrapper" style="text-align: center; line-height: 1; font-size: 124px;" spellcheck="false">
<span style="font-size: 124px; color: rgb(245, 230, 93); font-family: capture_it_2;" id="object13textContainer0" onclick="javscript:changeText('object13textContainer0')"> P</span>
<span style="font-size: 124px; color: rgb(245, 230, 93); font-family: capture_it_2;" id="object13textContainer1" onclick="javscript:changeText('object13textContainer1')">arty</span>
</div>
</div>
</div>
正如您所见,jsoup添加了额外的空格作为文本缩进。怎么避免这个?
答案 0 :(得分:3)
解决方案非常简单。要禁用文本缩进,我在打印html之前使用了此代码:
doc.outputSettings().prettyPrint(false);
以下是文档:http://jsoup.org/apidocs/org/jsoup/nodes/Document.OutputSettings.html#prettyPrint(boolean)