fix(docx): keep base text of phonetic guides (w:ruby)

SH
16h ago
+31-0
  • Branch: fix/docx-ruby-base-text (head 96141ae)
  • Base: main (6feb6c2)
  • Fixes #235

Diffstat

src/formats/docx/content.rs | 12 ++++++++++++
src/formats/docx/mod.rs     | 19 +++++++++++++++++++
2 files changed, 31 insertions(+)

Problem

walk_run_content() had no "ruby" arm, so a w:ruby fell through to the catch-all _ => {} and its base text was silently dropped: Before 東 after (guide tō) rendered as Before after. This loses content characters, not decoration, in a feature common in CJK documents.

Fix

Add a "ruby" arm: walk into w:rubyBase and render its runs with the existing walk_run(), skipping the pronunciation (w:rt) and properties (w:rubyPr). This matches the XLSX side's rPh handling. Per the spec w:ruby only appears inside w:r, so no paragraph-level branch is needed, and ruby inside hyperlinks/text boxes goes through the same walk_run_content path. No API, model, or renderer change.

Tests

  • New unit test ruby_phonetic_guide_keeps_its_base_text (in src/formats/docx/mod.rs).
  • Before: cargo run --example convert -- handmade-ruby.docx outputs Before after; after: Before 東 after. (Note: anydoc has no executable binary; the convert example is the entry point.)
  • New test failed before the fix (verified via git stash) and passes after. Full cargo test --release: lib 287 passed; other suites 2 + 1 + 10 (9 passed, 1 ignored, 0 failed). cargo fmt --check is clean.

Summary by cubic

Fixes DOCX phonetic guides (w:ruby) so their base text is no longer dropped when converting to Markdown. Previously Before 東 after (with guide tō) rendered as Before after, losing content characters common in CJK documents. Closes #235.

  • Adds a "ruby" arm that renders the base text runs and skips pronunciation and properties, matching the existing XLSX rPh handling.
  • Adds a unit test that fails before the fix and passes after.