1

I have a string like this:

"noun<br> an expression of greeting <br>- every morning they exchanged polite hellos<br> <font color=dodgerblue> ••</font> Syn:  hullo,  hi,  howdy,  how-do-you-do<be>"

want to show it in a label as a rich text. for example Instead of <br> tags, text must go to the next line.

in Android we can do that with:

Html.fromHtml(myHtmlString)

but I don't know how to do it in libgdx. I try to use Jsoup but it removes all tags and does not go to the next line for <br> tag for example.

Jsoup.parse(myHtmlString).text()
Hadi Ahmadi
  • 1,924
  • 2
  • 17
  • 38

3 Answers3

0

Jsoup.parse returns a document containing many elements -of- strings. Not a single string so you are only seeing the first bit. You can assemble the complete string yourself by going through the elements or try

Document doc = Jsoup.parse(yourHtmlInput);
String htmlString = doc.toString();
londonBadger
  • 611
  • 2
  • 5
  • 5
0
String htmlText = "<p>This is an <strong>Example</strong></p>";

//this will convert your HTML text into normal text
String normalText = Jsoup.parse(htmlText).text();
greybeard
  • 2,249
  • 8
  • 30
  • 66
0

in kotlin i use this code:

                var definition = "my html string"
                definition = definition.replace("<br>", "\n")
                definition = definition.replace("<[^>]*>".toRegex(), "")
Hadi Ahmadi
  • 1,924
  • 2
  • 17
  • 38