X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParser.java;h=d271203fc0b3f0ab755782b3f9260cba696a788b;hb=79f1429cf43a59b6e539934555844b3d3ae6bee7;hp=9754ac423ff28329a4fe5a56d12f878e7f3bfb82;hpb=ff0ba9cb343bb7b006ff5f859ef46e165a4bc29f;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index 9754ac4..d271203 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -123,6 +123,11 @@ public class SoneTextParser implements Parser { continue; } emptyLines = 0; + /* + * lineComplete tracks whether the block you are parsing is the + * first block of the line. this is important because sometimes you + * have to add an additional line break. + */ boolean lineComplete = true; while (line.length() > 0) { int nextKsk = line.indexOf("KSK@"); @@ -177,7 +182,11 @@ public class SoneTextParser implements Parser { } if (linkType == LinkType.SONE) { if (next > 0) { - parts.add(new PlainTextPart(line.substring(0, next))); + if (lineComplete && !lastLineEmpty) { + parts.add(new PlainTextPart("\n" + line.substring(0, next))); + } else { + parts.add(new PlainTextPart(line.substring(0, next))); + } } if (line.length() >= (next + 7 + 43)) { String soneId = line.substring(next + 7, next + 50); @@ -192,6 +201,7 @@ public class SoneTextParser implements Parser { parts.add(new PlainTextPart(line.substring(next))); line = ""; } + lineComplete = false; continue; } if (linkType == LinkType.POST) { @@ -202,8 +212,6 @@ public class SoneTextParser implements Parser { String postId = line.substring(next + 7, next + 43); Post post = postProvider.getPost(postId, false); if ((post != null) && (post.getSone() != null)) { - String postText = post.getText(); - postText = postText.substring(0, Math.min(postText.length(), 20)) + "…"; parts.add(new PostPart(post)); } else { parts.add(new PlainTextPart(line.substring(next, next + 43)));