secretumvault/scripts/fix-table-formatting.nu
2026-01-11 23:12:38 +00:00

64 lines
1.6 KiB
Plaintext
Executable File

#!/usr/bin/env nu
# Fix MD060 table formatting errors - ensure spaces around pipes
def main [] {
let files = (glob **/*.md
| where {|f| not ($f | str contains ".git") }
| where {|f| not ($f | str contains "target") }
| where {|f| not ($f | str contains ".coder") }
| where {|f| not ($f | str contains ".claude") }
)
print $"Processing ($files | length) markdown files..."
for file in $files {
fix_tables_in_file $file
}
print "✅ Table formatting fixed"
}
def fix_tables_in_file [file: string] {
let content = (open $file --raw)
let lines = ($content | lines)
mut fixed_lines = []
for line in $lines {
if ($line | str contains "|") {
# This is likely a table line
let fixed = (fix_table_line $line)
$fixed_lines = ($fixed_lines | append $fixed)
} else {
$fixed_lines = ($fixed_lines | append $line)
}
}
$fixed_lines | str join "\n" | save -f $file
}
def fix_table_line [line: string] {
# Fix table pipes to have spaces: |word| → | word |
mut result = $line
# Pattern 1: |word| → | word |
# Replace pipes with no spaces around content
$result = ($result
| str replace --all --regex '\|([^\s\|][^\|]*?)\|' '| $1 |'
)
# Pattern 2: Fix leading/trailing pipes
$result = ($result
| str replace --all --regex '^\|([^\s])' '| $1'
| str replace --all --regex '([^\s])\|$' '$1 |'
)
# Pattern 3: Fix consecutive pipes with content
$result = ($result
| str replace --all --regex '\|([^\s\|])' '| $1'
| str replace --all --regex '([^\s\|])\|' '$1 |'
)
$result
}