Skip to content

feat: add native HWPX document backend - #3856

Open
myeolinmalchi wants to merge 3 commits into
docling-project:mainfrom
myeolinmalchi:feat/hwpx-backend
Open

myeolinmalchi wants to merge 3 commits into
docling-project:mainfrom
myeolinmalchi:feat/hwpx-backend

Conversation

@myeolinmalchi

Copy link
Copy Markdown

Summary

Adds a native input backend for HWPX documents (Korean Hangul Word Processor XML format, OWPML / KS X 6101), the first half of #3602.

HWPX is a zip+XML container, structurally analogous to DOCX, so it is parsed natively with zipfile and lxml only:

  • Zero new dependencies. lxml is already a core dependency; pyproject.toml and uv.lock are untouched.
  • Registers InputFormat.HWPX for .hwpx (extension-first detection with zip-content confirmation, so generic zips are not misdetected).
  • HwpxDocumentBackend (DeclarativeDocumentBackend) maps OWPML to DoclingDocument: paragraphs, headings (outline levels), lists, tables including merged cells, and pictures.
  • Out of scope for v1 and documented as such: charts, text-box content, header/footer furniture, equations beyond raw-script preservation, and DRM/distribution documents (rejected with a clear error). Legacy binary .hwp is intentionally excluded; see the plan below.
  • Docs updated (index.md, supported_formats.md); test fixtures are MIT-licensed samples with provenance recorded in tests/data/hwpx/SOURCES.md.

Relation to #3602 (please do not auto-close)

Part of #3602. This PR covers the XML half of the request with no dependency risk. The binary .hwp half needs a real parser and is planned as a follow-up on top of rhwp (MIT Rust HWP parser), where I have an implementation PR for a versioned DocLang v0.6 export in review: edwardkim/rhwp#3132. Feedback on the preferred integration shape for that follow-up (CLI subprocess like the Tesseract OCR engine, or an optional binding) is welcome.

Issue resolved by this Pull Request:
Part of #3602 (HWPX only; binary HWP remains open)

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Validation

  • uv run pytest tests/test_backend_hwpx.py — 14 passed (format detection for path and stream inputs, e2e conversion with groundtruth verification, heading levels, table with colSpan merged cells, list items, picture, footnote, formula script preservation)
  • uv run pytest tests/test_input_doc.py — 9 passed (no regression in existing format detection)
  • make validate — all hooks pass cleanly

Groundtruth data was generated with DOCLING_GEN_TEST_DATA=1 and reviewed manually. Test fixtures are MIT-licensed HWPX samples; one minimal fixture is synthesised for outline-heading coverage. Full provenance in tests/data/hwpx/SOURCES.md.

Add HwpxDocumentBackend, a dependency-free backend for the Korean Hangul
Word Processor XML format (HWPX / OWPML, KS X 6101). HWPX is a ZIP
container of OWPML XML, analogous to DOCX, parsed natively with the
standard-library zipfile plus the already-required lxml.

The backend maps paragraphs (merged run text), outline headings,
numbered/bulleted list items, tables with merged cells, embedded raster
pictures, footnotes/endnotes, and Hancom equation scripts onto a
DoclingDocument. The legacy binary .hwp (OLE/CFB) format is reported as
unsupported.

Register InputFormat.HWPX with its extension and mimetypes, add
extension-first plus content-confirm (application/hwp+zip marker)
detection, and wire the default format option into the converter and CLI.

Signed-off-by: 강민석 <[email protected]>
Add tests for the HWPX backend: format detection (extension and
content-confirm), an end-to-end groundtruth regression over all fixtures,
and targeted assertions for paragraph text, heading levels, table grid
dimensions with a merged-cell span, list items, footnotes, equation
scripts, embedded pictures, and clean failure on non-HWPX inputs.

Fixtures are real MIT-licensed HWPX documents from the rhwp sample corpus,
one per exercised element class, plus a synthesised outline-heading
fixture; provenance and licensing are recorded in tests/data/hwpx/SOURCES.md.

