保留< br>使用Jsoup清洁时的标签 [英] Preserving the <br> tags when cleaning with Jsoup

查看:179
本文介绍了保留< br>使用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>标记转换为换行符,我想保持它们的原样.我该怎么办?

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?

推荐答案

尝试一下:

Document doc2deal = Jsoup.parse(inputText);
doc2deal.select("br").append("br"); //or append("<br>")

这篇关于保留&lt; br&gt;使用Jsoup清洁时的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