scripts-fix-md060
#!/usr/bin/env python3 """
title: "Fix Md060" component_type: script version: "1.0.0" audience: contributor status: stable summary: "CODITECT Markdown Quality System Copyright © 2025 AZ1.AI INC - All Rights Reserved" keywords: ['fix', 'md060', 'testing'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "fix-md060.py" language: python executable: true usage: "python3 scripts/fix-md060.py [options]" python_version: "3.10+" dependencies: [] modifies_files: false network_access: false requires_auth: false
CODITECT Markdown Quality System Copyright © 2025 AZ1.AI INC - All Rights Reserved
Simple wrapper for MD060 table formatting fixes for testing.""" from pathlib import Path import re
def fix_md060(content): """Fix table formatting by adding proper spacing around pipes.""" lines = content.split('\n') result = [] fixed = 0
table_row_pattern = re.compile(r'^\|.+\|$')
for line in lines:
if table_row_pattern.match(line):
# Fix spacing around pipes
parts = line.split('|')
fixed_parts = []
for i, part in enumerate(parts):
if i == 0 or i == len(parts) - 1:
# Keep empty parts at start/end
fixed_parts.append(part)
elif part.strip() == '':
# Empty cell
fixed_parts.append(' ')
elif re.match(r'^-+$', part.strip()):
# Separator row
fixed_parts.append(f" {part.strip()} ")
else:
# Regular cell content
fixed_parts.append(f" {part.strip()} ")
fixed_line = '|'.join(fixed_parts)
if fixed_line != line:
fixed += 1
result.append(fixed_line)
else:
result.append(line)
return '\n'.join(result), fixed
def process_file(file_path, dry_run=False): with open(file_path, 'r', encoding='utf-8') as f: content = f.read() fixed_content, count = fix_md060(content) if count > 0 and not dry_run: with open(file_path, 'w', encoding='utf-8') as f: f.write(fixed_content) return count
if name == 'main': import argparse parser = argparse.ArgumentParser() parser.add_argument('paths', nargs='*', default=['.']) parser.add_argument('--dry-run', action='store_true') args = parser.parse_args()
total = 0
for path_str in args.paths:
path = Path(path_str)
if path.is_file() and path.suffix == '.md':
count = process_file(path, args.dry_run)
if count:
print(f"{'[DRY RUN] ' if args.dry_run else ''}Fixed {count} in {path}")
total += count
elif path.is_dir():
for md_file in path.rglob('*.md'):
count = process_file(md_file, args.dry_run)
if count:
print(f"{'[DRY RUN] ' if args.dry_run else ''}Fixed {count} in {md_file}")
total += count
print(f"\nTotal: {total} fixed")