Skip to content

feat: rich Markdown export + HwpxOxmlNote body helpers#42

Open
AgentBridge-Lab wants to merge 1 commit into
airmang:mainfrom
AgentBridge-Lab:feat/rich-markdown-export
Open

feat: rich Markdown export + HwpxOxmlNote body helpers#42
AgentBridge-Lab wants to merge 1 commit into
airmang:mainfrom
AgentBridge-Lab:feat/rich-markdown-export

Conversation

@AgentBridge-Lab
Copy link
Copy Markdown

Summary

  • 새 모듈 hwpx.tools.markdown_exportHwpxDocument.export_rich_markdown() 추가 — 인라인 서식(**/*/~~), 표(중첩·colspan/rowspan), 도형 텍스트, 이미지(BinData 추출), 각주/미주(정확한 본문 마커 위치), 하이퍼링크, #/## heading 자동 감지 보존.
  • HwpxOxmlNotebody_paragraph / add_run / add_hyperlink helper 추가 — 각주 본문에 혼합 서식·링크를 paragraph 직접 조작 없이 작성.
  • HwpxOxmlParagraph.add_footnote / add_endnote의 cpr 버그 수정 (인자 char_pr_id_ref가 본문 run에 무시되고 항상 "0"이 박히던 문제).
  • 27개 신규 회귀 테스트 추가 (tests/test_markdown_export.py).

Background

기존 평문 export_markdown()로는 인라인 스타일·표 구조·각주 위치가 손실되어 에이전트 파이프라인에서 재변환·재서식 단계가 필요했습니다. 실제 정부 문서(KASA 공고/신청서/연구보고서) 다수로 검증된 PoC 패턴을 모듈화했습니다.

API

```python
from hwpx import HwpxDocument

doc = HwpxDocument.open("보고서.hwpx")
md = doc.export_rich_markdown(
image_dir="out/images",
image_ref_prefix="images/",
detect_headings=True,
)
```

문자열·경로·바이트도 그대로 수용:

```python
from hwpx.tools.markdown_export import export_markdown
md = export_markdown("보고서.hwpx")
md = export_markdown(open("a.hwpx", "rb").read())
```

각주 본문 helpers:

```python
note = paragraph.add_footnote("")
note.add_run("자세한 내용은 ")
note.add_run("공식 사이트", bold=True)
note.add_hyperlink("https://www.kasa.go.kr\", "우주항공청")
```

Test plan

  • `pytest tests/test_markdown_export.py` — 27 passed
  • `pytest` 전체 — 281 passed, 6 skipped (기존 skip 사유 동일)
  • KASA 실제 hwpx 라운드트립: charPrIDRef 보존 확인
  • 각주 본문 마커 위치(텍스트 흐름 중간) + 본문 하이퍼링크 text 렌더링 확인
  • 중첩 표 / colspan / rowspan / 이미지 추출 / 도형 텍스트 출력 패턴 확인

Generated with Claude Code
via Happy

- Add hwpx.tools.markdown_export module and HwpxDocument.export_rich_markdown()
  preserving inline styles (**bold**, *italic*, ~~strike~~), nested tables with
  colspan/rowspan, shape text, BinData image extraction, footnotes/endnotes with
  precise marker positions, hyperlinks, and #/## heading detection.
- Add HwpxOxmlNote.body_paragraph / add_run / add_hyperlink helpers so note
  bodies can be populated with mixed inline formatting and links without
  manual paragraph manipulation.
- Fix add_footnote / add_endnote: the char_pr_id_ref argument was ignored and
  the body run always got charPrIDRef="0".
- Add 27 regression tests covering inline styles, tables, footnotes, note
  helpers, hyperlinks, headings, images, roundtrip, and source-input types.

Validated against real KASA government HWPX fixtures (announcements, application
forms, research reports) and synthetic edge cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant