From: David ‘Bombe’ Roden Date: Fri, 22 Jul 2011 21:43:38 +0000 (+0200) Subject: Don’t show line breaks in post excerpts. X-Git-Tag: 0.6.6^2~7 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=24d75cd307eddb3b9b94bcc8e343f85cfcc1f7f2;p=Sone.git Don’t show line breaks in post excerpts. This resolves #220. --- diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index 74641e9..332f504 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -286,10 +286,11 @@ public class ParserFilter implements Filter { * @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; } }