src/main/java/com/formentor/magnolia/mltranslation/parser/HtmlToPlainText.java
// appends text to the string builder with a simple word wrap method
appends text to the string builder with a simple word wrap method
appends text to the string builder with a simple word wrap method
private void append(String text) {
            if (text.startsWith("\n"))
                width = 0; 
            if (text.equals(" ") &&
                    (accum.length() == 0 || StringUtil.in(accum.substring(accum.length() - 1), " ", "\n")))
                return; 
            if (text.length() + width > maxWidth) { 
                String[] words = text.split("\\s+");
                for (int i = 0; i < words.length; i++) {
                    String word = words[i];
                    boolean last = i == words.length - 1;
                    if (!last) 
                        word = word + " ";
                    if (word.length() + width > maxWidth) { 
                        accum.append("\n").append(word);
                        width = word.length();
                    } else {
                        accum.append(word);
                        width += word.length();
                    }
                }
            } else { 
                accum.append(text);
                width += text.length();
            }
        }
private void append ( String text ) { if ( text . startsWith ( "\n" ) ) width = 0 ; if ( text . equals ( " " ) && ( accum . length ( ) == 0 || StringUtil . in ( accum . substring ( accum . length ( ) - 1 ) , " " , "\n" ) ) ) return ; if ( text . length ( ) + width > maxWidth ) { String [ ] words = text . split ( "\\s+" ) ; for ( int i = 0 ; i < words . length ; i ++ ) { String word = words [ i ] ; boolean last = i == words . length - 1 ; if ( ! last ) word = word + " " ; if ( word . length ( ) + width > maxWidth ) { accum . append ( "\n" ) . append ( word ) ; width = word . length ( ) ; } else { accum . append ( word ) ; width += word . length ( ) ; } } } else { accum . append ( text ) ; width += text . length ( ) ; } }
appends text to the string builder with a simple word wrap method
appends text to the string builder with a simple word wrap method
// reset counter if starts with a newline. only from formats above, not in natural text // don't accumulate long runs of empty spaces // won't fit, needs to wrap // insert a space if not the last word // wrap and reset counter // fits as is, without need to wrap text