aboutsummaryrefslogtreecommitdiff
path: root/juick-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-core/src')
-rw-r--r--juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java6
-rw-r--r--juick-core/src/main/java/com/juick/util/MessageUtils.java5
2 files changed, 10 insertions, 1 deletions
diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
index 459384fbc..0f5e07568 100644
--- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
+++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
@@ -32,10 +32,14 @@ public class PlainTextFormatter {
static PrettyTime pt = new PrettyTime(new Locale("ru"));
public static String formatPost(Message jmsg) {
+ return formatPost(jmsg, false);
+ }
+
+ public static String formatPost(Message jmsg, boolean markdown) {
StringBuilder sb = new StringBuilder();
boolean isReply = jmsg.getRid() > 0;
String title = isReply ? "Reply by @" : "@";
- String subtitle = isReply ? jmsg.getReplyQuote() : jmsg.getTagsString();
+ String subtitle = isReply ? jmsg.getReplyQuote() : markdown ? MessageUtils.getMarkdownTags(jmsg) : jmsg.getTagsString();
sb.append(title).append(jmsg.getUser().getName()).append(":\n")
.append(subtitle).append("\n").append(StringUtils.defaultString(jmsg.getText())).append("\n");
if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) {
diff --git a/juick-core/src/main/java/com/juick/util/MessageUtils.java b/juick-core/src/main/java/com/juick/util/MessageUtils.java
index aba718a53..6e0b47c0c 100644
--- a/juick-core/src/main/java/com/juick/util/MessageUtils.java
+++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java
@@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
/**
* Created by aalexeev on 11/13/16.
@@ -178,6 +179,10 @@ public class MessageUtils {
}
return hashtags.toString();
}
+ public static String getMarkdownTags(final Message jmsg) {
+ return jmsg.getTags().stream().map(t -> String.format("[%s](http://juick.com/tag/%s)", t.getName(), percentEncode(t.getName())))
+ .collect(Collectors.joining(", "));
+ }
// TODO: check if it is really needed
public static String percentEncode(final String s) {