maybe fix html spacing
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 2m15s

This commit is contained in:
Lee 2024-04-16 20:23:27 +01:00
parent 2e5c8b1ee0
commit 375a8cc2e6

View File

@ -46,22 +46,22 @@ public final class ColorUtils {
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
}
/**
* Convert the given input into HTML format.
* <p>
* This will replace each color code with
* a span tag with the respective color in
* hex format.
* </p>
*
* @param input the input to convert
* @return the converted input
*/
@NonNull
public static String toHTML(@NonNull String input) {
StringBuilder builder = new StringBuilder();
boolean nextIsColor = false; // Is the next char a color code?
// Get the leading spaces from the first line
int leadingSpaces = 0;
boolean foundNonSpace = false;
for (char character : input.toCharArray()) {
if (character == ' ' && !foundNonSpace) {
leadingSpaces++;
} else {
foundNonSpace = true;
}
}
for (char character : input.toCharArray()) {
// Found color symbol, next character is the color
if (character == '§') {
@ -80,7 +80,10 @@ public final class ColorUtils {
builder.append(character); // Append the char...
}
}
// Add leading spaces to the end of the HTML string
builder.append("&nbsp;".repeat(Math.max(0, leadingSpaces)));
return builder.toString();
}
}