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
There’s no api for jsoup-to-“formated text”, but you can convert lists by your own:
ul/olelement which is the root of the listExample:
In this example i use the
typeattribute to determine what kind of bullet is required and use the character (!) to index the items. If there’s no proper attribute, char1is used.Implementation:
Testcode:
Result:
Input (HTML):
Output:
Thats it! 🙂