3838public class ConfigOptionsDocGenerator {
3939
4040 public static void main (String [] args ) throws Exception {
41- Path projectRoot = findProjectRoot ();
42- File outputFile =
43- projectRoot .resolve ("website/docs/maintenance/config_reference.mdx" ).toFile ();
41+ Path root = findProjectRoot ();
42+ String projectRoot = (root != null ) ? root .toString () : System .getProperty ("user.dir" );
43+ String outputPath = projectRoot + "/website/docs/_configs/_partial_config.mdx" ;
44+
45+ File outputFile = new File (outputPath );
46+ outputFile .getParentFile ().mkdirs ();
4447
4548 System .out .println ("Generating MDX partial: " + outputFile .getAbsolutePath ());
4649
@@ -62,7 +65,6 @@ private static String generateMDXContent() throws IllegalAccessException {
6265 Field [] fields = ConfigOptions .class .getDeclaredFields ();
6366 Map <String , List <Field >> sections = new TreeMap <>();
6467
65- // 1. Group the fields first
6668 for (Field field : fields ) {
6769 if (field .getType ().equals (ConfigOption .class )) {
6870 String section = "Common" ;
@@ -79,16 +81,11 @@ private static String generateMDXContent() throws IllegalAccessException {
7981 }
8082 }
8183
82- // 2. Generate the HTML for each section
8384 for (Map .Entry <String , List <Field >> entry : sections .entrySet ()) {
8485 builder .append ("## " ).append (entry .getKey ()).append (" Configurations\n \n " );
85- builder .append ("<table class=\" configuration-table\" >\n " )
86- .append (" <thead>\n <tr>\n " )
87- .append (" <th style={{width: '25%'}}>Key</th>\n " )
88- .append (" <th style={{width: '15%'}}>Default</th>\n " )
89- .append (" <th style={{width: '15%'}}>Type</th>\n " )
90- .append (" <th style={{width: '45%'}}>Description</th>\n " )
91- .append (" </tr>\n </thead>\n <tbody>\n " );
86+
87+ builder .append ("| Key | Default | Type | Description |\n " );
88+ builder .append ("| :--- | :--- | :--- | :--- |\n " );
9289
9390 for (Field field : entry .getValue ()) {
9491 ConfigOption <?> option = (ConfigOption <?>) field .get (null );
@@ -98,37 +95,29 @@ private static String generateMDXContent() throws IllegalAccessException {
9895 defaultValue = field .getAnnotation (ConfigOverrideDefault .class ).value ();
9996 }
10097
101- // ESCAPE DESCRIPTION: Crucial for MDX/React rendering success
102- // We escape <, >, {, and } which are special JSX characters
98+ // IMPORTANT: MDX hates unescaped < or { symbols in text
10399 String description =
104100 option .description ()
105- .replace ("<" , "<" )
106- .replace (">" , ">" )
107- .replace ("{" , "{" )
108- .replace ("}" , "}" )
101+ .replace ("\n " , " " )
102+ .replace ("\r " , " " )
103+ .replace ("|" , "\\ |" )
104+ .replace ("<" , "<" ) // Escape for MDX
105+ .replace ("{" , "{" ) // Escape for MDX
106+ .replace ("}" , "}" ) // Escape for MDX
109107 .replace ("%s" , "" );
110108
111- builder .append (" <tr>\n " )
112- .append (" <td><code>" )
109+ builder .append ("| `" )
113110 .append (option .key ())
114- .append ("</code></td>\n " )
115- .append (" <td><code>" )
111+ .append ("` | `" )
116112 .append (defaultValue .replace ("<" , "<" ))
117- .append ("</code></td>\n " )
118- .append (" <td>" )
113+ .append ("` | " )
119114 .append (getType (option ))
120- .append ("</td>\n " )
121- .append (" <td>" )
115+ .append (" | " )
122116 .append (description )
123- .append ("</td>\n " )
124- .append (" </tr>\n " );
117+ .append (" |\n " );
125118 }
126- builder .append (" </tbody> \n </table> \n \n " );
119+ builder .append ("\n " );
127120 }
128-
129- // Mandatory export for MDX partials to render correctly in Docusaurus
130- builder .append ("export default ({children}) => <>{children}</>;\n " );
131-
132121 return builder .toString ();
133122 }
134123
0 commit comments