import os import re def check_file(filepath): issues = [] try: with open(filepath, 'r', encoding='utf-8') as f: lines = f.readlines() except Exception as e: return [f"Could not read file: {e}"] in_code_block = False for i, line in enumerate(lines): line_stripped = line.strip() # Code block tracking if line_stripped.startswith('```'): in_code_block = not in_code_block if in_code_block: continue # 1. Full-width parentheses `(` `)` if '(' in line or ')' in line: if line_stripped.startswith('#'): issues.append(f"Line {i+1}: Header contains full-width parentheses '(' or ')'") else: issues.append(f"Line {i+1}: Text contains full-width parentheses '(' or ')'") # 2. Missing intro text after headers if line_stripped.startswith('#'): j = i + 1 while j < len(lines) and lines[j].strip() == '': j += 1 if j < len(lines): next_line = lines[j].strip() if next_line.startswith('```'): issues.append(f"Line {i+1}: Header immediately followed by code block without text") elif next_line.startswith('|') and len(next_line.split('|')) > 2: issues.append(f"Line {i+1}: Header immediately followed by table without text") elif next_line.startswith('#') and next_line.count('#') == line_stripped.count('#') + 1: issues.append(f"Line {i+1}: Header immediately followed by sub-header (missing text between)") elif next_line.startswith('!['): issues.append(f"Line {i+1}: Header immediately followed by image without text") # 3. Missing blank line before list item # Is this line a list item? is_list_item = re.match(r'^(\s*[-*+]\s|\s*\d+\.\s)', line) if is_list_item and i > 0: prev_line = lines[i-1] prev_line_stripped = prev_line.strip() # If prev line is not empty, and not already a list item, header, quote, or HTML comment if prev_line_stripped and not prev_line_stripped.startswith('#') and not prev_line_stripped.startswith('>'): if not re.match(r'^(\s*[-*+]\s|\s*\d+\.\s)', prev_line) and not prev_line_stripped.startswith('