Skip to content

fix(hwp): keep picture captions when converting to DOCX - #2080

Merged
KnifeLemon merged 2 commits into
KnifeLemon:mainfrom
RionHwang0:codex/hwp-benchmark-regression
Dec 5, 2026
Merged

KnifeLemon merged 2 commits into
KnifeLemon:mainfrom
RionHwang0:codex/hwp-benchmark-regression

Conversation

@RionHwang0

Copy link
Copy Markdown
Contributor

What changed

Filee exports a floating picture to Word but loses the caption attached to it. When the picture is anchored between words, the caption belongs in its own paragraph after the complete sentence. The HWPX reader now reads the picture’s caption with the existing paragraph-list reader and appends its blocks when the anchor paragraph is complete. Captions become editable Word paragraphs. This also covers HWP → DOCX when rhwp converts the input to HWPX first.

Reproduce

Download either the HWP fixture or the HWPX fixture, then run filee-cli convert 13_floating_caption.hwpx --to docx (substitute the HWP filename for the other case).

Filee 2.5.0 and main at c0888c0 both keep the picture and the two body paragraphs but omit 그림 1. 야간 개관 안내. After the change, the DOCX contains the complete host sentence, that caption exactly once, then 안내문은 입구에 있다., matching the expected paragraphs.

Verification

  • Added an end-to-end regression with a floating picture between two runs and a two-paragraph caption. It failed on main because the next body paragraph immediately followed the picture. It passes with the change.
  • On macOS ARM64, 46 tests passed across HwpxReaderTests, DocxWriterTests and UnhwpLineBreakTests, with the release’s rhwp available. Formatting verification passed for all three changed files.
  • Converted 13 paired HWP/HWPX cases to DOCX before and after. In the two caption cases, the image remains anchored and the caption is restored. Across the other 24 outputs, extracted paragraphs, tables and drawing counts matched.

…2080)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, and thanks for the clear reproduction with the bench fixtures. The fix is small and in the right place:

  • Reading the caption with ReadSubList matches how table captions are already read, so nested paragraphs, tables and the nesting limit all behave the same way.
  • Holding the caption blocks until Finish keeps the host sentence whole, which is what Word readers expect. It also works inside cells, text boxes and headers, since each of those has its own ParagraphBuilder.
  • Every target that reads through HwpxReader gets the caption, not only DOCX, which is a good side effect.

Two things to know, neither blocking:

  • A caption set to side="TOP" also comes after the paragraph. Putting it before would mean holding it until the anchor paragraph starts, which is more change than this needs. If a real document shows it, a follow-up can handle it.
  • Only pic captions are read. Rectangles and groups can carry captions too, but pictures are by far the common case.

I pushed a CHANGELOG line under 2.6.0 Fixes (c74681d). Approving. This merges once CI is green.

@KnifeLemon
KnifeLemon merged commit 2fd1b93 into KnifeLemon:main Dec 5, 2026
20 of 22 checks passed
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