scripts-fix-md032-lists-blank-lines
#!/usr/bin/env python3 """
title: "Fix Md032 Lists Blank Lines" 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: ['blank', 'fix', 'lines', 'lists', 'md032'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "fix-md032-lists-blank-lines.py" language: python executable: true usage: "python3 scripts/fix-md032-lists-blank-lines.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
This software is proprietary and confidential. Unauthorized copying, distribution, or use is strictly prohibited.
CODITECT owns all intellectual property rights to this implementation. """
"""MD032 Fix: Lists should be surrounded by blank lines""" import re from pathlib import Path
def is_list_item(line: str) -> bool: """Check if line is a list item.""" stripped = line.strip() return bool(re.match(r'^[-*+]\s+|^\d+.\s+', stripped))
def fix_md032(content: str): """Add blank lines around lists.""" lines = content.split('\n') result = [] in_list = False fixed = 0 i = 0
while i < len(lines):
line = lines[i]
is_list = is_list_item(line)
if is_list and not in_list:
# Starting a list - add blank line before if needed
if result and result[-1].strip():
result.append('')
fixed += 1
result.append(line)
in_list = True
elif not is_list and in_list:
# Just ended a list - add blank line after last list item
in_list = False
if line.strip():
result.append('')
fixed += 1
result.append(line)
else:
result.append(line)
i += 1
return '\n'.join(result), fixed
def process_file(file_path: Path, dry_run=False): with open(file_path, 'r', encoding='utf-8') as f: content = f.read() fixed_content, count = fix_md032(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(description='Fix MD032: Lists blank lines') 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':
# Process single file
count = process_file(path, args.dry_run)
if count:
print(f"{'[DRY RUN] ' if args.dry_run else ''}Fixed {count} list boundaries in {path}")
total += count
elif path.is_dir():
# Process directory
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} list boundaries in {md_file}")
total += count
print(f"\nTotal: {total} list boundaries fixed")