scripts-fix-md055-table-row-match
#!/usr/bin/env python3 """
title: "Fix Md055 Table Row Match" component_type: script version: "1.0.0" audience: contributor status: stable summary: "CODITECT Markdown Quality System Copyright © 2025 AZ1.AI INC - All Rights Reserved" from pat..." keywords: ['fix', 'match', 'md055', 'row', 'table'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "fix-md055-table-row-match.py" language: python executable: true usage: "python3 scripts/fix-md055-table-row-match.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""" from pathlib import Path import re
def fix_md055_table_row_match(content): """Fix table separator rows that don't match the header column count.""" lines = content.split('\n') result = [] fixed = 0 i = 0
while i < len(lines):
line = lines[i]
# Check if this looks like a table header (has |)
if '|' in line and line.strip():
# Check if next line is a separator row
if i + 1 < len(lines) and re.match(r'^\s*\|[\s:-]+\|', lines[i + 1]):
header = line
separator = lines[i + 1]
# Count columns in header
header_cols = header.count('|') - 1
# Count columns in separator
sep_cols = separator.count('|') - 1
if header_cols != sep_cols:
# Fix separator to match header column count
# Create new separator with correct number of columns
new_separator = '|' + '------|' * header_cols
lines[i + 1] = new_separator
fixed += 1
result.append(line)
i += 1
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_md055_table_row_match(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")