保留< br>用Jsoup清洁时标签 [英] Preserve <br> tags when cleaning with Jsoup
本文介绍了保留< br>用Jsoup清洁时标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于输入文字: < / b>< br>的< b>的< b>的字符串< b> ;<峰; br>文字。 < EM>什么< / EM>到< strong>做< / strong>用它?
我运行以下代码:
Whitelist list = Whitelist.simpleText()。addTags(br);
//一些其他代码...
// plaintext是上面显示的字符串
retVal = Jsoup.clean(纯文本,StringUtils.EMPTY,列表,
新Document.OutputSettings ().prettyPrint(假));
我得到了输出:
< / b>的Arbit字符串< b>
文本。 < EM>什么< / EM>到< strong>做< / strong>用它?
我不想让Jsoup转换< br>
标签到换行符,我想保留它们原样。如何才能做到这一点?
解决方案
试试这个:
Document doc2deal = Jsoup.parse(inputText);
doc2deal.select(br)。append(br); //或追加(< br>)
For the input text:
<p>Arbit string <b>of</b><br><br>text. <em>What</em> to <strong>do</strong> with it?
I run the following code:
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));
I get the output:
Arbit string <b>of</b>
text. <em>What</em> to <strong>do</strong> with it?
I don't want Jsoup to convert the <br>
tags to line breaks, I want to keep them as-is. How can I do that?
解决方案
Try this:
Document doc2deal = Jsoup.parse(inputText);
doc2deal.select("br").append("br"); //or append("<br>")
这篇关于保留< br>用Jsoup清洁时标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文