fix_code_examples.jl
1 #!/usr/bin/env julia 2 3 """ 4 Fix Code Examples Script 5 6 This script fixes Julia code blocks that contain markdown links, 7 which cause parsing errors during testing. 8 """ 9 10 function fix_code_blocks(filepath::String) 11 if !isfile(filepath) 12 return false 13 end 14 15 content = read(filepath, String) 16 original_content = content 17 18 # Fix common issues in Julia code blocks 19 fixes = Dict( 20 # Remove markdown links from Julia code 21 r"s = strategy\(:QuickStart, \[exchange\]\([^)]+\)=:binance\)" => "s = strategy(:QuickStart, exchange=:binance)", 22 r"\[strategy\]\([^)]+\)" => "strategy", 23 r"\[exchange\]\([^)]+\)" => "exchange", 24 r"\[API keys\]\([^)]+\)" => "API keys", 25 r"\[configuration\]\([^)]+\)" => "configuration", 26 r"\[RSI\]\([^)]+\)" => "RSI", 27 r"\[backtesting\]\([^)]+\)" => "backtesting", 28 r"\[live trading\]\([^)]+\)" => "live trading", 29 r"\[OHLCV data\]\([^)]+\)" => "OHLCV data", 30 r"\[timeframe\]\([^)]+\)" => "timeframe", 31 r"\[strategies\]\([^)]+\)" => "strategies", 32 33 # Fix string interpolation issues 34 r"\$\$\(" => "\$(", 35 36 # Fix malformed comments 37 r"# Test small data fetch \(should work without \[API keys\]\([^)]+\)\)" => "# Test small data fetch (should work without API keys)", 38 r"# \(this is normal without \[exchange\]\([^)]+\) API\)" => "# (this is normal without exchange API)", 39 ) 40 41 for (pattern, replacement) in fixes 42 content = replace(content, pattern => replacement) 43 end 44 45 # Write back if changes were made 46 if content != original_content 47 write(filepath, content) 48 println("ā Fixed code examples in $(basename(filepath))") 49 return true 50 else 51 println("ā¹ļø No code fixes needed for $(basename(filepath))") 52 return false 53 end 54 end 55 56 println("š§ Fixing Code Examples in Documentation") 57 println("=" ^ 45) 58 59 files_to_fix = [ 60 "docs/src/getting-started/installation.md", 61 "docs/src/getting-started/quick-start.md", 62 "docs/src/getting-started/first-strategy.md" 63 ] 64 65 global fixes_applied = 0 66 for filepath in files_to_fix 67 if fix_code_blocks(filepath) 68 global fixes_applied += 1 69 end 70 end 71 72 println("\nš Code Fix Results:") 73 println("Files processed: $(length(files_to_fix))") 74 println("Files fixed: $fixes_applied") 75 println("\nš Code example fixes completed!")