From 24d75cd307eddb3b9b94bcc8e343f85cfcc1f7f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 22 Jul 2011 23:43:38 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20show=20line=20breaks=20in=20post?= =?utf8?q?=20excerpts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This resolves #220. --- src/main/java/net/pterodactylus/sone/template/ParserFilter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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; } } -- 2.7.4