39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Проверка: в .typ ПЗ нет длинного тире «—» (по чек-листу п. 29 — среднее «–»)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DIRS = [ROOT / "includes", ROOT / "appendices"]
|
|
SKIP = {"ch05-tests-generated.typ"}
|
|
EM = "\u2014"
|
|
|
|
|
|
def main() -> int:
|
|
bad: list[str] = []
|
|
for base in DIRS:
|
|
if not base.is_dir():
|
|
continue
|
|
for path in sorted(base.rglob("*.typ")):
|
|
if path.name in SKIP:
|
|
continue
|
|
text = path.read_text(encoding="utf-8")
|
|
for i, line in enumerate(text.splitlines(), 1):
|
|
if EM in line and "не длинное" not in line:
|
|
bad.append(f"{path.relative_to(ROOT)}:{i}: {line.strip()[:100]}")
|
|
if bad:
|
|
print("error: найдено длинное тире «—» (нужно среднее «–»):", file=sys.stderr)
|
|
for line in bad[:40]:
|
|
print(f" {line}", file=sys.stderr)
|
|
if len(bad) > 40:
|
|
print(f" ... и ещё {len(bad) - 40}", file=sys.stderr)
|
|
return 1
|
|
print("OK: длинное тире в .typ не найдено")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|