From 375a8cc2e675fe21ed1704ad7653de549cf88668 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 16 Apr 2024 20:23:27 +0100 Subject: [PATCH] maybe fix html spacing --- .../mcutils/backend/common/ColorUtils.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/xyz/mcutils/backend/common/ColorUtils.java b/src/main/java/xyz/mcutils/backend/common/ColorUtils.java index 22e7583..75b10e0 100644 --- a/src/main/java/xyz/mcutils/backend/common/ColorUtils.java +++ b/src/main/java/xyz/mcutils/backend/common/ColorUtils.java @@ -46,22 +46,22 @@ public final class ColorUtils { return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); } - /** - * Convert the given input into HTML format. - *

- * This will replace each color code with - * a span tag with the respective color in - * hex format. - *

- * - * @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(" ".repeat(Math.max(0, leadingSpaces))); + return builder.toString(); } - } \ No newline at end of file