@@ -46,9 +46,15 @@ func convertFile(srcPath, dstPath string) error {
4646 // Process lines
4747 i := 0
4848 inFrontmatter := false
49+ inCodeBlock := false
4950 for i < len (lines ) {
5051 line := lines [i ]
5152
53+ // Track code block boundaries (triple backticks)
54+ if strings .HasPrefix (strings .TrimSpace (line ), "```" ) {
55+ inCodeBlock = ! inCodeBlock
56+ }
57+
5258 // Track frontmatter boundaries
5359 if line == "---" {
5460 if ! inFrontmatter {
@@ -176,8 +182,10 @@ func convertFile(srcPath, dstPath string) error {
176182
177183 // Escape placeholder-like angle brackets (e.g., <src-path>, <dest-path>)
178184 // but preserve actual HTML tags (a, br, Accordion)
179- // Simple heuristic: if it contains a hyphen or underscore, it's likely a placeholder
180- line = escapeAngleBracketPlaceholders (line )
185+ // Skip escaping inside code blocks (triple backticks) where angle brackets are literal
186+ if ! inCodeBlock {
187+ line = escapeAngleBracketPlaceholders (line )
188+ }
181189
182190 fmt .Fprintln (writer , line )
183191 i ++
@@ -241,7 +249,17 @@ func fixAnchorLinks(line string) string {
241249func escapeAngleBracketPlaceholders (line string ) string {
242250 result := ""
243251 i := 0
252+ inBackticks := false
253+
244254 for i < len (line ) {
255+ // Track backtick state
256+ if line [i ] == '`' {
257+ inBackticks = ! inBackticks
258+ result += string (line [i ])
259+ i ++
260+ continue
261+ }
262+
245263 // Check for HTML comment pattern <!--
246264 if i + 3 < len (line ) && line [i :i + 4 ] == "<!--" {
247265 // Find the closing -->
@@ -315,9 +333,15 @@ func escapeAngleBracketPlaceholders(line string) string {
315333 content == "/thead" ||
316334 content == "/tbody"
317335
318- // If it's not a known HTML tag, escape using JSX expressions
336+ // If it's not a known HTML tag, escape it
319337 if ! isKnownTag {
320- result += `{"<"}` + content + `{">"}`
338+ // Inside backticks, leave as-is (no escaping needed in code context)
339+ // Outside backticks, use JSX expressions
340+ if inBackticks {
341+ result += line [i : end + 1 ]
342+ } else {
343+ result += `{"<"}` + content + `{">"}`
344+ }
321345 i = end + 1
322346 continue
323347 } else {
@@ -854,16 +878,26 @@ func main() {
854878 return nil
855879 }
856880
857- // Convert .md to .mdx
858- dstPath := filepath .Join (dstDir , strings .TrimSuffix (relPath , ".md" )+ ".mdx" )
881+ // Special handling for cli.md at root - move it to parent directory
882+ var dstPath string
883+ if relPath == "cli.md" {
884+ // Output to parent directory of dstDir
885+ // Clean the path first to remove trailing slashes
886+ cleanDstDir := filepath .Clean (dstDir )
887+ parentDir := filepath .Dir (cleanDstDir )
888+ dstPath = filepath .Join (parentDir , "cli.mdx" )
889+ fmt .Printf ("Converting %s -> cli.mdx (moved to parent directory: %s)\n " , relPath , dstPath )
890+ } else {
891+ // Convert .md to .mdx in normal location
892+ dstPath = filepath .Join (dstDir , strings .TrimSuffix (relPath , ".md" )+ ".mdx" )
893+ fmt .Printf ("Converting %s -> %s\n " , relPath , strings .TrimSuffix (relPath , ".md" )+ ".mdx" )
894+ }
859895
860896 // Create destination directory
861897 if err := os .MkdirAll (filepath .Dir (dstPath ), 0755 ); err != nil {
862898 return err
863899 }
864900
865- fmt .Printf ("Converting %s -> %s\n " , relPath , strings .TrimSuffix (relPath , ".md" )+ ".mdx" )
866-
867901 return convertFile (path , dstPath )
868902 })
869903
0 commit comments