@@ -225,7 +225,7 @@ private void generatePackageIndex(String packageName, List<TypeElement> classes,
225225 }
226226 }
227227 }
228- json .put ("description" , convertToMarkdown (description , packageName ).trim ());
228+ json .put ("description" , convertToMarkdown (description , packageName ).replace ( " \n " , " " ). replace ( " \r " , " " ). trim ());
229229 if (indexInDocs != null ) {
230230 json .put ("index" , indexInDocs );
231231 }
@@ -320,7 +320,7 @@ private void generateClassIndex(TypeElement classElement, List<ExecutableElement
320320 }
321321
322322 json .put ("scratchblock" , customTags .getOrDefault ("scratchblock" , "" ));
323- json .put ("description" , convertToMarkdown (description , currentPackage ).trim ());
323+ json .put ("description" , convertToMarkdown (description , currentPackage ).replace ( " \n " , " " ). replace ( " \r " , " " ). trim ());
324324 if (indexInDocs != null ) {
325325 json .put ("index" , indexInDocs );
326326 }
@@ -335,6 +335,31 @@ private void generateClassIndex(TypeElement classElement, List<ExecutableElement
335335 // Examples - support multiple examples
336336 json .put ("examples" , buildExamples (customTags ));
337337
338+ // --- Add public static fields under "fields" ---
339+ List <Map <String , Object >> fields = new ArrayList <>();
340+ for (Element member : classElement .getEnclosedElements ()) {
341+ if (member .getKind () == ElementKind .FIELD ) {
342+ Set <Modifier > modifiers = member .getModifiers ();
343+ if (modifiers .contains (Modifier .PUBLIC ) && modifiers .contains (Modifier .STATIC )) {
344+ Map <String , Object > fieldJson = new LinkedHashMap <>();
345+ fieldJson .put ("name" , member .getSimpleName ().toString ());
346+ fieldJson .put ("type" , simplifyType (member .asType ().toString ()));
347+ // Add field Javadoc if present
348+ DocCommentTree fieldDoc = env .getDocTrees ().getDocCommentTree (member );
349+ String fieldDesc = "" ;
350+ if (fieldDoc != null ) {
351+ fieldDesc = convertToMarkdown (extractDescription (fieldDoc , currentPackage ), currentPackage )
352+ .replace ("\n " , " " ).replace ("\r " , " " ).trim ();
353+ }
354+ fieldJson .put ("description" , fieldDesc );
355+ fields .add (fieldJson );
356+ }
357+ }
358+ }
359+ if (!fields .isEmpty ()) {
360+ json .put ("fields" , fields );
361+ }
362+
338363 writeJsonToFile (json , classDir .resolve ("index.md.json" ));
339364 }
340365
@@ -412,7 +437,7 @@ private void generateMethodJson(List<ExecutableElement> methods, String classNam
412437 }
413438 json .put ("scratchblock" , customTags .getOrDefault ("scratchblock" , "" ));
414439 json .put ("class" , className );
415- json .put ("description" , finalDescription .trim ());
440+ json .put ("description" , finalDescription .replace ( " \n " , " " ). replace ( " \r " , " " ). trim ());
416441 if (indexInDocs != null ) {
417442 json .put ("index" , indexInDocs );
418443 }
@@ -584,7 +609,7 @@ private String extractDescriptionRaw(DocCommentTree docComment) {
584609 */
585610 private String convertToMarkdown (String html , String currentPackage ) {
586611 // Convert <pre>{@code ...}</pre> to markdown code blocks
587- // Pattern matches: <pre>\s*{@code\s* ... }\s*</pre>
612+ // Pattern matches: <pre>\s*\\ {@code\s* ... }\s*</pre>
588613 String result = html .replaceAll (
589614 "(?s)<pre>\\ s*\\ {@code\\ s*(.*?)\\ s*\\ }\\ s*</pre>" ,
590615 "\n ```java\n $1\n ```\n " );
0 commit comments