diff options
author | scria1000 <91804886+scria1000@users.noreply.github.com> | 2021-11-14 11:52:07 +0000 |
---|---|---|
committer | scria1000 <91804886+scria1000@users.noreply.github.com> | 2021-11-14 11:52:07 +0000 |
commit | 839325efbedb108917b37353c9493fea305d71e2 (patch) | |
tree | f8f872dab154f78869aad1ba9f35e5c801baed18 /app/src/main/java | |
parent | e3976248cc948df3633f4254d29645389ae9221d (diff) | |
download | infinity-for-reddit-839325efbedb108917b37353c9493fea305d71e2.tar infinity-for-reddit-839325efbedb108917b37353c9493fea305d71e2.tar.gz infinity-for-reddit-839325efbedb108917b37353c9493fea305d71e2.tar.bz2 infinity-for-reddit-839325efbedb108917b37353c9493fea305d71e2.tar.lz infinity-for-reddit-839325efbedb108917b37353c9493fea305d71e2.tar.xz infinity-for-reddit-839325efbedb108917b37353c9493fea305d71e2.tar.zst infinity-for-reddit-839325efbedb108917b37353c9493fea305d71e2.zip |
Don't handle unescaped bracket links for now
Until there is a better solution that can also handle `[Title]: https://link.com` type links and others.
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 48 |
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; |