Create the excerpt of a linked post from the parsed plain text, not the raw text.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 5 Sep 2012 12:14:56 +0000 (14:14 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 5 Sep 2012 12:14:56 +0000 (14:14 +0200)
src/main/java/net/pterodactylus/sone/template/ParserFilter.java

index 90744e7..5f156f1 100644 (file)
@@ -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<Part> 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. */
+               }
        }
 
        /**