maybe fix html spacing
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 2m15s
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:
parent
2e5c8b1ee0
commit
375a8cc2e6
@ -46,22 +46,22 @@ public final class ColorUtils {
|
|||||||
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
|
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
|
@NonNull
|
||||||
public static String toHTML(@NonNull String input) {
|
public static String toHTML(@NonNull String input) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
boolean nextIsColor = false; // Is the next char a color code?
|
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()) {
|
for (char character : input.toCharArray()) {
|
||||||
// Found color symbol, next character is the color
|
// Found color symbol, next character is the color
|
||||||
if (character == '§') {
|
if (character == '§') {
|
||||||
@ -80,7 +80,10 @@ public final class ColorUtils {
|
|||||||
builder.append(character); // Append the char...
|
builder.append(character); // Append the char...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add leading spaces to the end of the HTML string
|
||||||
|
builder.append(" ".repeat(Math.max(0, leadingSpaces)));
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user