Signed-off-by: 강민석 <[email protected]>
List HWPX in the supported input formats table and the What's new
section.

Signed-off-by: 강민석 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @myeolinmalchi, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@vku-ibm
vku-ibm self-requested a review July 29, 2026 13:27
@codecov

codecov Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.08696% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/hwpx_backend.py 96.26% 8 Missing ⚠️
docling/datamodel/document.py 90.90% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mergify

mergify Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

1 similar comment
@mergify

mergify Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot mentioned this pull request Oct 25, 2026
2 of 3 tasks
@hyeonsang010716

Copy link
Copy Markdown

Thanks for splitting this up. HWPX first with zero new dependencies looks like the right first step.

I maintain OpenDocKit, an MIT Python converter that reads HWP/HWPX, and most of what I know about the format came from files breaking. I read through hwpx_backend.py with that list in mind. These are the cases I think real Hangul files will hit. Most are small fixes:

1. Inline elements inside hp:t are dropped, so words run together. "".join(child.itertext()) keeps the text around <hp:tab/>, <hp:lineBreak/>, <hp:nbSpace/> and <hp:fwSpace/> but not what they stand for. Forms use tabs everywhere:

<hp:t>성명<hp:tab/>홍길동<hp:lineBreak/>연락처</hp:t>

comes out as 성명홍길동연락처. Mapping them to \t, \n and a space while walking the children of hp:t fixes it.

2. Deleted text from tracked changes is kept. Hangul leaves the deleted text in place between <hp:deleteBegin Id="n"/> and <hp:deleteEnd Id="n"/>:

<hp:t>예산 <hp:deleteBegin Id="1"/>1,200<hp:deleteEnd Id="1"/>1,450 백만원</hp:t>

becomes 예산 1,2001,450 백만원, which is a wrong number rather than noise. Skipping the text between a matching pair inside the same hp:t is safe. When the pair spans runs it's harder to tell where the deletion ends, so we left that case as it is.

3. Table and picture captions are lost. A caption is in hp:tbl/hp:caption/hp:subList (the same under hp:pic), and _add_table only reads hp:tr. The number in a caption like <표 1> is an hp:autoNum control rather than text, so it needs filling in as well.

4. Nested tables are flattened into the parent cell. _cell_text uses .//hp:p, which also collects the paragraphs of a table inside the cell (and of a footnote inside the cell), so the inner grid becomes one space-joined string. Korean forms nest tables a lot. Reading only the cell's own hp:subList/hp:p and handing an inner hp:tbl to _add_table would keep its structure.

5. Ruby text and composed characters disappear. hp:dutmal keeps its base text in hp:mainText, not hp:t, so the whole word is dropped. hp:compose keeps its characters in the composeText attribute. Legal texts use it for circled numbers past ⑳, so 제⑫조 came out as 제조 for us. Composed characters show up in the Hancom-made samples of the public hwpxlib repo.

6. Pictures inside grouped objects are dropped without a placeholder. walk doesn't descend into hp:container, so an hp:pic inside a group never reaches _add_picture, which the placeholder comment there means to avoid.

On the binary .hwp part, rhwp sounds like a good choice. One thing that cost us time and doesn't depend on the parser: in real files the cell address is 8 bytes into LIST_HEADER, not 6 as the spec says. And if a pure-Python route ever comes up (say, shipping a Rust binary turns out to be awkward), OpenDocKit's HWP 5 reader is pure Python and MIT, so feel free to borrow from it.

Our tests build each of these cases in memory (tests/test_hwp.py: TestHwpxTrackChanges, TestDutmal, TestComposedCharacters, TestNestedTables, TestAutoNumber), so they can be reused as fixtures without license questions. Happy to send a small PR to your branch for any of the above if that helps.

This branch has not been deployed

No deployments
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.

2 participants