#!/usr/bin/env python3 """Structural validation of the revised document before it is served. python validate.py [ ...] Checks, from the bytes: * no CR (the document is LF-only UTF-8); * every markdown table's rows have the same number of cells as its header, counting escaped pipes (`\\|`) as text rather than separators; * the header/separator shapes agree (a separator row must be dashes and colons only); * the paragraph-level prose sections are still separated by `---`. Finding #2045 was exactly a cell-count defect, so this is the check that finding implies. """ import re import sys sys.stdout.reconfigure(encoding="utf-8", errors="replace") SEP = re.compile(r"^\|(\s*:?-{2,}:?\s*\|)+$") def cells(line): s = line.strip() if s.startswith("|"): s = s[1:] if s.endswith("|"): s = s[:-1] return re.split(r"(?