Skip to content

Commit

Permalink
Update model card description to be prettier (#4966)
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannParis authored Sep 30, 2024
1 parent 8fa1632 commit bf99671
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class JsonToHTML {
// Function to recursively render JsonNode object into HTML
public static String renderJsonToHTML(JsonNode jsonNode) {
StringBuilder html = new StringBuilder();
renderObject(jsonNode, html, 0);
renderObject(jsonNode, html, 2);
return html.toString();
}

Expand All @@ -25,7 +25,7 @@ private static void renderObject(JsonNode jsonNode, StringBuilder html, int leve
.append("<h")
.append(level + 1)
.append(">")
.append(capitalizeFirstLetter(fieldName))
.append(formatTitle(fieldName))
.append("</h")
.append(level + 1)
.append(">\n");
Expand Down Expand Up @@ -57,10 +57,18 @@ private static void renderArray(JsonNode arrayNode, StringBuilder html, int leve
}

// Helper to capitalize the first letter of a string
private static String capitalizeFirstLetter(String input) {
private static String formatTitle(String input) {
if (input == null || input.isEmpty()) {
return input;
}
return input.substring(0, 1).toUpperCase() + input.substring(1);

// Split the string into words and add a space between each word
String[] words = input.split("(?=[A-Z])");
StringBuilder formatted = new StringBuilder();
for (String word : words) {
formatted.append(word).append(" ");
}
final String title = formatted.toString().trim();
return title.substring(0, 1).toUpperCase() + title.substring(1);
}
}

0 comments on commit bf99671

Please sign in to comment.