Reputation: 43
I've used Java swing for my desktop app development. Now I'm experimenting with javaFX. Howerver I have stumbled on one issue - in swing you can easily parse html code to labels and other text components, however javaFX does not support it. So is the any java libraries that convert html code to unicode characters?
Example:
<html>N<sub>258</sub><html> --> N₂₅₈
Upvotes: 2
Views: 176
Reputation: 659
You need wither an headless HTML renderer or need to transform HTML to some other format.
You can use an embedded browser in JavaFX or you can use separate headless browser, like phantomjs.
The embedded browser option is detailed here
You can use the embedded browser trick for developing mobile apps as well, as most of the mobile OS provide embedded browsers(without chrome) in apps.
Upvotes: 0
Reputation: 3190
How about this?
import org.apache.commons.lang.StringEscapeUtils;
public class StringEscapeUtilsTrial {
public static void main(String[] args) {
String strHTMLInput = "<p>MyName<p>";
String strEscapeHTML = StringEscapeUtils.escapeHtml(strHTMLInput);
String strUnEscapeHTML = StringEscapeUtils.unescapeHtml(strEscapeHTML);
System.out.println("Escaped HTML >>> " + strEscapeHTML);
System.out.println("UnEscaped HTML >>> " + strUnEscapeHTML);
}
}
Source: Convert HTML-escaped strings to plain Unicode/ASCII
Upvotes: 1