Don’t show line breaks in post excerpts.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 22 Jul 2011 21:43:38 +0000 (23:43 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 22 Jul 2011 21:43:38 +0000 (23:43 +0200)
This resolves #220.

src/main/java/net/pterodactylus/sone/template/ParserFilter.java

index 74641e9..332f504 100644 (file)
@@ -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;
        }
 
 }