import re import sys from pathlib import Path sys.stdout.reconfigure(encoding='utf-8') md_path = Path("resources/knowledge/original/행정규칙/임도 품셈 적용기준 (현 산림사업 표준품셈)/첨부/(산림청고시 제2025-82호) 산림사업 표준품셈.md") with open(md_path, "r", encoding="utf-8") as f: text = f.read() lines = text.splitlines() # Find chapter headings (# 제X장 또는 ## 제X장 또는 제 X 장) chapters = [] for idx, line in enumerate(lines): # match patterns like # 제1장, ## 제1장, # 제 1 장 등 m = re.match(r'^(#{1,3})\s*(제\s*\d+\s*장.*?)$', line) if m: chapters.append((idx + 1, m.group(1), m.group(2).strip())) print(f"Found {len(chapters)} chapter headings:") for lno, level, title in chapters: print(f" Line {lno:5d}: {level} {title}")