class JSoupTextExtractor implements HtmlTextExtractor {

	@Override
	public String getPlaintext(final String htmltext) {
		try {
			// preserve newlines
			// html = html.replaceAll("(?i)<br[^>]*>", "br2nl"); // <br>s are often just inserted for style
			String hhtmltext = _end_prgrph_ptrn.matcher(htmltext).replaceAll("</p>br2nl");
			hhtmltext = _nwln_ptrn.matcher(hhtmltext).replaceAll("br2nl");

			Document soup = Jsoup.parse(hhtmltext);
			String plaintext = soup.text();

			plaintext = _tmp_nwln_ptrn.matcher(plaintext).replaceAll("\n");
			plaintext = _emptln_ptrn.matcher(plaintext.trim()).replaceAll("");

			return plaintext;
		} catch (Throwable t) {
			for (int i = 1; t != null && i < 10; i++) {
				LOG.log(Level.SEVERE, String.format("Failed to get plaintext from while '%s' (%d %s:%s).", StringUtils.abbreviate(htmltext, 100), i, t.getClass().getName(), t.getMessage()), t);
				t = t.getCause();
			}
			return "Failed to get plaintext content \n" + htmltext;
		}
	}

}