import sys import re import json def extract_checklist(markdown_content): checklist = [] lines = markdown_content.split('\n') current_section = "General" in_table = False headers = [] for line in lines: stripped = line.strip() # Detect headers as sections header_match = re.match(r'^(#{1,6})\s+(.+)', line) if header_match: current_section = header_match.group(2).strip() in_table = False continue # Detect existing checkboxes msg_match = re.match(r'^\s*-\s*\[([ x])\]\s+(.+)', line) if msg_match: status = "completed" if msg_match.group(1) == 'x' else "pending" checklist.append({ "section": current_section, "item": msg_match.group(2).strip(), "type": "checkbox", "status": status }) continue # Detect table start if '|' in line and not in_table: # check if it looks like a header row parts = [p.strip() for p in line.split('|') if p.strip()] if len(parts) > 1: headers = parts in_table = True continue # Detect table separator if in_table and set(stripped.replace('|', '').replace('-', '').replace(' ', '')) == set(): continue # Detect table rows if in_table and '|' in line: parts = [p.strip() for p in line.split('|') if p.strip()] if len(parts) == len(headers): # Heuristic: If first column looks like a File/ID/Method, treat as requirement item_text = f"{parts[0]}: {parts[1]}" if len(parts) >= 2 else parts[0] checklist.append({ "section": current_section, "item": item_text, "type": "table_row", "status": "pending" }) elif not stripped: in_table = False return checklist def generate_verification_plan(checklist): output = [] output.append("# Generated Gap Analysis Checklist") output.append("\n## Gap Analysis Matrix\n") output.append("| Category | Requirement | Implementation Status | Notes |") output.append("|---|---|---|---|") for item in checklist: output.append(f"| {item['section']} | {item['item']} | Pending | |") return "\n".join(output) if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python checklist_generator.py ") sys.exit(1) try: with open(sys.argv[1], 'r', encoding='utf-8') as f: content = f.read() checklist = extract_checklist(content) print(generate_verification_plan(checklist)) except Exception as e: print(f"Error: {e}") sys.exit(1)