#!/usr/bin/env python3 """HTML validator for BlackRoad OS""" import re import sys def validate_html(filename): errors = [] warnings = [] with open(filename, 'r') as f: content = f.read() # Check basic structure if not content.strip().startswith(''): errors.append("Missing DOCTYPE declaration") if '' not in content: errors.append("Missing html tags") if '
' not in content or '' not in content: errors.append("Missing head tags") if '' not in content or '' not in content: errors.append("Missing body tags") # Check for unclosed tags script_opens = content.count('', content, re.DOTALL) if script_match: js_code = script_match.group(1) # Basic JS validation if 'function' in js_code and 'let' in js_code: print("✓ JavaScript code found and appears valid") # Check CSS if '') if style_opens != style_closes: errors.append(f"Mismatched style tags: {style_opens} opens, {style_closes} closes") else: print(f"✓ Found {style_opens} style block(s)") # Report results print(f"\n{'='*60}") print(f"HTML Validation Results for: {filename}") print(f"{'='*60}") print(f"File size: {len(content)} bytes") print(f"Lines: {content.count(chr(10))}") print(f"Divs: {div_opens} opens, {div_closes} closes") print(f"Scripts: {script_opens} opens, {script_closes} closes") if errors: print(f"\n❌ ERRORS FOUND ({len(errors)}):") for i, error in enumerate(errors, 1): print(f" {i}. {error}") else: print("\n✓ No structural errors found") if warnings: print(f"\n⚠ WARNINGS ({len(warnings)}):") for i, warning in enumerate(warnings, 1): print(f" {i}. {warning}") return len(errors) == 0 if __name__ == '__main__': filename = sys.argv[1] if len(sys.argv) > 1 else 'index.html' valid = validate_html(filename) sys.exit(0 if valid else 1)