feat: rich Markdown export + HwpxOxmlNote body helpers#42
Open
AgentBridge-Lab wants to merge 1 commit into
Open
feat: rich Markdown export + HwpxOxmlNote body helpers#42AgentBridge-Lab wants to merge 1 commit into
AgentBridge-Lab wants to merge 1 commit into
Conversation
- 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.
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.
Summary
hwpx.tools.markdown_export와HwpxDocument.export_rich_markdown()추가 — 인라인 서식(**/*/~~), 표(중첩·colspan/rowspan), 도형 텍스트, 이미지(BinData 추출), 각주/미주(정확한 본문 마커 위치), 하이퍼링크,#/##heading 자동 감지 보존.HwpxOxmlNote에body_paragraph/add_run/add_hyperlinkhelper 추가 — 각주 본문에 혼합 서식·링크를 paragraph 직접 조작 없이 작성.HwpxOxmlParagraph.add_footnote/add_endnote의 cpr 버그 수정 (인자char_pr_id_ref가 본문 run에 무시되고 항상"0"이 박히던 문제).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
Generated with Claude Code
via Happy