Skip to content

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

Open
shengzhaowei wants to merge 1 commit into
firecrawl:mainfrom
shengzhaowei:fix/docx-ruby-base-text
Open

shengzhaowei wants to merge 1 commit into
firecrawl:mainfrom
shengzhaowei:fix/docx-ruby-base-text

Conversation

@shengzhaowei

@shengzhaowei shengzhaowei commented Nov 22, 2026 •

Copy link
Copy Markdown

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.

Written for commit 96141ae. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files

Confidence score: 3/5

  • content.rs drops base text when valid <w:ins> or other wrapper elements sit between rubyBase and its runs. Walk rubyBase with the regular inline walker so wrapped text is preserved.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/formats/docx/content.rs">

<violation number="1" location="src/formats/docx/content.rs:546">
P2: This drops base text wrapped in valid elements such as `<w:ins>`, because the loop only processes direct `<w:r>` children. Walk `rubyBase` through the regular inline walker so wrapped base runs are preserved.</violation>
</file>

Reply to a comment to ask cubic a question or push back. It learns from your replies.
Click Fix with cubic on a comment, or reply @cubic-dev-ai fix this, and cubic writes the fix.

View guided diff | Re-trigger cubic

Comment on lines +546 to +550
for run in base.child_elems() {
if run.is(ns::W, "r") {
self.walk_run(run)?;
}
}

@cubic-dev-ai cubic-dev-ai Bot Nov 22, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This drops base text wrapped in valid elements such as <w:ins>, because the loop only processes direct <w:r> children. Walk rubyBase through the regular inline walker so wrapped base runs are preserved.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/formats/docx/content.rs, line 546:

<comment>This drops base text wrapped in valid elements such as `<w:ins>`, because the loop only processes direct `<w:r>` children. Walk `rubyBase` through the regular inline walker so wrapped base runs are preserved.</comment>

<file context>
@@ -538,6 +538,18 @@ impl<'a, 'b, 'e> InlineWalker<'a, 'b, 'e> {
+                    // drop the pronunciation (w:rt) and properties
+                    // (w:rubyPr), matching the xlsx rPh handling.
+                    if let Some(base) = child.find(ns::W, "rubyBase") {
+                        for run in base.child_elems() {
+                            if run.is(ns::W, "r") {
+                                self.walk_run(run)?;
</file context>
Suggested change
for run in base.child_elems() {
if run.is(ns::W, "r") {
self.walk_run(run)?;
}
}
self.walk(base)?;
Fix with cubic

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.

[Bug]: DOCX phonetic guide (w:ruby) base text is silently dropped

1 participant