Skip to content

Commit

Permalink
Enhance wordWrap with HTML tags for line breaks
Browse files Browse the repository at this point in the history
Added HTML tags to the `wordWrap` method to ensure proper line breaks using `<br>` instead of newline characters. This change improves the rendering of wrapped text in HTML contexts by enclosing the output in `<html>` tags.
  • Loading branch information
IllianiCBT committed Oct 2, 2024
1 parent 69baa10 commit bc96356
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion megamek/src/megamek/client/ui/WrapLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,22 @@ public static String wordWrap(String input) {
public static String wordWrap(String input, int maximumCharacters) {
StringTokenizer token = new StringTokenizer(input, " ");
StringBuilder output = new StringBuilder(input.length());
output.append("<html>");

int lineLen = 0;

while (token.hasMoreTokens()) {
String word = token.nextToken();

if (lineLen + word.length() > maximumCharacters) {
output.append('\n');
output.append("<br>");
lineLen = 0;
}
output.append(word).append(' ');
lineLen += word.length();
}

output.append("</html>");
return output.toString();
}
}

0 comments on commit bc96356

Please sign in to comment.