aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-12 12:29:00 +0300
committerGravatar Vitaly Takmazov2018-11-12 12:29:00 +0300
commit0020a6561f537db248cff6630346bde8f20aaa1f (patch)
tree26f2ed571148c2b864dc1e44fb624d48fb066eff /src/main/java/com/juick
parenta1a06bebbdaae2a0a0e36381e005548a6423a8e6 (diff)
second type of markdown url
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/util/MessageUtils.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java
index 915f1748..8db8148c 100644
--- a/src/main/java/com/juick/util/MessageUtils.java
+++ b/src/main/java/com/juick/util/MessageUtils.java
@@ -79,6 +79,8 @@ public class MessageUtils {
private final static String textUrlRegex = "\\[([^\\]]+)\\]\\[((?:ht|f)tps?://[^\\]]+)\\]";
+ private final static String textUrlRegex2 = "\\[([^\\]]+)\\]\\(((?:ht|f)tps?://[^\\)]+)\\)";
+
private final static String boldRegex = "((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
private final static String italicRegex = "((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
@@ -95,6 +97,8 @@ public class MessageUtils {
List<Entity> result = new ArrayList<>(entitiesForType("a", txt, urlWithWhitespacesRegex, matcher -> matcher.group(3), matcher -> Optional.of(matcher.group(2))));
// [link text][http://juick.com/last?page=2]
result.addAll(entitiesForType("a", txt, textUrlRegex, matcher -> matcher.group(1), matcher -> Optional.of(matcher.group(2))));
+ // [link text](http://juick.com/last?page=2)
+ result.addAll(entitiesForType("a", txt, textUrlRegex2, matcher -> matcher.group(1), matcher -> Optional.of(matcher.group(2))));
// #12345
result.addAll(entitiesForType("a", txt, midRegex, matcher -> String.format("#%s", matcher.group(2)), matcher -> Optional.of("https://juick.com/m/" + matcher.group(2))));
// #12345/65
@@ -153,9 +157,10 @@ public class MessageUtils {
msg = msg.replaceAll(urlWithWhitespacesRegex, "$1<a href=\"$2\" rel=\"nofollow\">$3</a>");
// [link text][http://juick.com/last?page=2]
+ // [link text](http://juick.com/last?page=2)
// <a href="http://juick.com/last?page=2" rel="nofollow">link text</a>
msg = msg.replaceAll(textUrlRegex, "<a href=\"$2\" rel=\"nofollow\">$1</a>");
- msg = msg.replaceAll(textUrlRegex, "<a href=\"$2\" rel=\"nofollow\">$1</a>");
+ msg = msg.replaceAll(textUrlRegex2, "<a href=\"$2\" rel=\"nofollow\">$1</a>");
// #12345
// <a href="http://juick.com/12345">#12345</a>