maybe bold for html?
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m39s

This commit is contained in:
Lee 2024-04-16 20:44:37 +01:00
parent 5c77b59b90
commit 45fb517385

@ -57,7 +57,6 @@ public final class ColorUtils {
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?
boolean isBold = false; // Is the text currently bold?
// Get the leading spaces from the first line // Get the leading spaces from the first line
int leadingSpaces = 0; int leadingSpaces = 0;
@ -71,32 +70,23 @@ public final class ColorUtils {
} }
for (char character : input.toCharArray()) { for (char character : input.toCharArray()) {
// Found color symbol, next character is the color // Found color symbol, next color is the color
if (character == '§') { if (character == '§') {
nextIsColor = true; nextIsColor = true;
continue; continue;
} }
if (nextIsColor) { // Map the current color to its hex code if (nextIsColor) { // Map the current color to its hex code
String color = COLOR_MAP.getOrDefault(Character.toLowerCase(character), ""); String color = COLOR_MAP.getOrDefault(Character.toLowerCase(character), "");
builder.append("<span style=\"color:").append(color).append("\">"); builder.append("<span style=\"color:").append(color);
if (character == 'l') { // Bold
builder.append(";font-weight:bold");
}
builder.append("\">");
nextIsColor = false; nextIsColor = false;
if (character == 'l') { // Start bold
builder.append("<span style=\"font-weight: bold;\">");
continue; continue;
} }
if (character == 'r') { // Reset formatting
builder.append("</span>");
continue;
}
continue;
}
if (character == ' ') { // Preserve space character
builder.append("&nbsp;");
} else {
builder.append(character); // Append the char... builder.append(character); // Append the char...
} }
}
// Add leading spaces to the end of the HTML string // Add leading spaces to the end of the HTML string
builder.append("&nbsp;".repeat(Math.max(0, leadingSpaces))); builder.append("&nbsp;".repeat(Math.max(0, leadingSpaces)));