aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java48
1 files changed, 1 insertions, 47 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
index edc49f95..0b49ba31 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
@@ -61,7 +61,7 @@ public class Utils {
private static final long YEAR_MILLIS = 12 * MONTH_MILLIS;
public static String modifyMarkdown(String markdown) {
- StringBuilder regexed = new StringBuilder(trimAndEscapeSpaceInLinks(markdown)
+ StringBuilder regexed = new StringBuilder(markdown
.replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)")
.replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)")
.replaceAll("\\^{2,}", "^")
@@ -77,52 +77,6 @@ public class Utils {
return regexed.toString();
}
- // Also matches links inside code blocks as a side effect
- private static String trimAndEscapeSpaceInLinks(String markdown){
- String TEXT = "\\[([^\\[]\\n?[\\S\\h]+?\\n?[\\S\\h]*?)]";
- String LINK = "(\\n?[\\h]*?\\n?https?:\\/\\/[\\S\\h]+?\n?)";
- String TITLE = "(?:\\s\"(\\n?[\\S\\h]+?\\n?[\\S\\h]*?)?\")?";
- Pattern pattern = Pattern.compile(TEXT + "\\(" + LINK + TITLE + "\\n?\\h*?\\)");
- Matcher matcher = pattern.matcher(markdown);
- StringBuilder builder = new StringBuilder();
- int start = 0;
- while (matcher.find()) try {
- String match1;
- String match2;
- String match3;
- if ((match1 = matcher.group(1)) != null && (match2 = matcher.group(2)) != null) {
- match1 = match1.trim().replaceAll("\\s+", " ");
- match2 = match2.trim().replaceAll(" ", "%20");
- match3 = matcher.group(3);
- builder.append(markdown.substring(start, matcher.start()))
- .append("[")
- .append(match1)
- .append("]")
- .append("(")
- .append(match2);
- if (match3 != null) {
- builder.append(" \"")
- .append(match3)
- .append("\"");
- }
- builder.append(")");
- start = matcher.end();
- }
- } catch (NullPointerException e) {
- e.printStackTrace();
- }
-
- if (start < markdown.length()) {
- builder.append(markdown.substring(start));
- }
-
- if(builder.length() > 0) {
- return builder.toString(); }
- else {
- return markdown;
- }
- }
-
public static String fixSuperScript(StringBuilder regexed) {
boolean hasBracket = false;
int nCarets = 0;