기능: cat --with-segments 세그먼트 맵 + 표 행 한 줄 불변식 고정 - #17
Merged
Conversation
외부 소비자(코퍼스 추출 파이프라인)가 markdown 출력의 추출 근거를
"verbatim 인용 + 원본 좌표"로 기록할 수 있도록 두 계약을 추가한다.
- to_markdown_with_segments 신설: markdown 방출 코어를 to_markdown_with와
공유하며, 출력 문자(유니코드 스칼라 — Python str 인덱싱과 동일) 범위
[start,end)가 유래한 IR (섹션, 문단) 좌표 목록을 함께 산출. 정렬·비중첩·
간극 허용, cleanup 삭제 구간 재매핑, 표는 담은 문단 상속, 각주/미주
정의는 참조 문단 귀속.
- cat --format markdown --with-segments: 한 줄 컴팩트 JSON 봉투
{"markdown", "segments"} 출력. markdown 필드는 무옵션 출력과 바이트 동일
(방출 코어 공유로 구조 보장).
- 중첩 표를 바깥 행과 같은 줄로 인라인 직렬화 — 기존엔 중첩 표가 바깥
<tr>을 여러 줄로 쪼개 행 한 줄 균형이 4줄에서 깨져 있었다(report-tables
기준). 이제 모든 <tr>…</tr> 행과 GFM 파이프 행이 항상 한 줄.
- 테스트: 한국어 문자 오프셋 정합·불변식·cleanup 재매핑·각주 귀속·다중
구역·표 행 한 줄(단위 + 픽스처 전수, report-tables <tr> 37 회귀 핀)·
CLI 봉투/플래그 오용 통합 테스트.
- README: 표 직렬화 보장 명시 + --with-segments 계약 소절 신설.
- 버전 0.1.0 → 0.2.0 (릴리스 태그 v0.2.0 예정 — 소비 측 버전 고정용).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
배경
외부 소비자(문서 코퍼스 → LLM 추출 → 관계형 DB 파이프라인)가
hwp cat --format markdown출력을 코퍼스로 쓰면서 추출 근거를 "verbatim 인용 + 원본 문서 좌표(섹션/문단 인덱스)"로 기록한다. 이를 위한 두 계약을 추가한다.요청 A — 세그먼트 맵 출력 모드
hwp cat <file> --format markdown --with-segments→ stdout에 한 줄 컴팩트 JSON 봉투:{"markdown": "...", "segments": [{"kind": "para", "section": 0, "para": 12, "start": 345, "end": 512}, ...]}str인덱싱과 동일(바이트 아님). 한국어 픽스처로 테스트 고정.--format json)의sections[]/paragraphs[]인덱스 — 출력 블록 순번이 아닌 원본 안정 좌표.markdown필드는 무옵션 출력과 바이트 동일 — 방출 코어(emit_markdown)를to_markdown_with와 공유해 구조적으로 보장.구현 핵심: 방출 중 문단별 바이트 범위 기록 →
cleanup(빈 줄 정리)을 삭제 구간 맵 산출형으로 확장해 오프셋 재매핑 → 최종 문자열에서 바이트→문자 단일 패스 변환.요청 B — 표 행 한 줄 불변식
검증 중 main의 기존 출력이 불변식을 완전히 지키지 못함을 확인: 중첩 표가 바깥
<tr>을 여러 줄로 쪼개 report-tables.hwpx 기준 4개 줄에서 행 한 줄 균형이 깨져 있었다(의뢰 측 32/32 측정은 중첩 케이스 미포착 —<tr태그 총수는 37). 중첩 표를 개행 없이 바깥 행 줄에 인라인 직렬화하도록 수정해 위반 0을 만들고, 그 외 출력은 구버전과 바이트 동일하다.<tr수 ==</tr>수, GFM 파이프 행은 한 줄 완결. report-tables<tr>총수 37 회귀 핀.--with-segments계약 소절 신설.버전
0.1.0 → 0.2.0. 머지 후 v0.2.0 태그 예정(소비 측
hwp --version고정용).검증
scripts/check.sh(fmt+clippy+test = CI 게이트) 통과.json.load후md[start:end]코드포인트 슬라이싱으로 43개 세그먼트 전부 정합(정렬·비중첩·범위·후행 트림), 각주 정의 귀속·표 문단 상속 실출력 확인.🤖 Generated with Claude Code