From 00be7dff1eec2c325b03b0a6bbe7b1c9c515003b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 5 Sep 2012 14:14:56 +0200 Subject: [PATCH] Create the excerpt of a linked post from the parsed plain text, not the raw text. --- .../net/pterodactylus/sone/template/ParserFilter.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index 90744e7..5f156f1 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -241,7 +241,22 @@ public class ParserFilter implements Filter { * The part to render */ private void render(Writer writer, PostPart postPart) { - renderLink(writer, "viewPost.html?post=" + postPart.getPost().getId(), getExcerpt(postPart.getPost().getText(), 20), SoneAccessor.getNiceName(postPart.getPost().getSone()), "in-sone"); + SoneTextParser parser = new SoneTextParser(core, core); + SoneTextParserContext parserContext = new SoneTextParserContext(null, postPart.getPost().getSone()); + try { + Iterable parts = parser.parse(parserContext, new StringReader(postPart.getPost().getText())); + StringBuilder excerpt = new StringBuilder(); + for (Part part : parts) { + excerpt.append(part.getText()); + if (excerpt.length() > 20) { + excerpt.setLength(20); + break; + } + } + renderLink(writer, "viewPost.html?post=" + postPart.getPost().getId(), excerpt.toString(), SoneAccessor.getNiceName(postPart.getPost().getSone()), "in-sone"); + } catch (IOException ioe1) { + /* StringReader shouldn’t throw. */ + } } /** -- 2.7.4