@Test public void tableShouldBeWellHandled() { String html = " <table style=\"width:100%\">\n" + " <tr>\n" + " <th>Firstname</th>\n" + " <th>Lastname</th>\n" + " <th>Age</th>\n" + " </tr>\n" + " <tr>\n" + " <td>Jill</td>\n" + " <td>Smith</td>\n" + " <td>50</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Eve</td>\n" + " <td>Jackson</td>\n" + " <td>94</td>\n" + " </tr>\n" + "</table> "; String expectedPlainText = "\n" + " \n" + " Firstname\n" + " Lastname\n" + " Age\n" + " \n" + " \n" + " Jill\n" + " Smith\n" + " 50\n" + " \n" + " \n" + " Eve\n" + " Jackson\n" + " 94\n" + " \n" + " "; assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText); }
@Override public String toPlainText(String html) { try { Document document = Jsoup.parse(html); Element body = Optional.ofNullable(document.body()).orElse(document); return flatten(body, INITIAL_LIST_NESTED_LEVEL) .map(this::convertNodeToText) .reduce("", (s1, s2) -> s1 + s2); } catch (Exception e) { LOGGER.warn("Failed extracting text from html", e); return html; } }
JsoupHtmlTextExtractor implements HtmlTextExtractor { @Override public String toPlainText(String html) { try { Document document = Jsoup.parse(html); Element body = Optional.ofNullable(document.body()).orElse(document); return flatten(body, INITIAL_LIST_NESTED_LEVEL) .map(this::convertNodeToText) .reduce("", (s1, s2) -> s1 + s2); } catch (Exception e) { LOGGER.warn("Failed extracting text from html", e); return html; } } }
JsoupHtmlTextExtractor implements HtmlTextExtractor { @Override public String toPlainText(String html) { try { Document document = Jsoup.parse(html); Element body = Optional.ofNullable(document.body()).orElse(document); return flatten(body, INITIAL_LIST_NESTED_LEVEL) .map(this::convertNodeToText) .reduce("", (s1, s2) -> s1 + s2); } catch (Exception e) { LOGGER.warn("Failed extracting text from html", e); return html; } }  }
JsoupHtmlTextExtractor implements HtmlTextExtractor { @Override public String toPlainText(String html) { try { Document document = Jsoup.parse(html); Element body = Optional.ofNullable(document.body()).orElse(document); return flatten(body, INITIAL_LIST_NESTED_LEVEL) .map(this::convertNodeToText) .reduce("", (s1, s2) -> s1 + s2); } catch (Exception e) { LOGGER.warn("Failed extracting text from html", e); return html; } }  @Override String toPlainText(String html); }
JsoupHtmlTextExtractor implements HtmlTextExtractor { @Override public String toPlainText(String html) { try { Document document = Jsoup.parse(html); Element body = Optional.ofNullable(document.body()).orElse(document); return flatten(body, INITIAL_LIST_NESTED_LEVEL) .map(this::convertNodeToText) .reduce("", (s1, s2) -> s1 + s2); } catch (Exception e) { LOGGER.warn("Failed extracting text from html", e); return html; } }  @Override String toPlainText(String html); static final String BR_TAG; static final String UL_TAG; static final String OL_TAG; static final String LI_TAG; static final String P_TAG; static final String IMG_TAG; static final String ALT_TAG; static final int INITIAL_LIST_NESTED_LEVEL; }