mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-14 14:32:49 +01:00
Show superscript correctly.
This commit is contained in:
parent
ce503e242a
commit
7e5edf92b1
@ -37,39 +37,28 @@ public class Utils {
|
|||||||
private static final long YEAR_MILLIS = 12 * MONTH_MILLIS;
|
private static final long YEAR_MILLIS = 12 * MONTH_MILLIS;
|
||||||
|
|
||||||
public static String modifyMarkdown(String markdown) {
|
public static String modifyMarkdown(String 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)"));
|
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,}", "^"));
|
||||||
|
|
||||||
/*int startIndex = 0;
|
int startIndex = regexed.indexOf("^");
|
||||||
|
while (startIndex >= 0 && startIndex + 1 < regexed.length()) {
|
||||||
Pattern pattern = Pattern.compile("\\^.+");
|
char currentChar = regexed.charAt(startIndex + 1);
|
||||||
Matcher matcher = pattern.matcher(regexed);
|
if (currentChar == '^') {
|
||||||
// Check all occurrences
|
regexed.insert(startIndex, '^');
|
||||||
while (matcher.find(startIndex)) {
|
startIndex = regexed.indexOf("^", startIndex + 1);
|
||||||
int count = 0;
|
} else if (currentChar == ' ' || currentChar == '\n') {
|
||||||
Pattern pattern2 = Pattern.compile("(\\^\\([^)]+\\))");
|
regexed.insert(startIndex + 1, '^');
|
||||||
Matcher matcher2 = pattern2.matcher(matcher.group());
|
startIndex = regexed.indexOf("^", startIndex + 2);
|
||||||
if (matcher2.find()) {
|
} else {
|
||||||
regexed.setCharAt(matcher2.end() + matcher.start() - 1, '^');
|
if (startIndex + 1 == regexed.length() - 1) {
|
||||||
regexed.deleteCharAt(matcher2.start() + matcher.start() + 1);
|
regexed.append('^');
|
||||||
|
startIndex++;
|
||||||
startIndex = matcher.start() + matcher2.end();
|
|
||||||
String substring = regexed.substring(matcher.start() + matcher2.start() + 1, matcher.start() + matcher2.end() - 2);
|
|
||||||
String trimmedSubstring = substring.trim();
|
|
||||||
regexed.replace(matcher.start() + matcher2.start() + 1, matcher.start() + matcher2.end() - 2, trimmedSubstring);
|
|
||||||
startIndex -= (substring.length() - trimmedSubstring.length());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
regexed.insert(matcher.end(), '^');
|
|
||||||
|
|
||||||
for (int i = matcher.end() - 1; i >= matcher.start() + 1; i--) {
|
|
||||||
if (regexed.charAt(i) == '^') {
|
|
||||||
regexed.deleteCharAt(i);
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
startIndex++;
|
||||||
}
|
}
|
||||||
startIndex = matcher.end() - count;
|
}
|
||||||
}*/
|
|
||||||
return regexed.toString();
|
return regexed.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user