private String _wrapText(String text, int indentLength, String exclude) { StringBuffer sb = new StringBuffer(); StringBundler regexSB = new StringBundler("(?<=^|</"); regexSB.append(exclude); regexSB.append(">).+?(?=$|<"); regexSB.append(exclude); regexSB.append(">)"); Pattern pattern = Pattern.compile(regexSB.toString(), Pattern.DOTALL); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String wrapped = _formatInlines(matcher.group()); wrapped = StringUtil.wrap(wrapped, 80 - indentLength, "\n"); matcher.appendReplacement(sb, wrapped); } matcher.appendTail(sb); return sb.toString(); }
private String _wrapText(String text, String indent) { int indentLength = _getIndentLength(indent); if (text.contains("<pre>")) { text = _wrapText(text, indentLength, "pre"); } else if (text.contains("<table>")) { text = _wrapText(text, indentLength, "table"); } else { text = _formatInlines(text); text = StringUtil.wrap(text, 80 - indentLength, "\n"); } text = text.replaceAll("(?m)^", indent); text = text.replaceAll("(?m) +$", StringPool.BLANK); return text; }