} catch (NumberFormatException nfe1) {
/* ignore. */
}
- if (length == -1) {
+ if ((length == -1) && (parameters.get("length") != null)) {
try {
length = Integer.parseInt(String.valueOf(templateContext.get(parameters.get("length"))));
} catch (NumberFormatException nfe1) {
* @return The excerpt of the text
*/
private static String getExcerpt(String text, int length) {
- if (text.length() > length) {
- return text.substring(0, length) + "…";
+ String filteredText = text.replaceAll("(\r\n)+", "\r\n").replaceAll("\n+", "\n").replace("\r\n", " ").replace('\n', ' ');
+ if (filteredText.length() > length) {
+ return filteredText.substring(0, length) + "…";
}
- return text;
+ return filteredText;
}
}