diff options
author | Vitaly Takmazov | 2018-01-18 16:27:55 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-01-18 16:27:55 +0300 |
commit | 51af5b371c55bb0a49e0c9a4ac54e4dff90002d2 (patch) | |
tree | d636714434b1554d2ce0f9a12a6e7d8b1d117e6a /juick-core/src/main/java | |
parent | 230e5e80d9b1e3ca4535fb0dbba19246d799a737 (diff) |
tg: markdown escape
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 0f5e0756..ebeaef42 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 6e0b47c0..fa0072b2 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("`", "\\`"); + } } |