@@ -34,6 +34,11 @@ func convertFile(srcPath, dstPath string) error {
3434 return err
3535 }
3636
37+ // Trim excessive trailing blank lines (keep at most 1)
38+ for len (lines ) > 0 && strings .TrimSpace (lines [len (lines )- 1 ]) == "" {
39+ lines = lines [:len (lines )- 1 ]
40+ }
41+
3742 // Check if this is the v1alpha1/config file or cli file
3843 isConfigFile := strings .Contains (dstPath , "v1alpha1/config.mdx" ) || strings .Contains (dstPath , "v1alpha1\\ config.mdx" )
3944 isCliFile := strings .HasSuffix (dstPath , "/cli.mdx" ) || strings .HasSuffix (dstPath , "\\ cli.mdx" )
@@ -273,29 +278,53 @@ func escapeAngleBracketPlaceholders(line string) string {
273278 // Extract the content between < and >
274279 content := line [i + 1 : end ]
275280 // Check if it's likely a placeholder or text that should not be parsed as HTML
276- // Known HTML tags we want to preserve: a, br, p, Accordion, details, summary, pre, code and their closing tags
281+ // Known HTML tags we want to preserve: a, br, p, Accordion, details, summary, pre, code, td, th, tr, table, thead, tbody and their closing tags
277282 isKnownTag := strings .HasPrefix (content , "a " ) ||
283+ content == "a" ||
278284 strings .HasPrefix (content , "br" ) ||
279- strings .HasPrefix (content , "p" ) ||
285+ content == "p" ||
286+ strings .HasPrefix (content , "p " ) ||
280287 strings .HasPrefix (content , "Accordion" ) ||
281288 strings .HasPrefix (content , "details" ) ||
282289 strings .HasPrefix (content , "summary" ) ||
283290 strings .HasPrefix (content , "pre" ) ||
291+ content == "pre" ||
284292 strings .HasPrefix (content , "code" ) ||
293+ content == "code" ||
294+ strings .HasPrefix (content , "td" ) ||
295+ content == "td" ||
296+ strings .HasPrefix (content , "th" ) ||
297+ content == "th" ||
298+ strings .HasPrefix (content , "tr" ) ||
299+ content == "tr" ||
300+ strings .HasPrefix (content , "table" ) ||
301+ strings .HasPrefix (content , "thead" ) ||
302+ strings .HasPrefix (content , "tbody" ) ||
285303 content == "/a" ||
286304 content == "/br" ||
287305 content == "/p" ||
288306 content == "/Accordion" ||
289307 content == "/details" ||
290308 content == "/summary" ||
291309 content == "/pre" ||
292- content == "/code"
310+ content == "/code" ||
311+ content == "/td" ||
312+ content == "/th" ||
313+ content == "/tr" ||
314+ content == "/table" ||
315+ content == "/thead" ||
316+ content == "/tbody"
293317
294318 // If it's not a known HTML tag, escape using JSX expressions
295319 if ! isKnownTag {
296320 result += `{"<"}` + content + `{">"}`
297321 i = end + 1
298322 continue
323+ } else {
324+ // For known HTML tags, copy the entire tag at once
325+ result += line [i : end + 1 ]
326+ i = end + 1
327+ continue
299328 }
300329 }
301330 }
@@ -469,13 +498,88 @@ func processCellContent(content string) string {
469498 // Escape angle bracket placeholders
470499 content = escapeAngleBracketPlaceholders (content )
471500
501+ // Wrap technical patterns in backticks for code formatting
502+ content = wrapTechnicalPatternsInBackticks (content )
503+
472504 // Collapse all whitespace (including newlines) into single spaces for MDX compatibility
473505 // This prevents parsing errors with multi-line content in <td> tags
474506 content = strings .Join (strings .Fields (content ), " " )
475507
476508 return content
477509}
478510
511+ // wrapTechnicalPatternsInBackticks wraps patterns like memory_{some,full}_{avg10,avg60,avg300} in backticks
512+ func wrapTechnicalPatternsInBackticks (content string ) string {
513+ // Pattern: word characters, underscores, with {option1,option2,...} expansions
514+ // Examples: memory_{some,full}_{avg10,avg60,avg300,total}
515+ // Look for: starts with letter/underscore, contains {, }, commas, and underscores
516+
517+ result := ""
518+ i := 0
519+ for i < len (content ) {
520+ // Skip if already in backticks
521+ if i > 0 && content [i - 1 ] == '`' {
522+ result += string (content [i ])
523+ i ++
524+ continue
525+ }
526+
527+ // Check if we're at the start of a potential pattern
528+ // Pattern should start with a letter or underscore
529+ if (content [i ] >= 'a' && content [i ] <= 'z' ) ||
530+ (content [i ] >= 'A' && content [i ] <= 'Z' ) ||
531+ content [i ] == '_' {
532+
533+ // Look ahead to see if this contains the technical pattern markers
534+ start := i
535+ hasUnderscore := false
536+ hasBraces := false
537+ hasComma := false
538+
539+ // Scan ahead to find the end of this potential pattern
540+ end := i
541+ for end < len (content ) {
542+ ch := content [end ]
543+
544+ // Pattern continues with alphanumeric, underscore, braces, comma
545+ if (ch >= 'a' && ch <= 'z' ) || (ch >= 'A' && ch <= 'Z' ) ||
546+ (ch >= '0' && ch <= '9' ) || ch == '_' ||
547+ ch == '{' || ch == '}' || ch == ',' {
548+
549+ if ch == '_' {
550+ hasUnderscore = true
551+ }
552+ if ch == '{' || ch == '}' {
553+ hasBraces = true
554+ }
555+ if ch == ',' {
556+ hasComma = true
557+ }
558+ end ++
559+ } else {
560+ break
561+ }
562+ }
563+
564+ // If we found a pattern with underscores, braces, and commas, wrap it
565+ if end > start && hasUnderscore && hasBraces && hasComma {
566+ pattern := content [start :end ]
567+ // Make sure it's not already wrapped in backticks
568+ if start == 0 || content [start - 1 ] != '`' {
569+ result += "`" + pattern + "`"
570+ i = end
571+ continue
572+ }
573+ }
574+ }
575+
576+ result += string (content [i ])
577+ i ++
578+ }
579+
580+ return result
581+ }
582+
479583// cleanLinkText removes [] prefix from link text and moves it to href
480584func cleanLinkText (line string ) string {
481585 result := ""
@@ -700,9 +804,30 @@ func main() {
700804
701805 fmt .Printf ("Converting docs from %s to %s\n " , srcDir , dstDir )
702806
703- // Remove and recreate destination directory
704- os .RemoveAll (dstDir )
705- os .MkdirAll (dstDir , 0755 )
807+ // Files to preserve during conversion (don't delete these)
808+ preserveFiles := map [string ]bool {
809+ "overview.mdx" : true ,
810+ }
811+
812+ // Instead of removing entire directory, selectively remove only generated files
813+ // This preserves manually created files like overview.mdx
814+ if _ , err := os .Stat (dstDir ); err == nil {
815+ // Directory exists, remove only .mdx files that aren't in preserve list
816+ filepath .Walk (dstDir , func (path string , info os.FileInfo , err error ) error {
817+ if err != nil || info .IsDir () {
818+ return nil
819+ }
820+
821+ filename := filepath .Base (path )
822+ if ! preserveFiles [filename ] && strings .HasSuffix (path , ".mdx" ) {
823+ os .Remove (path )
824+ }
825+ return nil
826+ })
827+ } else {
828+ // Directory doesn't exist, create it
829+ os .MkdirAll (dstDir , 0755 )
830+ }
706831
707832 // Walk through source directory
708833 err = filepath .Walk (srcDir , func (path string , info os.FileInfo , err error ) error {
0 commit comments