Java Code Examples for org.jsoup.examples.HtmlToPlainText

The following examples show how to use org.jsoup.examples.HtmlToPlainText. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: zest-writer   Author: firm1   File: Corrector.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String checkHtmlContent(String htmlContent) {
    AnnotatedText markup = makeAnnotatedText(htmlContent);
    StringBuilder bf = new StringBuilder(htmlContent);

    langTool.getAllActiveRules().stream().filter(rule -> rule instanceof SpellingCheckRule).forEach(rule -> ((SpellingCheckRule) rule).acceptPhrases(wordsToIgnore));

    List<RuleMatch> matches = new ArrayList<>();
    try {
        matches = langTool.check(markup);
    }
    catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    int offset = 0;
    for (RuleMatch match : matches) {
        String desc = match.getMessage();
        desc = new HtmlToPlainText().getPlainText(Jsoup.parse(desc));

        if (!match.getSuggestedReplacements().isEmpty()) {
            desc += Configuration.getBundle().getString("ui.alert.correction.tooltip.suggestion")
                    + match.getSuggestedReplacements();
        }
        String before = "<span class=\"error-french\" title=\"" + desc + "\">";
        bf.insert(match.getFromPos() + offset, before);
        offset += before.length();

        String after = "</span> ";
        bf.insert(match.getToPos() + offset, after);
        offset += after.length();

    }
    return bf.toString();
}
 
Example #2
Source Project: quickperf   Author: quick-perf   File: HtmlToPlainTextTransformer.java    License: Apache License 2.0 4 votes vote down vote up
public String convertHtmlToPlainText(String html) {
    HtmlToPlainText htmlToPlainText = new HtmlToPlainText();
    Document jsoupDocument = Jsoup.parse(html);
    jsoupDocument.select("p").prepend("<br>");
    return htmlToPlainText.getPlainText(jsoupDocument);
}
 
Example #3
Source Project: zongtui-webcrawler   Author: zongtui   File: ElementOperator.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public String operate(Element element) {
    return new HtmlToPlainText().getPlainText(element);
}
 
Example #4
Source Project: xsoup   Author: code4craft   File: ElementOperator.java    License: MIT License 4 votes vote down vote up
@Override
public String operate(Element element) {
    return new HtmlToPlainText().getPlainText(element);
}