HTML 到格式化文本
是否有任何 java API 可以像 Android 中的 Html.fromHtml() 那样执行类似的操作? JSoup 确实解析并删除了标签,但输出不是格式化的。 例如:
<ol type="1">
<li>Test1</li>
<ol type="a">
<li>TestA1</li>
<li>TestB1</li>
</ol>
<li>Test2</li>
<ol type="a">
<li>TestA2</li>
<li>TestB2</li>
</ol>
</ol>
应该给我类似
Test1
的内容a.测试A1
b.测试B1
测试2
a.测试A2
b.测试B2
Are there any java APIs which does similar action like Html.fromHtml() as in Android? JSoup does parse and remove the tags but the output is not a formatted one.
eg:
<ol type="1">
<li>Test1</li>
<ol type="a">
<li>TestA1</li>
<li>TestB1</li>
</ol>
<li>Test2</li>
<ol type="a">
<li>TestA2</li>
<li>TestB2</li>
</ol>
</ol>
should give me something like
Test1
a. TestA1
b. TestB1
Test2
a. TestA2
b. TestB2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有用于jsoup-to-"formatted text"的API,但您可以自己转换列表:
ul
/ol
元素的示例:
在此示例中,我使用
type< /code> 属性来确定需要哪种类型的项目符号并使用字符 (!) 来索引项目。如果没有正确的属性,则使用 char
1
。实现:
测试代码:
结果:
输入 (HTML):
输出:
就是这样! :-)
There's no api for jsoup-to-"formated text", but you can convert lists by your own:
ul
/ol
element which is the root of the listExample:
In this example i use the
type
attribute to determine what kind of bullet is required and use the character (!) to index the items. If there's no proper attribute, char1
is used.Implementation:
Testcode:
Result:
Input (HTML):
Output:
Thats it! :-)