Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/formats/docx/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,18 @@ impl<'a, 'b, 'e> InlineWalker<'a, 'b, 'e> {
f.instr.push_str(&child.text());
}
}
"ruby" => {
// Phonetic guide: keep the base text (w:rubyBase) and
// 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)?;
}
}
Comment on lines +546 to +550

@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

}
}
_ => {}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/formats/docx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,25 @@ mod tests {
}
}

#[test]
fn ruby_phonetic_guide_keeps_its_base_text() {
// A w:ruby keeps its base text and drops the pronunciation (w:rt);
// without a ruby branch the whole guide was silently discarded.
let body = r#"<w:p>
<w:r><w:t xml:space="preserve">Before </w:t></w:r>
<w:r><w:ruby>
<w:rubyPr><w:rubyAlign w:val="center"/></w:rubyPr>
<w:rt><w:r><w:t>t&#333;</w:t></w:r></w:rt>
<w:rubyBase><w:r><w:t>&#26481;</w:t></w:r></w:rubyBase>
</w:ruby></w:r>
<w:r><w:t xml:space="preserve"> after</w:t></w:r>
</w:p>"#;
let document = format!(r#"<w:document {W}><w:body>{body}</w:body></w:document>"#);
let bytes = docx_parts(&[("word/document.xml", &document)]);
let markdown = crate::to_markdown_bytes(&bytes, crate::Format::Docx).unwrap();
assert_eq!(markdown, "Before 東 after\n");
}

#[test]
fn numbered_heading_keeps_its_number() {
// H1: a heading style with numbering shows its label and advances
Expand Down