# -*- coding: utf-8 -*- """기계 검사. 인자: 검사할 md 경로.""" import re, sys, json, os, hashlib, unicodedata WD=os.path.dirname(os.path.abspath(__file__)) p=sys.argv[1] raw=open(p,'rb').read() txt=raw.decode('utf-8') # UTF-8 재읽기 lines=txt.split('\n') res={} def chk(name, ok, detail=''): res[name]={'ok':bool(ok),'detail':detail} print(('PASS ' if ok else 'FAIL '), name, detail if not ok else '') chk('utf8', True) chk('title', lines[0]=='# 계약금 청구 — 청구취지 작성 규칙', lines[0]) # 코드펜스 짝 fences=[i for i,l in enumerate(lines) if l.strip().startswith('```')] chk('fence_pairs', len(fences)%2==0, len(fences)) infence=set() for a,b in zip(fences[0::2],fences[1::2]): infence.update(range(a,b+1)) # 최상위 절 순서 h2=[l for i,l in enumerate(lines) if l.startswith('## ') and i not in infence] exp=['## 0. 메타데이터와 사용법','## 1. 청구권·사실정보 연결과 보완','## 2. 유형 선택과 작성 경로','## 3. 당사자·대상·범위의 작성 규칙','## 4. 금액·기간·조건·부수청구','## 5. 표준 문형과 조립','## 6. 청구원인 작성 단계에 전달할 사항','## 7. 진행·보완·전환·중단 기준','## 부록 A. 근거와 적용 제한','## 부록 B. 문서 관리·제작 검증'] chk('h2_order', h2==exp, h2) # 메타데이터 4항목 m0=lines.index('## 0. 메타데이터와 사용법') meta=[l for l in lines[m0:m0+12] if l.startswith('| ') and not l.startswith('| 항목') ] fields=[l.split('|')[1].strip() for l in meta] chk('metadata_fields', fields==['사건종류','사건키','적용범위','적용제외'], fields) chk('metadata_values', '| 사건종류 | 계약금 청구 |' in lines and '| 사건키 | 계약금청구 |' in lines) # 템플릿 잔재 body='\n'.join(l for i,l in enumerate(lines)) res_tpl=[m.group(0) for m in re.finditer(r'(?