From 0020a6561f537db248cff6630346bde8f20aaa1f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 12 Nov 2018 12:29:00 +0300 Subject: second type of markdown url --- src/main/java/com/juick/util/MessageUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 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$3"); // [link text][http://juick.com/last?page=2] + // [link text](http://juick.com/last?page=2) // link text msg = msg.replaceAll(textUrlRegex, "$1"); - msg = msg.replaceAll(textUrlRegex, "$1"); + msg = msg.replaceAll(textUrlRegex2, "$1"); // #12345 // #12345 -- cgit v1.2.3