@Test public void toPlainTextShouldReplaceSkipLine() { String html = "<p>This is an<br/>HTML text !</p>"; String expectedPlainText = "This is an\nHTML text !\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; }