diff options
Diffstat (limited to 'juick-core/src/main/java')
-rw-r--r-- | juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java | 8 | ||||
-rw-r--r-- | juick-core/src/main/java/com/juick/util/MessageUtils.java | 6 |
2 files changed, 13 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 0f5e07568..ebeaef42f 100644 --- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java +++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java @@ -41,7 +41,13 @@ public class PlainTextFormatter { String title = isReply ? "Reply by @" : "@"; 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"); + .append(subtitle).append("\n"); + if (markdown) { + sb.append(MessageUtils.escapeMarkdown(StringUtils.defaultString(jmsg.getText()))); + } else { + sb.append(StringUtils.defaultString(jmsg.getText())); + } + sb.append("\n"); if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) { // FIXME: attachment does not serialized to xml if (jmsg.getAttachment() == null) { 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 6e0b47c0c..fa0072b27 100644 --- a/juick-core/src/main/java/com/juick/util/MessageUtils.java +++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java @@ -193,4 +193,10 @@ public class MessageUtils { } return ret; } + public static String escapeMarkdown(final String s) { + return s.replace("_", "\\_").replace("*", "\\*") + .replace("~", "\\~").replace("[", "\\[") + .replace("]", "\\]").replace("(", "\\(") + .replace(")", "\\)").replace("`", "\\`"); + } } |