[英]Preserving the <br> tags when cleaning with Jsoup
对于输入文本:
<p>Arbit string <b>of</b><br><br>text. <em>What</em> to <strong>do</strong> with it?
我运行以下代码:
Whitelist list = Whitelist.simpleText().addTags("br");
// Some other code...
// plaintext is the string shown above
retVal = Jsoup.clean(plaintext, StringUtils.EMPTY, list,
new Document.OutputSettings().prettyPrint(false));
我得到的输出:
Arbit string <b>of</b>
text. <em>What</em> to <strong>do</strong> with it?
我不希望Jsoup将<br>
标记转换为换行符,我想保持它们的原样。 我怎样才能做到这一点?
尝试这个:
Document doc2deal = Jsoup.parse(inputText);
doc2deal.select("br").append("br"); //or append("<br>")
这对我来说是不可复制的。 使用Jsoup 1.8.3和以下代码:
String html = "<p>Arbit string <b>of</b><br><br>text. <em>What</em> to <strong>do</strong> with it?";
String cleaned = Jsoup.clean(html,
"",
Whitelist.simpleText().addTags("br"),
new Document.OutputSettings().prettyPrint(false));
System.out.println(cleaned);
我得到以下输出:
Arbit string <b>of</b><br><br>text. <em>What</em> to <strong>do</strong> with it?
我想您的问题可能在其他地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.