From: David ‘Bombe’ Roden Date: Wed, 5 Sep 2012 12:14:56 +0000 (+0200) Subject: Create the excerpt of a linked post from the parsed plain text, not the raw text. X-Git-Tag: 0.8.3^2~53^2 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=00be7dff1eec2c325b03b0a6bbe7b1c9c515003b;p=Sone.git Create the excerpt of a linked post from the parsed plain text, not the raw text. --- 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. */ + } } /**