src/main/java/rocks/coffeenet/frontpage/plugin/feed/Parser.java
default String reduceText(String text, int maxLength) {

        String html = Jsoup.parse(text).body().html();

        if (html.length() <= maxLength) {
            return html;
        }

        Element bodyCropped = Jsoup.parse(text.substring(0, maxLength)).body();
        int textToHtmlDiff = bodyCropped.html().length() - bodyCropped.text().length();

        int minLengthToCrop = min(maxLength + textToHtmlDiff, html.length());
        String substring = html.substring(0, minLengthToCrop);

        int lastStartA = substring.lastIndexOf("<a");
        int lastCloseA = substring.lastIndexOf("</a>");

        int nextAfterLastCloseA = html.indexOf("</a>", lastStartA);

        if (lastStartA > lastCloseA) {
            substring = html.substring(0, nextAfterLastCloseA + "</a>".length());
        }

        return substring + "...";
    }
/**
     * Reduces a text.
     *
     * @param text      to reduce
     * @param maxLength max length of text
     * @return cropped text
     */
Reduces a text.
@param text      to reduce
@param maxLength max length of text
@return cropped text
Reduces a text . @param text to reduce @param maxLength max length of text @return cropped text
default String reduceText(String text, int maxLength) {
        String html = Jsoup.parse(text).body().html();
        if (html.length() <= maxLength) {
            return html;
        }
        Element bodyCropped = Jsoup.parse(text.substring(0, maxLength)).body();
        int textToHtmlDiff = bodyCropped.html().length() - bodyCropped.text().length();
        int minLengthToCrop = min(maxLength + textToHtmlDiff, html.length());
        String substring = html.substring(0, minLengthToCrop);
        int lastStartA = substring.lastIndexOf("<a");
        int lastCloseA = substring.lastIndexOf("</a>");
        int nextAfterLastCloseA = html.indexOf("</a>", lastStartA);
        if (lastStartA > lastCloseA) {
            substring = html.substring(0, nextAfterLastCloseA + "</a>".length());
        }
        return substring + "...";
    }
default String reduceText ( String text , int maxLength ) { String html = Jsoup . parse ( text ) . body ( ) . html ( ) ; if ( html . length ( ) <= maxLength ) { return html ; } Element bodyCropped = Jsoup . parse ( text . substring ( 0 , maxLength ) ) . body ( ) ; int textToHtmlDiff = bodyCropped . html ( ) . length ( ) - bodyCropped . text ( ) . length ( ) ; int minLengthToCrop = min ( maxLength + textToHtmlDiff , html . length ( ) ) ; String substring = html . substring ( 0 , minLengthToCrop ) ; int lastStartA = substring . lastIndexOf ( "<a" ) ; int lastCloseA = substring . lastIndexOf ( "</a>" ) ; int nextAfterLastCloseA = html . indexOf ( "</a>" , lastStartA ) ; if ( lastStartA > lastCloseA ) { substring = html . substring ( 0 , nextAfterLastCloseA + "</a>" . length ( ) ) ; } return substring + "..." ; }
Reduces a text.
Reduces a text .