"""Check source markup for a legal PDF/HTML layout follows print-safe rules:
no color-only distinctions, and page-break control present for a multi-page
Usage: check_print_layout.py <source.html-or-md> [<source2> ...]
def check_file(path: str) -> int:
text = open(path, encoding="utf-8").read()
color_only = re.findall(r'style="[^"]*color:\s*(red|green|#[0-9a-fA-F]{3,6})[^"]*"', text)
nearby_icon_or_text = re.search(r'aria-label|<strong>|\*\*|\[.*?\]', text)
if color_only and not nearby_icon_or_text:
print(f"❌ found {len(color_only)} color-only style declaration(s) with no accompanying icon/text cue")
print("✅ no unaccompanied color-only distinctions found")
is_multipage = len(text) > 3000 or "page-break" in text or re.search(r"#{1,2}\s", text)
has_page_break_rule = bool(re.search(r"page-break-(before|after|inside)|break-(before|after|inside)", text))
if is_multipage and not has_page_break_rule:
print("⚠️ document looks multi-page but no page-break-* / break-* rule found — confirm section breaks are intentional")
print("✅ page-break handling present or document is short enough not to need it")
print("Usage: check_print_layout.py <source.html-or-md> [<source2> ...]", file=sys.stderr)
for path in sys.argv[1:]:
worst = max(worst, check_file(path))
if __name__ == "__main__":