aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/util/MessageUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/util/MessageUtils.java')
-rw-r--r--src/main/java/com/juick/util/MessageUtils.java43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java
index 0ece7249..3651540e 100644
--- a/src/main/java/com/juick/util/MessageUtils.java
+++ b/src/main/java/com/juick/util/MessageUtils.java
@@ -149,6 +149,9 @@ public class MessageUtils {
}
public static String formatMessage(String msg) {
+ return formatMessage(msg, false);
+ }
+ public static String formatMessage(String msg, boolean compatibleWithDurov) {
msg = msg.replaceAll("&", "&");
msg = msg.replaceAll("<", "&lt;");
@@ -156,7 +159,9 @@ public class MessageUtils {
// --
// &mdash;
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1&mdash;$2");
+ if (!compatibleWithDurov) {
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1&mdash;$2");
+ }
// http://juick.com/last?page=2
// <a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>
@@ -186,20 +191,28 @@ public class MessageUtils {
// _underline_
// <span class="u">underline</span>
- msg = msg.replaceAll(underlineRegex, "$1<span class=\"u\">$2</span>$3");
+ msg = msg.replaceAll(underlineRegex, "$1<u>$2</u>$3");
// /12
// <a href="#12">/12</a>
msg = msg.replaceAll(replyNumberRegex, "$1<a href=\"#$2\">/$2</a>$3");
+
// @username@mastodon.social
// <a href="http://juick.com/mention?username=username@mastodon.social/">@username@mastodon.social</a>
- msg = msg.replaceAll(jidRegex, "$1<span class=\"h-card\"><a class=\"u-url\" href=\"http://juick.com/mention?username=$2\">@$2</a></span>$3");
+ if (compatibleWithDurov) {
+ msg = msg.replaceAll(jidRegex, "$1<a href=\"http://juick.com/mention?username=$2\">@$2</a>$3");
+ } else {
+ msg = msg.replaceAll(jidRegex, "$1<span class=\"h-card\"><a class=\"u-url\" href=\"http://juick.com/mention?username=$2\">@$2</a></span>$3");
+ }
// @username
// <a href="http://juick.com/username/">@username</a>
- msg = msg.replaceAll(usernameRegex, "$1<span class=\"h-card\"><a class=\"u-url\" href=\"https://juick.com/$2/\">@$2</a></span>$3");
-
+ if (compatibleWithDurov) {
+ msg = msg.replaceAll(usernameRegex, "$1<a href=\"https://juick.com/$2/\">@$2</a>$3");
+ } else {
+ msg = msg.replaceAll(usernameRegex, "$1<span class=\"h-card\"><a class=\"u-url\" href=\"https://juick.com/$2/\">@$2</a></span>$3");
+ }
// (http://juick.com/last?page=2)
// (<a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>)
Matcher m = regexLinks2.matcher(msg);
@@ -211,11 +224,13 @@ public class MessageUtils {
m.appendTail(sb);
msg = sb.toString();
- // > citate
- msg = msg.replaceAll(citateRegex, "<q>$1</q>");
- msg = msg.replaceAll("</q><q>", "\n");
+ if (!compatibleWithDurov) {
+ // > citate
+ msg = msg.replaceAll(citateRegex, "<q>$1</q>");
+ msg = msg.replaceAll("</q><q>", "\n");
- msg = msg.replaceAll("\n", "<br/>\n");
+ msg = msg.replaceAll("\n", "<br/>\n");
+ }
return msg;
}
@@ -259,11 +274,11 @@ public class MessageUtils {
.collect(Collectors.joining(", "));
}
- public static String getMarkdownUser(final User user) {
+ public static String getUserHtmlLink(final User user, final String webDomain) {
if (user.getUri().toASCIIString().length() > 0) {
- return String.format("[%s](%s)", user.getName(), user.getUri());
+ return String.format("<a href=\"%s\">%s</a>", user.getUri(), user.getName());
} else {
- return String.format("[%s](https://juick.com/%s/)", user.getName(), user.getName());
+ return String.format("<a href=\"https://%s/%s\">%s</a>", webDomain, user.getName(), user.getName());
}
}
@@ -276,10 +291,6 @@ public class MessageUtils {
return StringUtils.defaultString(msg.getText())
.replaceAll(replyNumberRegex, String.format("$1[/$2](https://juick.com/m/%d#$2)$3", msg.getMid()));
}
- public static String escapeMarkdown(final String s) {
- return s.replace("_", "\\_").replace("*", "\\*")
- .replace("`", "\\`");
- }
public static String attachmentUrl(final Message jmsg) {
if (StringUtils.isEmpty(jmsg.getAttachmentType())) {
return StringUtils.EMPTY;